Python scikit图像将二进制图像保存为完全黑色图像
因此,我尝试使用scikit image获取二进制图像,并使用以下代码将其保存在磁盘上:Python scikit图像将二进制图像保存为完全黑色图像,python,image,scikit-image,Python,Image,Scikit Image,因此,我尝试使用scikit image获取二进制图像,并使用以下代码将其保存在磁盘上: gray = color.rgb2gray(img) thresh = filters.threshold_otsu(gray) binary = gray >= thresh io.imsave("./testout/" + img_name, binary) 当我执行io.imshow(二进制)时,我得到了我期望的结果。但是imsave()返回给我的是完全黑色的图像,好像它将真值和假值都转换为r
gray = color.rgb2gray(img)
thresh = filters.threshold_otsu(gray)
binary = gray >= thresh
io.imsave("./testout/" + img_name, binary)
当我执行io.imshow(二进制)时,我得到了我期望的结果。但是imsave()返回给我的是完全黑色的图像,好像它将真值和假值都转换为rgb或其他格式的(0,0,0)值
那么什么是正确的方法呢
from skimage import img_as_uint
# ...
io.imsave("./testout/" + img_name, img_as_uint(binary))
这似乎有效,但我不确定这是最好的方法
此外,scikit image repo上还出现了一个问题:简单地将
二进制
转换为浮点
也可以实现以下功能:
binary = (gray >= thresh).astype(float)
我更喜欢使用
img\u作为ubyte
:
从skimage导入img\u as\u ubyte
io.imsave(“demo.jpg”,img作为单位(二进制))
此外,您不会看到从uint16到uint8的
有损转换。丢失8位分辨率…
来自img\u-as\u-uint的警告
你能用随机生成的数组重现这个吗?