Embed presentation
Download to read offline
![1
Q:apply built_in average ,median, blur and salt & pepper filter onimage in
matlab ?
Alsoapply image convolution?
Code:
clc
close all
I=imread('C:UsersAdministratorDesktopdahlia-red-blossom-bloom-
60597.jpeg');
figure
imshow(I);
%salt and pepper filter
noisy=imnoise(I, 'salt& pepper',0.1);
figure;
imshow(noisy);
%medianfilter(use toremove noise ,work only on gray images)
noisy=rgb2gray(noisy);
median=medfilt2(noisy,[3 3]);
figure
imshow(median);
%average filter
kaverage=filter2(fspecial('average',3),I)/255;
figure
imshow(kaverage);
%blur filter
h=fspecial('motion',10,20);
blur=imfilter(I,h);
figure
imshow(blur);
%convolutionon images
R=[-1 0 1,-1 0 1,-1 0 1];
W=[-1 0 1,-1 0 1,-1 0 1];
con=conv(R,W);
disp(con);
subplot(311);plot(R);subplot(312);plot(W);subplot(313);plot(con);
subplot(311);stem(R);subplot(312);stem(W);subplot(313);stem(con);](https://image.slidesharecdn.com/ai20assignment4-180909191942/85/matlab-filter-code-1-320.jpg)

This document contains Matlab code to apply several common image filters and operations to an image. It adds salt and pepper noise to the image using imnoise, applies a median filter using medfilt2 to remove noise, uses an average filter with filter2, applies a blur filter with imfilter, and performs convolution on the image with conv. It displays the original image and the results of each filter/operation.
![1
Q:apply built_in average ,median, blur and salt & pepper filter onimage in
matlab ?
Alsoapply image convolution?
Code:
clc
close all
I=imread('C:UsersAdministratorDesktopdahlia-red-blossom-bloom-
60597.jpeg');
figure
imshow(I);
%salt and pepper filter
noisy=imnoise(I, 'salt& pepper',0.1);
figure;
imshow(noisy);
%medianfilter(use toremove noise ,work only on gray images)
noisy=rgb2gray(noisy);
median=medfilt2(noisy,[3 3]);
figure
imshow(median);
%average filter
kaverage=filter2(fspecial('average',3),I)/255;
figure
imshow(kaverage);
%blur filter
h=fspecial('motion',10,20);
blur=imfilter(I,h);
figure
imshow(blur);
%convolutionon images
R=[-1 0 1,-1 0 1,-1 0 1];
W=[-1 0 1,-1 0 1,-1 0 1];
con=conv(R,W);
disp(con);
subplot(311);plot(R);subplot(312);plot(W);subplot(313);plot(con);
subplot(311);stem(R);subplot(312);stem(W);subplot(313);stem(con);](https://image.slidesharecdn.com/ai20assignment4-180909191942/85/matlab-filter-code-1-320.jpg)
