Replacing centre pixel value

I have a code ,of 7x7 natrix in that for each 3x3 i have found minimum value and if that minimum value is greater the centre pixel value ,the centre pixel value must be replaced by 5.have problem in replacing centre pixel value ,please help
for i=2:6
for j=2:6
K= A(i-1:i+1,j-1:j+1);
T=K(2,2);finding centre pixel value
B=min(K(:));
if B>T
%%%please tell what must come here replacing centre pixel vaue by 5
%%%%I DID K(2,2)=5;
else
%%%%%%%%%here also
%%I DID K=K;
end
end
end
BUT I GET 3x3 matrix only,how to get 7x7 matrix
please assist
please assist

1 comentario

Image Analyst
Image Analyst el 19 de Dic. de 2012
You've been posting here long enough that you should already know how to format your questions. Please review the tutorial http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup. By the way, you can type Ctrl-A, Ctrl-I, Ctrl-C when your code is in MATLAB to fix indenting problems. Then come here and paste it in, highlight it, and click {}Code. Do not have any spaces before non-code text (like your first paragraph). It's not hard - give it a try.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 19 de Dic. de 2012

0 votos

The minimum value in a 7x7 window will never be greater than the center value. Please explain what you are thinking.
By the way, you can call imerode() to get the local min values in a 7x7 sliding window.

3 comentarios

FIR
FIR el 19 de Dic. de 2012
Just it is an example ,i want to try on my own ,the concept which i was given,the above explaination is just the concept,finallyy i need 7x7 but i get only 3x3
Image Analyst
Image Analyst el 19 de Dic. de 2012
Editada: Image Analyst el 19 de Dic. de 2012
But the concept is flawed! Anyway, you might play around and use imerode and subtract it from your original, or vice-versa. Then threshold and replace items meeting the threshold with 5. I think you already know how to do that without loops. Even if you did want to use loops, you'd have to have 4 loops, not 2. Two to scan rows and columns, and then at each pixel, another two loops (like you already have) to scan a window around that pixel. But not a very efficient way to do it. I suggest you review the code examples I gave you in your prior, related questions.
FIR
FIR el 20 de Dic. de 2012
Can u please post an example here please,i could nor review the codes since there are many questions posted by me

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 19 de Dic. de 2012

0 votos

A(i,j) = 5;

6 comentarios

FIR
FIR el 20 de Dic. de 2012
s walter but i get only 3x3 window,but i need 7x7
Walter Roberson
Walter Roberson el 20 de Dic. de 2012
Your question in your code comments was
%%please tell what must come here replacing centre pixel vaue by 5
and that assignment answers that question.
If you want a 7 x 7 window then replace
K= A(i-1:i+1,j-1:j+1);
with
K= A(i-3:i+3,j-3:j+3);
FIR
FIR el 20 de Dic. de 2012
I GET ERRPR
Subscript indices must either be real positive integers or logicals.
7X7 window i meant is after processing ,in the code above i have taken 3x3 and have processed ,in which my last 3x3 window is displayed.but how to display as 7x7 which is after processing,and same size of input matrix
Walter Roberson
Walter Roberson el 20 de Dic. de 2012
In that case do not use K= A(i-3:i+3,j-3:j+3); and use the original instead, and use
A(i,j) = 5;
like I originally indicated. The output will be A.
This is for replacing the center pixel like you asked. It probably isn't what you wanted, though, as replacing the center pixel as you proceed is going to affect the computations to the right and below. What you probably want is to output a new array that is like the original array but with the center pixels replaced. Such as
newA = A;
for i=2:6
for j=2:6
K= A(i-1:i+1,j-1:j+1);
T=K(2,2);finding centre pixel value
B=min(K(:));
if B>T
newA(i,j) = 5;
else
%I could not tell what you want done in this case
end
end
end
FIR
FIR el 20 de Dic. de 2012
ok walter thanks
can u guide me in quanterion switching filter,please
Walter Roberson
Walter Roberson el 20 de Dic. de 2012
I do not know anything about quaternion switching filters.

Iniciar sesión para comentar.

Categorías

Más información sobre Scripts en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

FIR
el 19 de Dic. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by