Using the drawline function to get distance and intensities between endpoints

7 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Image Analyst
Image Analyst il 23 Set 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 Commenti
Kyle Williams
Kyle Williams il 23 Set 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 il 23 Set 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.

Accedi per commentare.

Categorie

Scopri di più su Recognition, Object Detection, and Semantic Segmentation in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by