Marking termination and bifurcation finger minutia

2019-03-03 19:42发布

I have a project on Fingerprint Matching and I got stuck at marking the points of termination and bifurcation on the image. I have already stored pixels' coordinates. How would I go about doing this?

1条回答
干净又极端
2楼-- · 2019-03-03 20:02

Assuming that your image is stored in a grayscale image called im, and your points of termination and bifurcation are stored in 2D matrices where the first column denotes the row and the second column denotes the column of each point, you can easily do this using sub2ind. sub2ind converts 2D co-ordinates into linear indices so that you can easily vectorize setting pixels in an image, or locations in a matrix quickly. As such, make your grayscale image into a RGB image by stacking the image three times as a 3D matrix. If you recall, grayscale images in the RGB colour model have all of the red, green and blue channels the same. For example, gray would be (R,G,B) = (128,128,128).

Let's call your bifurcation points as bifur and terminations as term and are in that 2D matrix format I specified earlier. As such, do something like this:

%// Get linear indices for bifurcation and termination points
ind_b = sub2ind(size(im), bifur(:,1), bifur(:,2));
ind_t = sub2ind(size(im), term(:,1), term(:,2));

%// Mark them on the image
red = im;
green = im;
blue = im;

red(ind_b) = 255;
green(ind_b) = 0;
blue(ind_b) = 0;

red(ind_t) = 0;
green(ind_t) = 255;    
blue(ind_t) = 0;

im_colour = cat(3, red, green, blue);
imshow(im_colour);

Let's walk through this code slowly. I first figure out the linear indices of where the bifurcation and termination points are in the image. What I do next is create red, green and blue channels that are all copies of the original image. After this, I access each colour channel and mark the bifurcation and termination points with different colours. For the bifurcation points, I made them purely red or (R,G,B) = (255,0,0). For the termination points, I made them purely green or (R,G,B) = (0,255,0). Once I set the colours for the points, I create a colour image by stacking the channels together with cat, and specifically choosing the third dimension. I finally show the image in the end.

What you may also have to play with is the size of the markings on the image. As you can see, the pixels that are marked are just the single pixels themselves, and depending on the resolution of your image, you may or may not be able to see them properly in the image. As such, I would recommend you mark the pixels within a grid surrounding the original point. Perhaps you can make this a 5 x 5 grid surrounding the pixel of interest. With this, perhaps make a for loop for each point and mark a 5 x 5 pixel grid that surrounds this point. I'm also going to assume that your markings are sufficiently well inside the image so that we don't risk drawing the grid out of bounds. So the code would be modified like so:

%// Get linear indices for bifurcation and termination points
ind_b = [];
for idx = 1 : size(bifur,1)
    [c,r] = meshgrid(bifur(idx,2)-2:bifur(idx,2)+2, bifur(idx,1)-2:bifur(idx,1)+2);
    c = c(:);
    r = r(:);
    ind_b = [ind_b; sub2ind(size(im), r, c);
end

ind_t = [];
for idx = 1 : size(term,1)
    [c,r] = meshgrid(term(idx,2)-2:term(idx,2)+2, term(idx,1)-2:term(idx,1)+2);
    c = c(:);
    r = r(:);
    ind_t = [ind_t; sub2ind(size(im), r, c);
end

%// Mark them on the image
red = im;
green = im;
blue = im;

red(ind_b) = 255;
green(ind_b) = 0;
blue(ind_b) = 0;

red(ind_t) = 0;
green(ind_t) = 255;    
blue(ind_t) = 0;

im_colour = cat(3, red, green, blue);
imshow(im_colour);

What has changed is the beginning of the code. For each point that we have for the bifurcation and the termination points, I use meshgrid to determine a 5 x 5 grid of points that surround each relevant pixel, then generate the linear indices for each point within the 5 x 5 grid. I then add this into one final array for both so that we can carry out the same marking logic we saw above.

You'll have to play around with the colours if you want them to be other than red and green, but this should be something for you to start with. If you want a list of possible colours with the RGB model, a nice tool is the RGB colour picker where you figure out which colour you want, and it gives you the RGB values to replicate that colour.

Good luck!

查看更多
登录 后发表回答