【发布时间】:2018-10-22 23:43:33
【问题描述】:
读取图像有以下函数,我添加了几行重新输出图像,并输出图像数组的不同像素值。图像看起来像这样。然而 a,indices =np.unique(img,return_index=True)
给予
一个 [0 1]
指数 [0 879385]
好像图像数组有两个唯一值,[0 1],这有道理,但是索引表示什么?
def _get_image_data_pil(image_id, image_type, return_exif_md=False, return_shape_only=False):
fname = get_filename(image_id, image_type)
try:
img_pil = Image.open(fname)
except Exception as e:
assert False, "Failed to read image : %s, %s. Error message: %s" % (image_id, image_type, e)
if return_shape_only:
return img_pil.size[::-1] + (len(img_pil.getbands()),)
# -----
# this is what I adde
# -----
img = np.asarray(img_pil)
plt.imshow(img)
plt.show()
a,indices =np.unique(img,return_index=True)
print('a ',a)
print('indices ',indices)
assert isinstance(img, np.ndarray), "Open image is not an ndarray. Image id/type : %s, %s" % (image_id, image_type)
if not return_exif_md:
return img
else:
return img, img_pil._getexif()
【问题讨论】:
-
可能是每个值的第一个像素的索引。
标签: python numpy image-processing scipy pillow