使用遮罩和 Python scikit-image 裁剪图像
Crop image using mask and Python scikit-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)
我想根据凸包裁剪原始图像以消除图像中的空白space(附有原始图像),并且有一个仅包含凸包内部的图像船体。如何裁剪原始图像以减小其尺寸? (删去左右空的space)
谢谢。
可以用min和max求出凸包图像的边界
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]
我从事图像处理工作,我有以下代码来获取图像的凸包:
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)
我想根据凸包裁剪原始图像以消除图像中的空白space(附有原始图像),并且有一个仅包含凸包内部的图像船体。如何裁剪原始图像以减小其尺寸? (删去左右空的space)
谢谢。
可以用min和max求出凸包图像的边界
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]