フィルターのクリア

code does not seem to work but is not giving any errors

1 回表示 (過去 30 日間)
Lewis Laurence
Lewis Laurence 2022 年 1 月 26 日
コメント済み: Lewis Laurence 2022 年 1 月 27 日
I=imread('phonebox2_noisy.bmp');
a=I;
[row, col, channel]=size(a);
red=a(:,:,1);
green=a(:,:,2);
blue=a(:,:,3);
a1 = red;
a2 = green;
a3 = blue;
for i=2:1:row-1
for j = 2:1:col-1
a1(i,j)= (red(i-1,j-1)+red(i-1,j)+red(i-1,j+1)+red(i,j-1)+red(i,j)+red(i,j+1)+...
red(i+1,j-1)+red(i+1,j)+red(i+1,j+1));
a1=sort(a1);
red(i,j)= a1(5);
a2(i,j)= (green(i-1,j-1)+green(i-1,j)+green(i-1,j+1)+green(i,j-1)+green(i,j)+green(i,j+1)+...
green(i+1,j-1)+green(i+1,j)+green(i+1,j+1));
a2=sort(a2);
green(i,j)= a2(5);
a3(i,j)= (blue(i-1,j-1)+blue(i-1,j)+blue(i-1,j+1)+blue(i,j-1)+blue(i,j)+blue(i,j+1)+...
blue(i+1,j-1)+blue(i+1,j)+blue(i+1,j+1));
a3=sort(a3);
blue(i,j)= a3(5);
end
end
final=cat(3,red,green,blue);
figure;
imshow(a);
title('latte noisy');
figure;
imshow(final);
title('latte');
  1 件のコメント
Benjamin Thompson
Benjamin Thompson 2022 年 1 月 27 日
Can you post your bitmap? It runs on the coloredChips.png sample image that comes with MATLAB, though I don't know what the output is supposed to look like. Sometimes bitmaps are not 24 bit color, try using imfinfo on your image.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 1 月 26 日
a1(i,j)= (red(i-1,j-1)+red(i-1,j)+red(i-1,j+1)+red(i,j-1)+red(i,j)+red(i,j+1)+...
red(i+1,j-1)+red(i+1,j)+red(i+1,j+1));
As written, that is a problem because red is going to be an integer data type such as uint8, and adding uint8 gives you a uint8 -- which will very likely overflow.
a1=sort(a1);
You are doing that within the loop. So you are replacing one element of a1 at a time, and sorting the entire a1 array.
red(i,j)= a1(5);
a1 is a 2D array the same size as red so a1(5) is likely to be the same as a1(5,1)
I get the impression that your code is attempting to do a median filter. To do a median filter "by hand" (instead of using medfilt2() ) you should not add those elements of red, you should extract them. For example,
a1 = red(i-1:i+1, j-1:j+1);
a1 = sort(a1(:));
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 27 日
I would recommend just using medfilt2() .
If for some reason you can't use that, then
a1 = red(i-1:i+1, j-1:j+1);
red(i,j) = median(a1(:));
and if you are not even permitted to use median() then
a1 = red(i-1:i+1, j-1:j+1);
a1 = sort(a1(:));
red(i,j) = a1(5);
Lewis Laurence
Lewis Laurence 2022 年 1 月 27 日
thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by