How to get profile coordinates x,y after using improfile

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

Hi darova, thanks for your answer, i know this command gives me an intensity profile with coordinates x and y you asked for (xi and yi) but it implies that i already know where i want to study my profile. The problem is that i would like to ask user to select a profile depending on what he wants to study, that is exactly what does improfile but after i would like to plot an image with a line corresponding to this profile and for that i need to know positions where i calculate my profile. and at the end i would like to get a matlab figure something like this (this comes from ResearchIR software)
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.
Indeed that is what i had planned to do, your code will be really helpful too, thanks !

Sign in to comment.

 Accepted Answer

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

Community Treasure Hunt

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

Start Hunting!