I am trying to alter some voxel values in Matlab.
I am using the following code:
for p=1:100
Vol(Vol(:,:,p) > 0) = 65535; %altering voxel values in the volume to 65535 if value > 0.
end
Unfortunately, I find all the values being altered, as if the condition is not working, although if i write Vol(Vol(:,:,1)>0)= 65535 immediately in the command line it works perfectly.
Any clue where the error is??

 채택된 답변

Ben11
Ben11 2014년 7월 14일
편집: Ben11 2014년 7월 14일

0 개 추천

It looks like when you use this line:
Vol(Vol(:,:,p) > 0) = 65535
you are in fact referring to a 2D matrix corresponding to a single channel from an image instead of a 3-channel image from your volume. I think it would save you trouble if you used this:
Vol(Vol > 0) = 65535;
instead of your for-loop, since you would then replace all the pixel values greater than 0 with 65535.
EDIT:
I just saw that you asked this question on Stack Overflow, good idea by the way, and that Ray provided a very thorough explanation! Anyhow I hope it is clearer for you now :)

댓글 수: 4

Noha Asas
Noha Asas 2014년 7월 14일
Ohhh...it worked :). Many thanks :).
But still what I should do if I want to use same syntax for thresholding image by image in a volume ?? It will still give the same false response.
and still I don't understand why it worked when I write the index explicitly: Vol(Vol(:,:,1)>0)=65535; outside the loop and it doesn't work inside the loop.
Thanks for the help, appreciate it :).
Great! If the answer helped you please mark it as accepted :)
If you need to threshold every image individually you can create a matrix containing an 'extra' dimension, so that you can access both the channel AND the image of your choice while looping in the volume. For instance:
% First you might want to initialize the array. Here I declare 'uint16' as the type of data.
Vol = zeros(ImageHeight,ImageWidth,NumberChannels,NumberImages,'uint16') % NumberChannels is probably 3.
for p = 1:100
% Add you code
Vol(Vol(:,:,ChannelofInterest,p) > 0) = 65535;
end
Note that if you want to threshold on all channels you can use rgb2gray(YourImage).
Hope that helps! If not please ask for more details.
Noha Asas
Noha Asas 2014년 7월 23일
Many thanks again....that's very helpful :). Sorry for late response....was away from internet connection.
Ben11
Ben11 2014년 7월 24일
No problem! Glad I could help :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

질문:

2014년 7월 14일

댓글:

2014년 7월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by