image thumbnail

Max filter

by

 

This code is used for max filter

maxfilter.m
clc;
clear all;
close all;

a=uigetfile('*.*','Select the Image:-');
a=imread(a);
% aa=isrgb(a);
% if aa==1
    a=rgb2gray(a);
% end
b1=double(a);
c=imnoise(a,'salt & pepper',0.2);
d=double(c);
b=d;
m=(1/9)*(ones(3,3));
[r1,c1]=size(a);

for i=2:r1-1
    for j=2:c1-1
        a1=[d(i-1,j-1) d(i-1,j) d(i-1,j+1) d(i,j-1) d(i,j) d(i,j+1) d(i+1,j-1) d(i+1,j) d(i+1,j+1)];
        a2=sort(a1);
        med=a2(9);
        b(i,j)=med;
    end
end

subplot(131);imshow(uint8(a));title('Original Image');
subplot(132);imshow(uint8(c));title('Image Currepted by Salt & Pepper Noise');
subplot(133);imshow(uint8(b));title('Filtered Image 3 x 3 mask');

Contact us