我的图片如下所示:
我的最终目标是提取手指中的静脉图案。所以我要做的就是单独提取手指对象。为此,我首先尝试了Otsu阈值处理步骤,然后进行了侵蚀和扩张。现在使用二进制图像作为掩模我将元素与原始图像相乘以获得单独的手指(尽管不是那么准确)。
代码如下:
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)
现在我想使用我之前创建的面具单独裁剪这个手指部分。如何实现?
为了清楚起见,我上传的图片包含要裁剪的区域:(最后我不想手动或使用带有像素坐标的imcrop()实用程序作为输入。我会喜欢用一些算法得到那些像素坐标。)
答案 0 :(得分:1)
您可以从遮罩BWmm
中找到像素坐标,然后使用imcrop
的坐标。
找到BWmm
使用
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 );