Using the drawline function to get distance and intensities between endpoints

7 Ansichten (letzte 30 Tage)
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 Kommentare
Kyle Williams
Kyle Williams am 23 Sep. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 23 Sep. 2022
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 Kommentare
Kyle Williams
Kyle Williams am 23 Sep. 2022
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 am 23 Sep. 2022
You probably changes it, like you don't have the line
plot(xLine, yLine)
Attach your code if you still want help with it.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Recognition, Object Detection, and Semantic Segmentation finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by