Edge detection of a nail

2 次查看(过去 30 天)
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 ?

采纳的回答

Mohammad Abouali
Mohammad Abouali 2014-10-10
编辑:Mohammad Abouali 2014-10-10
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 个评论
Muzammil Mumtaz
Muzammil Mumtaz 2014-10-11
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 2014-10-12
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2014-10-10
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.

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by