2017-04-08 38 views
0

我有一个图像,我想裁剪它。我使用了Otsu的方法,并将图像更改为二进制形式。二进制图像是:如何裁剪图像以删除背景

My original binary image

我想从这个图片找到XMIN,XMAX,YMIN,YMAX,这样我可以裁剪图像,使得只有叶部分保持原来的形象。

我需要为输出的图像(以二进制形式): The image I want

我不想使用手动裁剪。

回答

0

您可以使用regionprops选择您感兴趣的区域如下:

BW = imread('wxK0w.jpg'); 
stats = regionprops(BW<128, 'BoundingBox', 'Area'); % The black region (lowest values) is the region you are interested in. 
[~, iForeground] = max([stats.Area]); % assume the largest area is the foreground you want 
box = round(stats(iForeground).BoundingBox); 
BWcropped = BW(box(2) + (1:box(4)), box(1) + (1:box(3))); 
imshow(BWcropped) 

enter image description here