필터 지우기
필터 지우기

How to measure distance in mm instead of pixel ?

조회 수: 4 (최근 30일)
Mehbuba Shaikh
Mehbuba Shaikh 2021년 3월 15일
답변: Image Analyst 2021년 3월 28일
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
Mehbuba Shaikh
Mehbuba Shaikh 2021년 3월 27일
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 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
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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by