MATLAB:如何通过识别一些功能从二进制图像中裁剪对象? [英] MATLAB : How to crop an object from a binary image by identifying some features?

查看:368
本文介绍了MATLAB:如何通过识别一些功能从二进制图像中裁剪对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这里所示的图片:
我的最终目的是提取静脉图案在手指。所以我想做的是单独提取手指对象。为此,我首先尝试了Otsu阈值步骤,然后尝试侵蚀和膨胀。现在使用二进制图像作为掩码,元素明智地乘以原始图像,以获得手指单独(不是那么精确)。

I have an image like shown here: My ultimate aim is to extract the vein pattern in the finger. So What I am trying to do is the extraction of the finger object alone. For that purpose, I tried an Otsu thresholding step first, then an erosion and dilation. Now using the binary image as a mask I multiplied element wise with original image to obtain the finger alone (not that accurate though).

代码如下:

I = imread('3.5.bmp');
[level] = graythresh(I);
BW = im2bw(I,level);
[BWm] = imerode(BW,strel('disk',10)); figure, imshow(BWm)
[BWmm] = imdilate(BWm,strel('disk',15)); figure, imshow(BWmm)
B = I.*uint8(BWmm); % BWmm is the mask
imshow(B)

单独使用我之前创建的掩码。如何实现这一点?

Now I want to crop this finger part alone using the mask which I created before. How to achieve that?

为了清楚起见,我上传的图像有要裁剪的区域:(最后我不想手动或使用imcrop()实用程序像素坐标作为输入。我想使用一些算法得到那些像素坐标。 )

For clarity I am uploading the image with the area to be cropped: (And finally I don't want to do this manually or using imcrop() utility with pixel coordinates as input. I would like to get those pixel coordinate using some algorithms.)

推荐答案

您可以从掩码 BWmm 然后使用 imcrop 的坐标。

You can find the pixel coordinates from the mask BWmm and then use the coordinates with imcrop.

要查找 BWmm use

To find the extermal points of BWmm use

projX = any( BWmm, 1 ); % projection of mask along x direction
projY = any( BWmm, 2 ); % projection of mask along y direction
fx = find( projX, 1, 'first' ); % first column with non-zero val in mask
tx = find( projX, 1, 'last' );  % last column with non-zero val in mask
fy = find( projY, 1, 'first' ); % first row with non-zero val in mask
ty = find( projY, 1, 'last' );  % last row with non-zero val in mask
cropRect = [fx, fy, tx-fx+1, ty-fy+1];
cImg = imcrop( I, cropRect );

这篇关于MATLAB:如何通过识别一些功能从二进制图像中裁剪对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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