alter image pixels intensities, gray scale image

3 次查看(过去 30 天)
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
Image Analyst 2014-8-30
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 个评论
Image Analyst
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
M 2014-8-30
Sorry for the misunderstanding I don't know specifically what value are CSF and BG are, yes they can be 0 or 1. I am running that on many images and every image has its color distribution. I am planning to use a vectorized code as soon as I solve the problem. BUT the problem now is not with the time the 3 loops take, its with why is not that simple code working as it is supposed to

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by