0
我在python 2.7 Anaconda上使用simpleITK,我做了一个测试,读取一个大的tif文件(大约2Gb),将其转换为numpy数组,将其转换回numpy数组tif和保存在磁盘上,新文件大约是4Gb(我尝试了2种不同的方式保存,但结果相同)。数据类型在每一步都是一样的,任何想法为什么会发生?谢谢 !。 :)SimpleITK:tif到numpy数组并返回到tif使文件大小更大
import SimpleITK as sitk
p1 = sitk.ReadImage('my_image.tif') #read image
# print properties
print 'Width ',p1.GetWidth()
print 'Height ',p1.GetHeight()
print 'Depth ',p1.GetDepth()
print 'Dimension ',p1.GetDimension()
print 'Pixel Id Value ',p1.GetPixelIDValue()
print 'Pixel ID Type ',p1.GetPixelIDTypeAsString()
print 'Size ',p1.GetSize()
print '__________ '
p1_np = sitk.GetArrayFromImage(p1) #get numpy array from Image
print 'Array type ',p1_np.dtype #print array type
print '__________ '
p1_np_img = sitk.GetImageFromArray(p1_np) #get image from array
# print properties
print 'Width ',p1_np_img.GetWidth()
print 'Height ',p1_np_img.GetHeight()
print 'Depth ',p1_np_img.GetDepth()
print 'Dimension ',p1_np_img.GetDimension()
print 'Pixel Id Value ',p1_np_img.GetPixelIDValue()
print 'Pixel ID Type ',p1_np_img.GetPixelIDTypeAsString()
print 'Size ',p1_np_img.GetSize()
sitk.WriteImage(p1_np_img,'my_image_test_a.tif') #save new image
sitk.WriteImage(sitk.Cast(p1_np_img,sitk.sitkUInt16),'my_image_test_b.tif') #save new image
print "End "
的结果是这样的:
如果我复制了与您所写的相同的指令,输出图像的尺寸是3,而不是2在后。 – Jalo
是否为您的输入图像启用了任何类型的压缩? – blowekamp
感谢您的意见。我猜维度是2,因为我使用的是灰度图像。我没有检查原始图像的压缩,可能是的,现在检查是否可以保存为压缩的tif。 – CarlosG