我正在处理一组显微图像,并试图为它们找到合适的阈值。我使用以下几行代码:
from skimage import io, img_as_float
from skimage.restoration import denoise_nl_means, estimate_sigma
from skimage import exposur
from skimage.io import imsave
img = img_as_float(io.imread(image))
sigma_est = np.mean(estimate_sigma(img, multichannel = True))
patch_kw = dict(patch_size = 5, patch_distance = 6, multichannel = True)
denoise_img = denoise_nl_means(img, h = 15 * sigma_est, fast_mode = True,
** patch_kw)
eq_img = exposure.equalize_adapthist(denoise_img)
imsave("Contrast_DAPI.tif", eq_img)当我运行这段代码时,我得到了一个比我的原始图像大四倍的文件,并且它不能被包括Python在内的任何东西打开。我只能保存它,以防我将格式从tif更改为png。但是,然后我收到了这样的警告消息:“从float64到uint8的有损转换。范围0,1。在保存之前将图像转换为uint8,以抑制此警告。”
有人能帮帮忙吗?在这种情况下如何保存tif文件?
谢谢
发布于 2020-12-09 07:23:24
问题是您将图像保存为float64数据类型。有关数据类型的更多信息,请阅读"Image data types and what they mean" -image文档。tiff文件库将很乐意保存float64,但许多tiff读者不会阅读它们。
根据下游应用程序的不同,您可以使用skimage.util.img_as_ubyte或skimage.util.img_as_uint转换为8位或16位整数数组,然后以相同的方式进行保存。下游库会更好,你几乎肯定不需要64位浮点数的全精度-这是一种在不损失精度的情况下将许多操作链接在一起的有用格式,但如果你打算在下一步计算阈值,就没有必要这样做。
https://stackoverflow.com/questions/65190600
复制相似问题