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

Respuestas (1)

Image Analyst
Image Analyst el 30 de Ag. de 2014

0 votos

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 comentarios

M
M el 30 de Ag. de 2014
doesn't matter with the name, its a chosen intensity for an area I want to change its color. I don't exactly know their values so I pick a point inside that area and compare to it, and there were a plenty of voxels with the same intensity in the image.
What is "stepping through with the debugger" means?
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
M el 30 de Ag. de 2014
CSF is the Cerebrospinal fluid in brain and GM is gray matter in brain, I have clustered images of brains, and I need to extract mask for the CSF by changing their color and comparing it.
I was using 4 "if" to make sure I keep same number of clusters after altering the image.
Image Analyst
Image Analyst el 30 de Ag. de 2014
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 el 30 de Ag. de 2014
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

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Preguntada:

M
M
el 30 de Ag. de 2014

Comentada:

M
M
el 30 de Ag. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by