constructiong 3x3 matrix window

I am designing a filter removing impulses noises from an RGB IMAGE
For identifying the noise pixels in the image I need a 3x3 window to slide over the image starting from the first Pixel to the Last.
If the corrupted Pixel is found i have to do some calculation to correct it.
To find this Corrupted Pixel I need a 3x3 Window to slide over my Image.
please send me the code for this

 採用された回答

Matt J
Matt J 2012 年 12 月 19 日

0 投票

Hint - the CONV command

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 12 月 19 日

0 投票

blockproc()

7 件のコメント

FIR
FIR 2012 年 12 月 19 日
Walter this command is used to divide into blocks,but how it will be appropiate for my question
Walter Roberson
Walter Roberson 2012 年 12 月 19 日
Actually the older blkproc() would be more suitable for sliding blocks
blockproc() is not just for dividing into blocks: it is for processing each of the divided blocks and creating an output. However, it is for distinct blocks which would be a nuisance in your situation.
Matt J
Matt J 2012 年 12 月 19 日
No, blockproc can handle sliding blocks as well, by suitable use of the BorderSize parameter.
CONV could be superior to both in speed, however. It is advisable to see whether the desired operation can be decomposed into convolution steps.
Walter Roberson
Walter Roberson 2012 年 12 月 19 日
Hey, cute! blockproc() on 1x1 blocks with BorderSize [1 1]. Nice.
FIR
FIR 2012 年 12 月 19 日
did u mean like
x=myimage;
img = zeros(size(x));
filtImg = conv2(img,Gaussian,'same');
FIR
FIR 2012 年 12 月 19 日
or
I = imread(...)
kernel = ones(3, 3) / 9; % 3x3 mean kernel
J = conv2(I, kernel, 'same');
Walter Roberson
Walter Roberson 2012 年 12 月 19 日
Matt J is referring to the second of those forms, where you create your own kernel.

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

Image Analyst
Image Analyst 2012 年 12 月 19 日

0 投票

FIR, I've ALREADY posted code to get rid of impulse noise. In fact it was to your very own question just a few days ago! Perhaps you've forgotten, or just ignored my answer. Here is the link: http://www.mathworks.com/matlabcentral/answers/56515#answer_68417 If you want to replace noise pixels with blurred pixels, just replace the medfilt2() with conv2() like Matt said, though I don't know why you'd do that because you'd be designing a worse filter.

6 件のコメント

FIR
FIR 2012 年 12 月 20 日
Sir if i procees with that code for RGB image i get error
Error using ==> iptcheckinput Function MEDFILT2 expected its first input, A, to be two-dimensional.
Walter Roberson
Walter Roberson 2012 年 12 月 20 日
Divide the image into the three color planes and process the planes one by one, and afterwards put the results back together into a single image.
FIR
FIR 2012 年 12 月 20 日
ok walter i tried that ,but is that the same as processing directly on colour images
Walter Roberson
Walter Roberson 2012 年 12 月 20 日
Put in a breakpoint just at the medfilt2() call. Check size() of the array you are passing in to medfilt2(). If the array is 3 dimensional, then you have not separated the color planes.
FIR
FIR 2012 年 12 月 20 日
no walter my question is without separating the RGB image to ,R,G,B plane can we directly proceed on RGB IMAGE,i dont want to separate into planes ,is it possible
Walter Roberson
Walter Roberson 2012 年 12 月 20 日
Not using the code posted by Image Analyst. That code could be altered to effectively pull apart the planes without looking like it was pulling apart the planes. You can for example create a routine similar to medfilt2() but which accepts an RGB image and does plane-by-plane filtering internally.
You need to ask yourself, though, what it means to do a median() with respect to values that have three components (R, G, B), and how that differs from [median®, median(G), median(B)] applied individually. The problem becomes rather similar to that of comparing two complex numbers: just as there is no defined sorting order for all P < Q when P and Q are complex, there is also no defined sorting order for all (R1,G1,B1) < (R2,G2,B2) pixels. Without a defined sorting order, you cannot determine median() as median() requires logically fully ordering the values to find which value is in the "middle" of the fully ordered list.

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

質問済み:

FIR
2012 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by