Filter löschen
Filter löschen

How to measure distance in mm instead of pixel ?

4 Ansichten (letzte 30 Tage)
Mehbuba Shaikh
Mehbuba Shaikh am 15 Mär. 2021
Beantwortet: Image Analyst am 28 Mär. 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 Kommentare
Mehbuba Shaikh
Mehbuba Shaikh am 27 Mär. 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 am 28 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 28 Mär. 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

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by