Tiger pugmark binary image analysis

how could i find the centroid and area of each object in the image automatically.

 Accepted Answer

First run imclose() on it to fill in nooks and crannies. Then do imfill() to fill in holes. Then regionprops(). See im image segmentation tutorial for details if you need them: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

5 Comments

i want to calculate area and centroid for each toe and pad. and also want to calculate the distances between each centrods of each toe and angles between pad centroid and each toe centroid. how to do that ?
Did you read my answer? Where I tell you how to do that?
Did you run my demo where I find centroids?
How much of the code for your project do you want me to write for you?
Suvidha: OK here. This code pretty much does everything you want as far as I can tell, except the angles which I imagine you can get because you know how to use atand(). So just change the filename and foldername of your image and then run it. Let me know what you think.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Read in a color demo image.
folder = 'C:\Users\Suvidha\Documents';
baseFileName = 'pawprint.png';
% 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
originalImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(originalImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(originalImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Convert to grayscale.
if numberOfColorBands > 1
originalImage = originalImage(:,:,2);
end
% Binarize the image
binaryImage = originalImage > 128;
% Get rid of stuff near border.
binaryImage = imclearborder(binaryImage);
% Get rid of small things
binaryImage = bwareaopen(binaryImage, 300);
% Do a morphological closing to smooth it some
se = strel('disk', 3, 0);
binaryImage = imclose(binaryImage, se);
% Fill holes
% binaryImage = imfill(binaryImage, 'holes');
% Display image.
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Get the convex hull of each blob.
binaryImage = bwconvhull(binaryImage, 'objects');
% Display image.
subplot(2, 2, 3);
imshow(binaryImage);
axis on;
title('Convex Hull Image with Centroids', 'FontSize', fontSize);
% Measure the image
measurements = regionprops(binaryImage, 'Area', 'Centroid');
allAreas = [measurements.Area] % Get all areas into one vector.
numberOfBlobs = length(allAreas)
% Plot centroids on to image
hold on;
for k = 1 : numberOfBlobs
thisCentroid = measurements(k).Centroid
plot(thisCentroid(1), thisCentroid(2), 'b+', 'MarkerSize', 10);
end
% Display image in lower right.
subplot(2, 2, 4);
imshow(originalImage);
axis on;
title('Original Image', 'FontSize', fontSize);
% Find the distances between every pair of blobs.
distance = zeros(numberOfBlobs, numberOfBlobs);
for b1 = 1 : numberOfBlobs
thisCentroid1 = measurements(b1).Centroid
x1 = thisCentroid1(1);
y1 = thisCentroid1(2);
for b2 = (b1 + 1) : numberOfBlobs
thisCentroid2 = measurements(b2).Centroid
x2 = thisCentroid2(1);
y2 = thisCentroid2(2);
distance(b1,b2) = sqrt((x1-x2)^2+(y1-y2)^2);
distance(b2,b1) = distance(b1,b2);
line([x1 x2], [y1 y2], 'Color', 'r', 'LineWidth', 3);
message = sprintf('This distance is %.3f', distance(b1,b2));
uiwait(helpdlg(message));
end
end
Thank you ... the code has done almost what i want .. i think i can do further from here.
Then please mark the answer as "Accepted".

Sign in to comment.

More Answers (1)

regionprops() and ask for Centroid, and either Area or FilledArea.
Question: when you say "each object in the image", should each pugmark be considered one object, or should each toe be considered separate objects?

3 Comments

each toe and pad as separate objects. also i need to calculate distances between each toe and angle between toes and pad centre
How do you want to define the distances between the toes? Closest point? Distance between centroids?
distance between centroids

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!