Area Calculation Using polyarea: Figure vs PNG

I'm encountering an issue while working with the polyarea function. I've created a 2D scatter plot and used drawfreehand to select my roi and polyarea to calculate its area. However, when I save the figure as a PNG and recalculate the area from the image, the result is significantly larger. From what I can understand it has to do with how I am saving the figure to a png (?).
What I eventually want to do is have a png displaying a set of points and a figure displaying a different set of points and calculate their respective areas and compare them. The two will not be displaying the same thing necesserily so that why I need their areas to be comperable in dimensions.
I am attaching an example script.

 Respuesta aceptada

Image Analyst
Image Analyst el 22 de Dic. de 2023

0 votos

There is no spatial calibration when you save a figure, or a non-image graph in an axes on a figure. So the image you get upon saving the figure or axes is just basically a screenshot, so the area will depend on that size of the figure. If you resize the figure before saving you will get a different area.
You should be writing to a digital image and saving it with imwrite.

2 comentarios

Aikaterini
Aikaterini el 28 de Dic. de 2023
Thank you for your response. I am not resizing the figure at all. I tried saving using imwrite as well as:
F = getframe(gca);
F = frame2im(F);
[A,map] = rgb2ind(F, 256);
imwrite(A, map, 'File.png');
Still, when I calculate the area of a 1x1 square from the png I get something around 30000.
So 30,000 pixels, or sqrt(30000) pixels per unit. So your calibration factor is
unitsPerPixel = 1/sqrt(30000);
Multiply linear pixel distances by that and areas by the square of that to get quantities in real world units.
See attached demo.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 22 de Dic. de 2023

Comentada:

el 28 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by