MATLAB Answers

0

Detect concentric empty rough circles

Asked by Carine on 23 Jan 2014
Latest activity Edited by Carine on 27 Mar 2014

Hello,

I want to be able to detect and draw a square around some circles. These circles are taken with a camera so depending of the angle of view and the distance, the radius vary and they can be deformed.Here are two examples: First example and Second example.

The last thing I have tried is using the CircularHough_Grd function from Tao Peng but it finds circles that are tangent of the sought circles: Result with CircularHough_Grd. And I am not sure how resistant this function is to deformation.

Any suggestion would be welcome as I am running a bit out of ideas at the moment.

Cheers.

  2 Comments

Can you attach them here using the image icon? My company policy has banned dropbox.

Above there is one and here is the second one

Sign in to comment.

8 Answers

Answer by Image Analyst
on 23 Jan 2014
 Accepted Answer

  10 Comments

The problem with this particular image is that the black ring is touching the edge of the image. So you're going to have to think up a way to get a "C" shape (a partial ring) as well as a ring. It would take some thought. Otherwise, just expand the one ring you do find. Of course there is the problem that even the central disk could be cropped, so it looks like a "D". All of these pathological cases make the algorithm a lot more complicated. It would help if you could define the parameters of your experiment, like make sure the black ring never touches the edge of the image. Otherwise, let me review your algorithm to get "C" shapes. I probably won't have time to develop an algorithm for you today, but since it's your project you can probably spend all day on it.
Hi again, I am of course spending the day on it... But the day is ending her in Europe. I have tried the another example but the result is rather worse. Your code give this plot:
More tomorrow.
I really appreciate your help! Cheers-
Hello, I have finally something quite satisfying (history will see if fame is approaching dear Image Analyst ;-)):
nomFile = 'Piscine80b.JPG';
rgbImage = imread(nomFile);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
redChannel = rgbImage(:, :, 1);
level = graythresh(rgbImage);
binaryImage = im2bw(redChannel,level);
binaryImage = bwareaopen(binaryImage, 20000);
binaryImage = ~bwareaopen(~binaryImage, 20000);
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8);
% Label each blob so we can make measurements of it
fprintf('Found %d blobs.\n', numberOfBlobs);
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% pseudo random color labels
% Measure the regions
measurements = regionprops(labeledImage, 'Perimeter', 'Area');
% Select certain blobs based using the ismember function.
% Let's say that we wanted to find only those blobs
% with a circularity more than 5 or so.
allBlobPerimeters = [measurements.Perimeter];
allBlobAreas = [measurements.Area];
allCircularities = allBlobPerimeters .^ 2 ./ (4*pi*allBlobAreas)
% Get a list of the blobs that meet our criteria and we need to keep.
% keeperIndexes = find(allCircularities < 1.5)
[~,keeperIndexes] = min(allCircularities)
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% Measure the regions, this time getting equivalent circular diameter and centroid.
measurements = regionprops(logical(keeperBlobsImage), ...
'Perimeter', 'Area', 'EquivDiameter', 'Centroid','BoundingBox');
ecd = measurements.EquivDiameter
equivDiameter(k,lettre) = ecd;
c = measurements.Centroid;
centroid(k,lettre,:) = c;
BoundingBox = [measurements.BoundingBox]
% Create a square mask including the circle
x0 = BoundingBox(1); y0 = BoundingBox(2); % Upper left corner
w = BoundingBox(3); h = BoundingBox(4); % Width and heigth
dw = 0.1*w; dh = 0.1*h; % To let some margin
mask = zeros(rows,columns);
mask(max(1,ceil(y0-dh)):min(rows,ceil(y0+h+dh)), ...
max(1,ceil(x0-dw)):min(columns,ceil(x0+w+dw))) = 1;
mask = logical(mask);
Imask = rgbImage;
Imask(~mask) = 255;
IbinMask = ~(~binaryImage.*mask);
close
togglefig(nomFile)
imshow(rgbImage)
pause
imshow(IbinMask)
hold on
plot(c(1), c(2), 'r+', 'MarkerSize', 20, 'LineWidth', 3);
plot(c(1)-ceil(ecd/2):c(1)+ceil(ecd/2),c(2),'r','LineWidth', 3);
hold off
pause
end
end
Using that, I can define the box around my "nearly circle" and select it, draw the equivalent diameter and the centre. Thank you again for you help!

Sign in to comment.


Answer by Carine on 24 Mar 2014

Hello,
I would like to reopen this question as, dealing with a noiser picture, it does not work anymore. For example, if I take a picture which I process and transform to black and white. I get this one:
Now, when I try to find regions with regionprops, it just finds one in red. Whereas I need the system to dectect my black circle.
</matlabcentral/answers/uploaded_files/10333/region.jpg> To get it, following the previous idea of this thread I do:
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8);
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
imshow(coloredLabels)
Any idea on how I could detect the circle?
Cheers.

  1 Comment

Fix your link, and post your original image.

Sign in to comment.


Answer by Carine on 26 Mar 2014
Edited by Carine on 26 Mar 2014

OK, here is a full example: I have this picture:
</matlabcentral/answers/uploaded_files/10400/Turbio10b.JPG> or link here. I process it using adapthisteq with Rayleigh distribution and clip of 1 and get:
Now I transform it to black and white and use bwareaopen to clean the image a bit:
Then if I try to find the blobs with
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8);
I get this, link here or in fig . I find it very surprising as in very similar example, it works and detect both circles.
Cheers,
Carine.
P.S. I put hyperlink as it seems the direct links to the images don't work. I don't know why as when I download them, I am able visualize them but then it stop working.

  3 Comments

So you got it working?
And to insert images, did you use the image icon? Did you pick an image on the web or one from your hard drive?
No, if you can see my images, you will see that one of the circles is not detected. Yes I did use the image icon, choosing an image from my hard drive.

Your links are broken. Let me see if I can upload one from my hard drive from the image icon and see if the link it inserts is broken.

It seems I can insert one. Please try again.

Sign in to comment.


Answer by Carine on 27 Mar 2014

Original image

  0 Comments

Sign in to comment.


Answer by Carine on 27 Mar 2014

Using adapthisteq with Rayleigh distribution
on red channel

  0 Comments

Sign in to comment.


Answer by Carine on 27 Mar 2014

Now I transform it to black and white and use bwareaopen to clean the image a bit:

  0 Comments

Sign in to comment.


Answer by Carine on 27 Mar 2014

Then if I try to find the blobs with
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8);
I get this

  0 Comments

Sign in to comment.


Answer by Carine on 27 Mar 2014
Edited by Carine on 27 Mar 2014

I find it very surprising as in very similar example, it works and detect both circles.
I have split the text to have only one figure in each answer and see if it works better.

  0 Comments

Sign in to comment.