Edge detection of a nail

4 views (last 30 days)
Muzammil Mumtaz
Muzammil Mumtaz on 10 Oct 2014
Commented: Image Analyst on 12 Oct 2014
I am working on a assignment in which i have to detect the edges of nail. i tried to do this using bwboundaries command i did my work to some extent but the problem is that it detected the boundary of the large circle as well. however i just want to detect the nail edges. is there anyway by which i can do this ?

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 10 Oct 2014
Edited: Mohammad Abouali on 10 Oct 2014
reverse your mask (so the big black circle becomes white) then calculate the convex hull of that using (bwconvhull). This gives you the entire circle.
Then mask your original mask with the convex hull of your circle, this would set the outer perimeter to black.
Then use your method to get the boundary again.
I downloaded the image you posted and something like this will happen
I=imread('~/Desktop/lateralview.jpg');
I=double(rgb2gray(I))/255; % The image that I downloaded was rgb image. You might be able to skip this step.
Mask=logical(round(I));
bigCircleMask=bwconvhull(~Mask);
newMask=bwmorph(and(Mask, bigCircleMask),'majority');
This is the mask of big circle.
This is the new mask of the nail.
Now use your own algorithm to detect the edges of the nail.
If you want you can go one step further and fit a circle using imfindcircle of matlab to get a better circular mask of the bigCircle.
  2 Comments
Muzammil Mumtaz
Muzammil Mumtaz on 11 Oct 2014
Sir i tried your code and came up with this after modification. And the code worked really well and i have achieved my objective but yes this circles near the nail are being overlapped the nail boundary. But that is kind of ok for me. Here i would need a bit more of your favor with the code as i dont know about few commands what they are doing. Kindly comment them so i understand whats goin on behind the script.
This is the code:
clc; clear all; close all; I=imread('centroid.png'); z=I; I=double(rgb2gray(I))/255; % The image that I downloaded was rgb image. You might be able to skip this step. Mask=logical(round(I)); % KINDLY COMMENT THIS bigCircleMask=bwconvhull(~Mask); % KINDLY COMMENT THIS newMask=bwmorph(and(Mask, bigCircleMask),'majority'); % KINDLY COMMENT THIS newMask = bwareaopen(newMask,200); % KINDLY COMMENT THIS b=figure,imshow(newMask);
[B,L] = bwboundaries(newMask,'noholes'); % KINDLY COMMENT THIS figure,imshow(label2rgb(L, @jet, [.5 .5 .5])); % KINDLY COMMENT THIS figure,imshow(z);
hold on
for k = 1:length(B) % COMMENT boundary = B{k}; % COMMENT plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2) end
hold off
Image Analyst
Image Analyst on 12 Oct 2014
The convex hull is like you put a rubber band around your region.
bwboundaries gives you a cell array, where each cell is an outline. They have to be cells because each outline has a different length. See the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F Saying boundary = B{k}; extracts that one particular boundary so that you can pass it into plot and display it as an outline over the image.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 10 Oct 2014
Simply mask the image by the know location of the circle, which I assume will be in the same location for every image. See my attached masking demo.
Then use bwareaopen, or my attached ExtractNLargestBlobs function to get just the big nail and not all those other blobs in the array.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!