# How to calculate distance in centimeters using IMDISTLINE?

조회 수: 38(최근 30일)
karishma 2013년 10월 4일
댓글: Image Analyst 2022년 9월 8일
i want to find out height of a sleeping infant. for that i want to find out the distance in cm. using 'imdistline' i'm getting the distance in pixels but how to convert that in cm?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Image Analyst 2013년 10월 4일
편집: Image Analyst 2013년 10월 4일
Put a ruler, a tape measure, a standard sheet of paper, or anything else of known length into the scene. Then snap a picture of it and use imdistline() to find the length in pixels. For example, let's say you laid down a sheet of A4 paper and measured it's distance as 2100 pixels. Knowing that it is 21 cm long, you get a spatial calibration factor of 21/2100, which you multiply your distances in pixels by to get the distance in cm. Multiply by that calibration factor squared to convert the area in pixels to the area in square centimeters.
calibrationFactor = 21/2100;
distanceInCm = distanceInPixels * calibrationFactor;
areaInSquareCm = areaInPixels * calibrationFactor ^ 2;
It's in the FAQ.
See my demo attached below for a really nice demo.
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
Image Analyst 2022년 9월 8일
@Kanwarpal evidently you have not tried my demo attached above, because that will do it.

댓글을 달려면 로그인하십시오.

### 추가 답변(2개)

Roche de Guzman 2021년 1월 30일
global h; h = imdistline; % activates the fx for drawing and measuring line
setLabelTextFormatter(h,'measure'); % message
%% Custom fx
function ShowDistance(pos)
global h xc yc; % sets line handles and x and y conversion factors to global
X = pos(:,1)*xc; Y = pos(:,2)*yc; % converts x and y positions from px to target unit
d = norm(diff([X Y])); % distance in target unit
setLabelTextFormatter(h,[num2str(d,'%.1f') ' target unit']); % updates measurement
end
##### 댓글 수: 1표시숨기기 없음
Image Analyst 2021년 1월 30일
I like how you put in so many comments. I wish everyone would do that.

댓글을 달려면 로그인하십시오.

Matt J 2013년 10월 4일
Multiply by the length (in cm) of one pixel.
##### 댓글 수: 9표시숨기기 이전 댓글 수: 8
leylin fatqiyah 2015년 2월 12일
thank you

댓글을 달려면 로그인하십시오.

### 범주

Find more on Convert Image Type in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by