How to get profile coordinates x,y after using improfile

7 views (last 30 days)
hi, I try to find a way to get x and y coordinates of my profile after using improfile.
I want to use improfile command to ask user to select a line on the image where he wants a profile intensity and then i want to also get coordinates x and y of this line.
improfile only give me intensity values along the line i trace.
i also know [x,y] = ginput to get pixels positions from mouse click but it doesn't draw a line between 2 positions clicking so it's hard to know which line i will study with improfile(I,xi,yi).
Here is an example of a picture i want to study:
Thanks !
  4 Comments
Image Analyst
Image Analyst on 11 Apr 2020
You have cx and cy. Which do you want for the x axis?
Or do you want the distance from the leftmost point? If so, do this:
% Plot lines and markers like he want:
plot(cx(1), cy(1), 'g.', 'MarkerSize', 25); % Green spot.
hold on
plot(cx(end), cy(end), 'rs', 'MarkerSize', 25); % Red Square.
plot(cx, cy, 'r-', 'LineWidth', 2); % Red line.
% Get distance from left-most point.
[xLeft, index] = min(cx);
yLeft = cy(index);
distance = sqrt((cx-xLeft).^2 + (cy - yLeft) .^ 2);
% Now plot with distance as the x-axis.
plot(distance, c, 'b.-');
grid on;
title('Intensity Profile', 'FontSize', 15);
xlabel('Distance from left point', 'FontSize', 15);
ylabel('Gray Level', 'FontSize', 15);
You could also do distance from the peak, if you'd rather have that.
benjamin gorin
benjamin gorin on 11 Apr 2020
Indeed that is what i had planned to do, your code will be really helpful too, thanks !

Sign in to comment.

Accepted Answer

darova
darova on 11 Apr 2020
What about this
clc,clear
close
figure('windowstyle','docked')
I = imread('image.png');
imshow(I) % show image
h = msgbox('select the profile');
waitfor(h) % wait of "OK" button
p = impoly; % pick points to create improfile
xy = p.getPosition; % get xy data
[cx,cy,c] = improfile(I,xy(:,1),xy(:,2));
ax1 = axes('position',[.6 .2 .3 .3]); % create small window
line(cx,c(:,1,1),'color','r') % plot red channel
line(cx,c(:,1,2),'color','g') % plot green channel
line(cx,c(:,1,3),'color','b') % plot blue channel

More Answers (0)

Categories

Find more on Image Processing Toolbox 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!