How do I convert pixels to centimeters?

36 visualizaciones (últimos 30 días)
ISABELLE GUNDRUM
ISABELLE GUNDRUM el 3 de Mayo de 2022
Respondida: Image Analyst el 3 de Mayo de 2022
I've been using this code below to convert from pixels to centimeters by measuring a line known to be 1 cm in the image. I recently discovered my results are off and the code is not converting properly because the area I get later on is way too small. Does anyone have suggestions?
p2cm = 1/norm(hline.Position(1:2) - hline.Position(3:4));
CalibrationLine = hline.Position;
disp(['Length per pixel = ' num2str(p2cm) ' cm/pixel'])
** Result was .000759 cm/pixel and the area of the polygon was way, way smaller when it was supposed to be around 1.73 cm^2.

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Mayo de 2022
Sine the line gives you the number of pixels, your p2cm is actually centimeters per pixel, not pixels per cm like you thought. So it's something like this
cmPerPixel = distanceInCm / distanceInPixels;
% Now to convert a distance.
lengthInCm = lengthInPixels * cmPerPixel
% And to convert an area in pixels to square cm:
areaInSquareCm = areaInPixels * cmPerPixel ^ 2
See my attached demo.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by