Using the drawline function to get distance and intensities between endpoints

조회 수: 7 (최근 30일)
I am using this function https://www.mathworks.com/help/images/ref/drawline.html to draw a line across an image. My goal is to get the distance between the endpoints and get the intensity across the line.
disp('Please draw a line from the anterior edge of the patient to the center of the prostate');
anteriorLine = drawline(fh.CurrentAxes,'Color','r');
% Calculate the length of the line in physical units
% anteriorLine.Position
Distance = anteriorLine.Position;
x1 = Distance(1,1); y1 = Distance(1,2); x2 = Distance(2,1); y2 = Distance(2,2);
% Interpolate the intensities allong the line in increments of 0.1 mm
% Plot intensities allong line
I am having trouble with the position code in the link I shared above and I don't even know where to start with interpolating the intensities across the line. I would greatly appreciate a starting point or some help, thank you.
  댓글 수: 2
Kyle Williams
Kyle Williams 2022년 9월 23일
I have been trying that but I don't know how to include improfile() in my code. I have to use it in the command window for it to work.

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

답변 (1개)

Image Analyst
Image Analyst 2022년 9월 23일
Try this:
grayImage = imread('moon.tif');
subplot(2, 1, 1);
imshow(grayImage);
drawnow;
uiwait(helpdlg('Left click the first point and right click the second point.'))
[xLine, yLine, intensities] = improfile;
hold on;
plot(xLine, yLine, 'b-', 'LineWidth', 2)
subplot(2, 1, 2);
plot(intensities, 'b-', 'LineWidth', 2)
grid on;
xlabel('Distance')
ylabel('Gray Level')
  댓글 수: 2
Kyle Williams
Kyle Williams 2022년 9월 23일
This code works great. When I try it with mine, the line disppears after I draw the line and I don't get a plot. Idk why.
Image Analyst
Image Analyst 2022년 9월 23일
You probably changes it, like you don't have the line
plot(xLine, yLine)
Attach your code if you still want help with it.

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

카테고리

Help CenterFile Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by