【发布时间】:2019-06-13 23:55:39
【问题描述】:
我有一个尺寸为 512 * 256 的图像,
左边部分应该是 NN 的输入,右边部分必须是相应的输出。因此,每张图片的尺寸为 256 * 256。
到目前为止,我做了什么来拆分两个图像:
image_dir = 'images'
image_filenames = os.listdir( image_dir )
for filename in image_filenames:
image = Image \
.open(os.path.join( image_dir, filename)) \
.convert( 'RGB' )
width , height = image.size
x.append( np.asarray( image.crop( ( width , width/2 , width , width/2 )) ))
print( x )
输出显示一个空图像,大小为 0 * 0,
[array(<PIL.Image.Image image mode=RGB size=0x0 at 0x27049C55CF8>,
dtype=object), array(<PIL.Image.Image image mode=RGB size=0x0 at 0x27049C55710>,
dtype=object)]
我怎样才能完美地将 512 * 256 的图像分割成 256 * 256 的 2 个图像而不会出现上述问题使用 PIL 甚至 NumPy?
【问题讨论】:
-
您是否有理由坚持使用 PIL 而不是仅仅使用 numpy 进行拆分?
-
绝对不是。如果您可以在 NumPy 中提供解决方案,将会很有帮助。
标签: python image image-processing python-imaging-library