如何将双层图像保存到julia中的文件?
目标:如中所示,以双层格式保存图像 代码: 它保存为深度8的图像,但不是深度1的图像如何将双层图像保存到julia中的文件?,julia,binary-image,Julia,Binary Image,目标:如中所示,以双层格式保存图像 代码: 它保存为深度8的图像,但不是深度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
请指导我将双层图像保存到文件 我还不是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上工作可能很有用,这样您就可以立即看到错误。如“…tib=灰色。(灰色。(img_二进制)。>阈值)…”,它似乎是灰度格式的!如何验证图像是否为二进制(1bit/pixel)格式或灰度(1byte/pixel)格式?
repr(tib[1:50])
显示“Gray{Bool}[Gray{Bool}(false).
。因此它是一个布尔灰度数组…:)类型在保存到文件时未被保留。即,加载保存的图像类型为array{Gray{Normed{UInt8,8},2},但不是array类型{{Bool},2}。
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)