我正在尝试剪切图像,以某种方式去除白线。此图像在角落中有一个对象,由空格环绕。 我试图使用以下命令,但它以错误的方式切割图像。 image
The first line makes the image this way
第二行给出一个空文件。
image2= image[np.where((image < 255).any(axis=1))[0]]
image2[np.where((image2 < 255).all(axis=0))[1]]
我做错了什么?
答案 0 :(得分:0)
IIUC,你应该只需找到最小的非白色像素矩形。假设频道是最后一个维度:
color_x, color_y = np.where(np.any(image < 255, axis=2))
x0 = color_x.min()
x1 = color_x.max()
y0 = color_y.min()
y1 = color_y.max()
cropped_image = image[x0:x1 + 1, y0:y1 + 1]