Borrar filtros
Borrar filtros

The roundness ratio of exact circle is less than 1

1 visualización (últimos 30 días)
Mahmoud
Mahmoud el 26 de En. de 2015
Respondida: Image Analyst el 11 de Dic. de 2015
hello everyone,
i am new to matlab and i am trying to understand it by myself. I am plotting an exact circle. however, when i try to find the roundness ratio, matlab gives me a ratio of less than 1.

Respuesta aceptada

Image Analyst
Image Analyst el 26 de En. de 2015
How are you finding it? Normally it's the perimeter squared divided by (4*pi*area), or the inverse of that. What formula are you using?
  2 comentarios
Mahmoud
Mahmoud el 26 de En. de 2015
Editada: Mahmoud el 26 de En. de 2015
I am using the same formula you mentioned. I used Autocad to draw an exact circle a certain radius to check if Matlab can give the ratio to be 1. however, I got it 0.92. I want any approach that can help me differentiate ovality from an exact circle. Please, can you provide any help? I appreciate your response :)
Image Analyst
Image Analyst el 26 de En. de 2015
Attach your m-file and image.

Iniciar sesión para comentar.

Más respuestas (2)

John D'Errico
John D'Errico el 26 de En. de 2015
Show how you are computing that number. Without knowing how you did it, one can only surmise what you did.
In fact, I can imagine any number of ways one might do so, and I would expect to see SOME number that is not exactly 1. The fact is, no matter what you do, you will not get the exact answer, UNLESS you use the circle itself. Perhaps this quote applies:
"The best material model of a cat is another, or preferably the same, cat."
Philosophy of Science (1945) (with A. Rosenblueth)
The point is, any approximation is only that, an approximation.
For example, perhaps you computed the roundness-ratio as the ratio of areas, comparing the area of a polygonal set of segments that will approximate a circle (using points on that circle) to the known area of that circle.
It matters not that you used many points in that approximation. (In fact, that was one way that some early mathematicians were able to approximate the value of pi.) But no matter how many points taken, that ratio of areas will always be less than 1, and only approach 1 as a limit.
  8 comentarios
Christovão Abrahão
Christovão Abrahão el 11 de Dic. de 2015
I understand that the analog world can not be represented exactly by a digital model (discrete). But a circle drawn by Autocad should have greater roundness higher the resolution or the absolute size of the picture, right?
John D'Errico
John D'Errico el 11 de Dic. de 2015
It depends entirely upon how the image is created, something about which I can have no knowledge. Start with a low res image, then resize it, and you will gain nothing. Anyway, be careful about the measured length of a curve, when that curve is a city block one, as one might find in an image.
p1 = [0 1;1 1;1 0];
p2 = [0 1;.5 1; .5 .5; 1 .5;1 0];
p3 = [0 1;.25 1;.25 .90;.5 .90; .5 .75; .75 .75;.75 .5;.90 .5;.90 .25;1 .25;1 0];
plot(p1(:,1),p1(:,2),'r-',p2(:,1),p2(:,2),'g-',p3(:,1),p3(:,2),'b-')
See that each of those curves have the same length, though the third would seem to be a bit better approximation to a circle. In fact, ANY curve that proceeds in a city block fashion from the point (0,1) to the point (1,0) has the same length (2 units) as long as it moves monotonically between the two end points.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 11 de Dic. de 2015
Mahmoud, I know I asked you before and you didn't respond with your code, so perhaps you realized your mistake. But I thought I'd show the circularity with my code and your image.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
% clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%===============================================================================
% Read in a gray scale demo image.
folder = pwd;
baseFileName = 'trial.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Unfortunately the image was saved as color so we need to get the circle only.
% Threshold the image at 192 to binarize it.
binaryImage = grayImage == 192;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
axis on;
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Now fill it so we can get the area and perimeter
binaryImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
axis on;
title('Filled Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Perimeter', 'Area');
circularity = measurements.Perimeter^2 ./ (4*pi*measurements.Area)
% Tell user we're done
message = sprintf('The circularity = %f', circularity);
uiwait(helpdlg(message));
So I get a circularity = 0.987191321413265 which is reasonably close to 1, especially considering the jaggy nature of the low resolution image you uploaded. If you're still interested in learning why your code gave a wrong value of 0.92, then you need to attach your code.

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by