How do I circle the pores in a fingerprint image?

I have extracted pores(the white blobs) in a fingerprint, how do I highlight them by encircling?

 Accepted Answer

Use bwareaopen() to remove larger blobs. Then use regionprops on the remaining small blobs
binaryImage = binaryImage = bwareaopen(binaryImage, 100);
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area', 'Centroid');
allAreas = [measurements.Area];

13 Comments

I tried this code on the image but it shows an error stating "bwlabel expects 2d input" What does that mean? Also in bwareopen what does 100 signify?
You need to use your binary image - your segmented image. This is a logical image of what is foreground and what is background.
Okay thanks, I rectified that.
Is there a way I can circle the white dots that are present on the black lines? Like the one shown in the image below.
The rectangle() function will let you draw circles in the overlay like in the image you show above.
Since I will be working on different images, is there no other way of marking the blobs ,instead of using a function, where I need to enter the coordinates in the code?
Sure, you can draw your own circle using the FAQ, but why , when rectangle() will do it so conveniently?
Image Analyst,
I want to mark the pores.The rectangle() function takes the coordinates as input.Even if I enter the various coordinates for one image(which is again a tedious task), they will never be true for a different image.I am looking for something direct and automatic,such that pore coordinates are detected and marked on the image on their own.Is it too difficult to achieve?
You said "I have extracted pores" - if true, you have segmented the image and now have a binary image of the pores only. So you can just use my code to find their centroids and then use rectangle() to place a circle over each one. It's not manual or tedious, it's just a for loop over all the centroids returned by regionprops().
If "I have extracted pores" is NOT true, then that is the task you need to tackle first. Only then can you use my code to circle the centroids.
BinaryImage=im2bw(OriginalImage);
labeledImage = bwlabel(BinaryImage);
measurements = regionprops(labeledImage, 'Area', 'Centroid');
allAreas = [measurements.Area];
for k=1:allAreas
blobCentroid = measurements(k).Centroid;
rectangle('Position',blobCentroid,'Curvature',[1 1])
imshow(labeledImage);
end
title('Pores detected');
end
I am getting white blobs over black ground, these are pores. Now on applying the loop for circling these pores, it shows error.Can you please fix the code?
Attach the original image file.
What is the minimum blob size that you consider to be not noise? 2 pixels? 5 pixels?
The blob size lies between 2-45 pixels.

Sign in to comment.

More Answers (1)

I wish people would stop using im2bw() and graythresh(). They're almost never any good. See the attached code that does pretty much what I said except that there is now the 2-45 size filter in there.
clc;
close all;
workspace; % Make sure the workspace panel with all the variables is showing.
format long g;
format compact;
fontSize = 18;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a demo image.
folder = pwd;
baseFileName = 'originalImage.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = grayImage(:,:,2); % Take green channel if it's color)
end
% Display the original color image.
subplot(2, 2, 1);
imshow(grayImage);
axis on;
title('Original Gray Scale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(grayLevels, pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Make smaller to speed up the demo
grayImage = imresize(grayImage, 0.25);
% Threshold the image to create a binary image
% binaryImage = im2bw(grayImage); % No good
binaryImage = grayImage > 20; % Better!
% Get rid of blobs smaller than 2 pixels.
binaryImage = bwareaopen(binaryImage, 2);
% Find blobs bigger than 45 pixels.
bigBlobs = bwareaopen(binaryImage, 45);
% Subtract to get blobs in the range 2-45 pixels.
binaryImage = xor(binaryImage, bigBlobs);
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage, []);
axis on;
title('Binary Image', 'FontSize', fontSize);
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area', 'Centroid');
allAreas = [measurements.Area];
subplot(2, 2, 4);
imshow(grayImage, []);
title('Binary Image with small lines removed', 'FontSize', fontSize);
circleRadius = 5;
hold on;
for k = 1 : numberOfBlobs
blobCentroid = measurements(k).Centroid;
pos = [blobCentroid - circleRadius/2, circleRadius, circleRadius]
rectangle('Position', pos,...
'EdgeColor', 'r', 'Curvature',[1 1])
end
caption = sprintf('%d Pores Detected', numberOfBlobs);
title(caption, 'FontSize', fontSize);

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!