Borrar filtros
Borrar filtros

How to measure distance in mm instead of pixel ?

4 visualizaciones (últimos 30 días)
Mehbuba Shaikh
Mehbuba Shaikh el 15 de Mzo. de 2021
Respondida: Image Analyst el 28 de Mzo. de 2021
I have picture with the image and scale and i would like to measure every width distance in mm rather than pixel in the attached code, (code and picture copied from @Image Analyst)
  10 comentarios
Mehbuba Shaikh
Mehbuba Shaikh el 27 de Mzo. de 2021
Rik, apolosife for misunderstanding. I have measured this 200 mm distance through software previously. Unfortunately this software is not working in our computer now. We don't know how much pixel contain in this lines but we would like to use this scale to calculate other distances. Is it clear now ?
David Goodmanson
David Goodmanson el 28 de Mzo. de 2021
Hi Mehbuba.
How accurate would you like the result to be? You have obtained in some manner the ‘200mm’ line, which I assume is done by scaling an image with 3000x4000 pixels.
On my monitor the width of the image (to the nearest 1/2 mm) is 191.5 mm and the ‘200 mm’ line has length 27 mm. With the image being 3000 pixels wide, doing the appropriate scaling gjves (3000/191.5)*(27/200) = 2.11 pixels/mm on the original image, wherever it is.
This process has nothing to do with the actual number of pixels on my monitor, which is 1920 pixels across, or on most other monitors.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 28 de Mzo. de 2021
Try this:
rgbImage = imread('original image3.jpg');
redChannel = rgbImage(:, :, 1);
nexttile
imshow(redChannel);
impixelinfo;
% Micron bar should always be placed by the image capture
% software at the same location for all images. Extract it.
micronBar = mean(redChannel(3669:3672, :), 1);
nexttile
plot(micronBar, 'b-', 'LineWidth', 2);
grid on;
% Get the full width, half max of the bar
threshold = mean([min(micronBar), max(micronBar)])
yline(threshold, 'Color', 'r', 'LineWidth', 2);
leftEdge = find(micronBar <= threshold, 1, 'first');
rightEdge = find(micronBar <= threshold, 1, 'last');
% Put up vertical lines.
xline(leftEdge, 'Color', 'r', 'LineWidth', 2);
xline(rightEdge, 'Color', 'r', 'LineWidth', 2);
% Compute the width in pixels.
widthInPixels = rightEdge - leftEdge;
% Compute the spatial calibration factor in mm per pixel.
mmPerPixel = 200 / widthInPixels
threshold =
50.875
widthInPixels =
317
mmPerPixel =
0.630914826498423

Categorías

Más información sobre Image Processing Toolbox 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