目标:如https://memorynotfound.com/convert-image-black-white-java/
所示,以双层格式保存图像代码:
using Images, ImageView;
function save_as_binary_image(img_path::String, threshold::Float16)
img_binary = load(img_path);
img_binary = (Gray.(img_binary) .> threshold);
imshow(img_binary);
typeof(img_binary);#=>BitArray{2}
save("/path/to/dest/image.png", img_binary);
img_saved = load("/path/to/dest/image.png");
imshow(img_saved);
typeof(img_saved);#=>Array{Gray{Normed{UInt8,8}},2}
end
save_as_binary_image("/path/to/image/file", convert(Float16, 0.5));
将其另存为深度8的图像,但不保存为深度1的图像。
请指导我将双层图像保存到文件中!
答案 0 :(得分:1)
我还不是Images.jl用户(也许很快),但是这有些起作用:
using Images, ImageView
function save_binary_image(img_path, threshold)
img_binary = load(img_path)
@info size(img_binary)
tib = Gray.(Gray.(img_binary) .> threshold)
save("$(img_path)-$(threshold).png", tib)
end
save_binary_image("/tmp/mandrill.png", 0.1)
也许您可以慢慢地修改它以做您想要的...
在REPL上工作非常有用,这样您就可以立即看到错误。