Detect concentric empty rough circles

8 visualizzazioni (ultimi 30 giorni)
Carine
Carine il 23 Gen 2014
Modificato: Carine il 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 Commenti
Image Analyst
Image Analyst il 23 Gen 2014
Can you attach them here using the image icon? My company policy has banned dropbox.
Carine
Carine il 23 Gen 2014
Modificato: Carine il 23 Gen 2014

Above there is one and here is the second one

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 23 Gen 2014
  10 Commenti
Carine
Carine il 28 Gen 2014
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-
Carine
Carine il 30 Gen 2014
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!

Accedi per commentare.

Più risposte (7)

Carine
Carine il 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.

Carine
Carine il 26 Mar 2014
Modificato: Carine il 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 Commenti
Carine
Carine il 27 Mar 2014
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.
Image Analyst
Image Analyst il 27 Mar 2014
Modificato: Image Analyst il 27 Mar 2014

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.

Accedi per commentare.


Carine
Carine il 27 Mar 2014

Original image


Carine
Carine il 27 Mar 2014
Using adapthisteq with Rayleigh distribution
on red channel

Carine
Carine il 27 Mar 2014
Now I transform it to black and white and use bwareaopen to clean the image a bit:

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

Carine
Carine il 27 Mar 2014
Modificato: Carine il 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.

Categorie

Scopri di più su Image Data Workflows in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by