alter image pixels intensities, gray scale image
이전 댓글 표시
So I was trying to make simple pixel alteration in an image by the following code
CSF = IMG(147,53,24);
BG = IMG(1,1,24);
for i=1:256
for j=1:256
for k=1:50
if(IMG(i,j,k)==CSF)
IMG(i,j,k)=1;
elseif(IMG(i,j,k)==BG)
IMG(i,j,k)=0;
elseif (IMG(i,j,k)==1)
IMG(i,j,k)=CSF;
elseif (IMG(i,j,k)==0)
IMG(i,j,k)=BG;
end
It is suppose to alter pixels with those specific intensities into the given ones. The BG part is working properly, but the CSF part won't alter properly and I don't know why
답변 (1개)
Image Analyst
2014년 8월 30일
0 개 추천
What is "the CSF part"? CSF is mentioned on 3 lines. What is the value of CSF and BG? They're some scalar numbers. It should do the "if" for CSF for at least one voxel, and that is the one at (1,1,24). Have you tried stepping through with the debugger?
댓글 수: 5
M
2014년 8월 30일
Image Analyst
2014년 8월 30일
View this to learn an indispensible skill http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
I don't know what you mean by "doesn't matter with the name". You did not answer my question. What are the values of CSF and GB. OK, take the semicolons off this line and tell me what you see in the command window.
CSF = IMG(147,53,24)
BG = IMG(1,1,24)
And why are you using 4 "if"s? What is the purpose of that? You're not simply binarizing the image. And there is potential conflicts, like what if IMG(i,j,k) = 5? Both the last two "if"s could apply.
M
2014년 8월 30일
Image Analyst
2014년 8월 30일
M, I'm trying to see if this can be sped up by vectorizing but it depends on the values of CSF and BG. If they can be 0 or 1, we have a problem, and have to stay with your 3 loops. If they're not, we can vectorize and do this in a faster, more MATLAB-ish way. I don't care what GM is - you didn't even have that in your code, but you still haven't told me what the values of CSF and BG are, even after I've asked twice before (3 times now ). Can you at least tell me if they might ever take on the values of 0 or 1? Just trying to help here but you're not making it easy.
M
2014년 8월 30일
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!