two for loops problem

1 次查看(过去 30 天)
Hi everyone,
here i want to get pixel intensity out of a 512*512 image.
i wrote two for loops, but in the end in matrix 'intensityValue', l got only the last set of data.
the background is to get the coordinates from x and y. corx and cory are 41*75 matrices.
Thanks !
fluo = imread('fluo0020.tif');
% imshow(fluo);
corx=[];
cory=[];
intensityValue=[];
for i=1:length(coordinate)
A = [coordinate ; coordinate(1,:)] ;
if mod(i, 2) == 1
x= int16(A(:,i));
y= int16(A(:,(i+1)));
corx=[corx,x];
cory=[cory,y];
end
% scatter(x,y);
% line(x,y);
% hold all
end
for ttt=1:length(x)
xc=x(ttt,:);
xy=y(ttt,:);
inten=fluo(xc,yc);
intensityValue =[intensityValue;inten];
end
  3 个评论
yunwei hu
yunwei hu 2020-3-6
i am still new to write the code.... it's true there not so much logic..
what l tried to get is the same corresponding values(the same row and column) from corx and cory, which l have uploaded. They are actually the x and y coordinates.
And from the two vuales, i get the intensity from the image.
the final intensityValue i expected is a 42*75 matrix
Thank you for your reply!
Ameer Hamza
Ameer Hamza 2020-3-6
Please check the one-liner in the answer to directly extract the value instead of writing a for loop.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-3-6
编辑:Ameer Hamza 2020-3-6
You are directly use corx and cory variables to extract values from the matrix instead of the second for loop in your code.
intensityValue = fluo(sub2ind(size(fluo), cory, corx)); % cory is the row number and corx is the column number
  7 个评论
Ameer Hamza
Ameer Hamza 2020-3-6
As you can see, the image dimension is 512x512, and some elements of corx and cory are higher than 512. Therefore it is throwing an error. I guess that there is some issue in the calculation of the corx and cory in the first loop.
yunwei hu
yunwei hu 2020-3-6
Now i see.
i would check the data again.
thank you so much for your help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by