Effacer les filtres
Effacer les filtres

my code doesnt go into the loop

2 vues (au cours des 30 derniers jours)
prem preet
prem preet le 13 Nov 2011
picture = imread ('C:\Users\prempreet\Desktop\lena512color.tiff');
noisy_picture= imnoise (picture,'salt & pepper', 0.10)
% image = picture(: , :);
image_red = picture (:, :, 1);
image_green = picture (:, :, 2);
image_blue = picture (:, :, 3);
redChannel = noisy_picture(:, :, 1);
greenChannel = noisy_picture(:, :, 2);
blueChannel = noisy_picture(:, :, 3);
%median = medfilt2 ( image );
red_median = medfilt2 (redChannel);
blue_median = medfilt2 (blueChannel);
green_median = medfilt2 (greenChannel);
difference_red = abs (redChannel - red_median);
difference_blue = abs (blueChannel - blue_median);
difference_green = abs (greenChannel - green_median);
difference_red = im2double (difference_red);
difference_green = im2double (difference_green);
difference_blue = im2double (difference_blue);
[m n] = size (difference_red);
while ( i == 2:m-1 && j == 2:n-1 )
a1 = [difference_red(i-1,j-1), difference_red(i-1,j), difference_red(i-1,j+1), difference_red(i,j-1), difference_red(i,j), difference_red(i,j+1),difference_red(i+1,j-1), difference_red(i+1,j), difference_red(i+1,j+1)];
b1 = [difference_blue(i-1,j-1), difference_blue(i-1,j), difference_blue(i-1,j+1), difference_blue(i,j-1), difference_blue(i,j), difference_blue(i,j+1), difference_blue(i+1,j-1), difference_blue(i+1,j), difference_blue(i+1,j+1)];
c1 = [difference_green(i-1,j-1), difference_green(i-1,j), difference_green(i-1,j+1),difference_green(i,j-1), difference_green(i,j), difference_green(i,j+1), difference_green(i+1,j-1), difference_green(i+1,j), difference_green(i+1,j+1)];
a2 = a1(a1<=0.7);
b2 = b1 (b1<= 0.7);
c2 = c1 (c1<=0.7);
med_red (i,j)= median (a2);
med_blue (i,j)= median (b2);
med_green (i,j)= median (c2);
the code doesnt go into the loop.......
  1 commentaire
Jan
Jan le 13 Nov 2011
The question would be much easier to understand, if yo omit all unnecessary details. Actually you need these two lines only:
[m n] = size (difference_red);
while ( i == 2:m-1 && j == 2:n-1 )
The rest is only confusing.

Connectez-vous pour commenter.

Réponse acceptée

Wayne King
Wayne King le 13 Nov 2011
That is not correct syntax for a while loop. For example:
% This does not work!
n = 1;
while (n==1:4)
disp('Hi');
n = n+1;
end
% This works!
n = 1;
while (n>=1 & n<4)
disp('Hi');
n=n+1;
end
Without getting in the specifics of your code, how about trying:
for i=2:m-1
for j = 2:n-1
...
...
end
end
  2 commentaires
prem preet
prem preet le 13 Nov 2011
its doesnt work sir ......
the code still dont go into the loop
Jan
Jan le 13 Nov 2011
@prem: Accepting an answer means, that your problem is solved. But you comment sounds, like there are still problems.
Please explain exactly, what you have changed.

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 13 Nov 2011
[m, n] = size (difference_red);
while ( i == 2:m-1 && j == 2:n-1 ) % Not working
The argument of while contains vectors: "i == 2:m-1" is a LOGICAL vector. But the && operator works on scalars only. If you use the & or and() operation, the next problem occurs: Then the two logical vectors i==2:m-1 and j==2:n-1 must have the same number of elements or one must be a scalar, because the and works elementwise.
Assuming that both LOGICAL vectors have teh same size accidently, the next problem occurs: If the argument of while or if is not a scalar, a all is inserted automatically:
while all(i == 2:m-1 & j == 2:n-1)
But there is always an element, which is not true in the vector (if it can be evaluated at all, see above). Therefore I assume the two FOR loops suggested by Wayne are doing what your want.

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by