my code doesnt go into the loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Jan
2011년 11월 13일
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.
채택된 답변
Wayne King
2011년 11월 13일
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
Jan
2011년 11월 13일
@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.
추가 답변 (1개)
Jan
2011년 11월 13일
[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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!