mean filter special matrix apply to image. Salt and pepper noise
4 次查看(过去 30 天)
显示 更早的评论
How can I apply mean filter like 3x3 square neigboorhod following matrix?
mean4=[0,1,0;1,1,1;0,1,0];
I would like to apply with noise image this method. Here is my code:
orgim=imread('coins.png');
figure
imshow(orgim)
saltpeppern = imnoise(orgim,'salt & pepper');
figure
imshow(saltpeppern)
0 个评论
回答(3 个)
DGM
2021-12-20
Normalize the filter sum and apply it with imfilter().
originalimg = imread('coins.png');
noisyimg = imnoise(originalimg,'salt & pepper');
fk = [0,1,0;1,1,1;0,1,0]/5; % unit sum
avgfiltimg = imfilter(noisyimg,fk);
imshow(originalimg)
figure; imshow(noisyimg)
figure; imshow(avgfiltimg)
yanqi liu
2021-12-20
clc; clear all; close all;
mean4=[0,1,0;1,1,1;0,1,0];
% i would like to apply with noise image this method.here is my code;
orgim=imread('coins.png');
figure
imshow(orgim)
saltpeppern = imnoise(orgim,'salt & pepper');
figure
imshow(saltpeppern)
% use imfilter
im1 = imfilter(double(saltpeppern), mean4, 'replicate');
% use conv2
im2 = conv2(double(saltpeppern), mean4, 'same');
% use fft
im3 = real(ifft2(fft2(double(saltpeppern)).*fft2(mean4, size(saltpeppern,1), size(saltpeppern,2))));
% display
figure; imshow(im1, []); title('use imfilter');
figure; imshow(im2, []); title('use conv2');
figure; imshow(im3, []); title('use fft');
Image Analyst
2021-12-20
See my attached salt and pepper demos. It adds noise to the original image, then takes the median filter of the image. Then it identified the location of the noise and replaces only those noise pixels with the median filtered value.

另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







