使用遮罩和Python scikit图像裁剪图像 [英] Crop image using mask and Python scikit-image

查看:73
本文介绍了使用遮罩和Python scikit图像裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理图像,并且我有以下代码来获取图像的凸包:

I'm working in image proceesing and I have the following code to obtain the convex hull of a image:

from skimage import io
from skimage.color import rgb2gray
from skimage.morphology import convex_hull_image

original = io.imread('test.png')

image = rgb2gray(original)

chull = convex_hull_image(image)

我想根据凸包裁剪原始图像,以消除图像中的空白空间(附加原始图像),并且使图像只包含凸包内部的内容.如何裁剪原始图像以减小其尺寸?(删除左侧和右侧的空白区域)

I want to crop the original image according to the convex hull in order to eliminate empty space that is in the image (original image attached), and have an image that only contains what is inside the convex hull. How could I crop the original image to reduce its size? (deleting the empty space at left and right)

谢谢.

推荐答案

您可以使用min和max来查找凸包图像的边界.

You can use min and max to find the border of the convex hull image.

import numpy as np
[rows, columns] = np.where(chull)
row1 = min(rows)
row2 = max(rows)
col1 = min(columns)
col2 = max(columns)
newImage = original[row1:row2, col1:col2]

这篇关于使用遮罩和Python scikit图像裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆