How to measure distance in mm instead of pixel ?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
David Goodmanson
le 28 Mar 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.
Réponses (1)
Image Analyst
le 28 Mar 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
0 commentaires
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!