MATLAB : How to crop an object from a binary image by identifying some features? -


i have image shown here: finger_vein ultimate aim extract vein pattern in finger. trying extraction of finger object alone. purpose, tried otsu thresholding step first, erosion , dilation. using binary image mask multiplied element wise original image obtain finger alone (not accurate though). enter image description here

the code below:

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 mask imshow(b) 

now want crop finger part alone using mask created before. how achieve that?

for clarity uploading image area cropped: enter image description here (and don't want manually or using imcrop() utility pixel coordinates input. pixel coordinate using algorithms.)

you can find pixel coordinates mask bwmm , use coordinates imcrop.

to find 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 non-zero val in mask tx = find( projx, 1, 'last' );  % last column non-zero val in mask fy = find( projy, 1, 'first' ); % first row non-zero val in mask ty = find( projy, 1, 'last' );  % last row non-zero val in mask croprect = [fx, fy, tx-fx+1, ty-fy+1]; cimg = imcrop( i, croprect ); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -