[英]The image size pixel is changing while reseize using PIL Python?
fName = sys.argv[1]
X_original = Image.open(fName)
width, height = X_original.size
print(f'Original image --> width:{width}, height:{height}')
scale = 0.90
width_r, height_r = int(width*scale), int(height*scale)
print('Percentage of downsample:{:0.2f}%'.format(scale*100))
print(f'Resize image --> width:{width_r}, height:{height_r}')
X_resize = X_original.resize((width_r, height_r))
X_original = np.array(X_original)
print('Original image shape (height, width) --> ', X_original.shape)
print('Total number of unique pixel values: ', len(np.unique(X_original)))
X_resize = np.array(X_resize)
print('Resize image shape (height, width) --> ', X_resize.shape)
print('Total number of unique pixel values: ', len(np.unique(X_resize)))
img_original = Image.fromarray(X_original)
img_original.save("img_original.png")
img_resize = Image.fromarray(X_resize)
img_resize.save("img_resize.png")
problem is:问题是:
**ouput **** **输出**
Total number of unique pixel values of orginal:15原始唯一像素值总数:15
Total number of unique pixel values after resize:50**调整大小后唯一像素值的总数:50**
I think you're asking how/why additional colours/shades of grey are appearing in an image, despite making the size smaller.我想你是在问图像中如何/为什么出现额外的颜色/灰色阴影,尽管尺寸变小了。
I believe they're being created during the bicubic interpolation process.我相信它们是在双三次插值过程中创建的。
See:看:
If the image mode specifies a number of bits, such as "I;16", then the default filter is:py:data:
PIL.Image.Resampling.NEAREST
.如果图像模式指定了多个位,例如“I;16”,则默认过滤器为:py:data:PIL.Image.Resampling.NEAREST
。 Otherwise, the default filter is:py:data:PIL.Image.Resampling.BICUBIC
.否则,默认过滤器是:py:data:PIL.Image.Resampling.BICUBIC
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.