How to plot multiple IMPROFILE lines and export them to EXCEL?

7 views (last 30 days)
Hi all!
Thanks in advance for your help!
Basically what I'm trying to do is to plot several IMPROFILE lines and export their values to Excel.
I'm getting the user to select an image and to draw a line along which a predetermined number of perpendicular IMPROFILE lines will be plotted. However, the code below only returns values for the first line (when i=0). For all the other i-values the vectors generated by the IMPROFILE function contain only NaN values.
Does anyone know why that's the case? By the way, the code runs with no errors.
Thanks! Giuseppe
[FileName,PathName] = uigetfile('*.jpg','Select the IMAGE');
imshow(FileName);figure(gcf);
I=imread(FileName);
g = imline;
pos = wait(g);
cat=diff(pos); catx=abs(cat(1)); caty=abs(cat(2));
len = sqrt(catx.^2+caty.^2);
hp = 75; %half length of improfile line
int_num = 5; % Number of improfile lines
int = len/int_num;
offset = 1;
x0 = pos(1) + caty*hp/len; %top point x coordinate
y0 = pos(3) - catx*hp/len; %top point y coordinate
x1 = pos(1) - caty*hp/len; %bottom point x coordinate
y1 = pos(3) + catx*hp/len; %bottom point y coordinate
for i=0:1:int_num
x0 = x0 + i*int*(catx*hp/len);
y0 = y0 + i*int*(caty*hp/len);
x1 = x1 + i*int*(catx*hp/len);
y1 = y1 + i*int*(caty*hp/len);
xi= [x1 x0];
yi= [y1 y0];
line(xi,yi);
profile_3d = improfile(I,xi,yi);
Vprofile_1d = profile_3d(:,:,1);
Hprofile_1d = rot90(Vprofile_1d);
xlswrite('NAME.xlsx',Hprofile_1d,1, sprintf('A%d',offset));
offset = offset + 1;
end

Answers (1)

Image Analyst
Image Analyst on 30 Jun 2014
Well, what are the values of xi and yi when that happens?

Community Treasure Hunt

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

Start Hunting!