my code doesnt go into the loop
Afficher commentaires plus anciens
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
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.
Réponse acceptée
Plus de réponses (1)
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 Image Arithmetic dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!