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

I don't fully understand the logic of this code, however, shouldn't the last part be,
for ttt=1:length(corx)
xc=corx(ttt,:);
xy=cory(ttt,:);
inten=fluo(xc,yc);
intensityValue =[intensityValue;inten];
end
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일

0 개 추천

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

yunwei hu
yunwei hu 2020년 3월 6일
Hi Ameer,
there is an error "Out of range subscript."
you are right about that l am extracting values form two matrices.
but l am not sure about the row number and column number, since both corx and cory are the matrix have the same number of rows and columns, as l uppolded before.
But the corx and cory are extracting the values from fluo. Do the elements of corx denotes the row number of the pixel in flou or the column number?
I suspect that, if you got out of bound error, the following might be the correct.
intensityValue = fluo(sub2ind(size(fluo), corx, cory));
yunwei hu
yunwei hu 2020년 3월 6일
corx is the row number.
but l tried this code as well.
the same error occured.
Could be that the number in corx or cory exceed 512?
Since i turned to all into int16, maybe this could be the problem?
Ameer Hamza
Ameer Hamza 2020년 3월 6일
This depends on the resolution of you image file. The number in corx and cory should not exceed the image dimensions.
If possible share the image file and the value of variable coordinate in a mat file.
yunwei hu
yunwei hu 2020년 3월 6일
i share the files
they should not exceed l suppose.
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개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 3월 6일

댓글:

2020년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by