How to measure distance in mm instead of pixel ?
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
David Goodmanson
2021 年 3 月 28 日
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.
回答 (1 件)
Image Analyst
2021 年 3 月 28 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!