0% found this document useful (0 votes)
27 views

Image Processing Programs

This document contains code snippets demonstrating various image processing techniques in MATLAB, including reading and displaying an image, separating an image into RGB color channels, converting a grayscale image to binary, creating image histograms, Wiener filtering for noise removal, median filtering to reduce salt and pepper noise, and detecting edges using Prewitt, Sobel, and Roberts methods.

Uploaded by

rahish tandel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Image Processing Programs

This document contains code snippets demonstrating various image processing techniques in MATLAB, including reading and displaying an image, separating an image into RGB color channels, converting a grayscale image to binary, creating image histograms, Wiener filtering for noise removal, median filtering to reduce salt and pepper noise, and detecting edges using Prewitt, Sobel, and Roberts methods.

Uploaded by

rahish tandel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program:read and display image

clc;
closeall;
clearall;
I = imread('shadow.tif');
imshow(I);
info=imfinfo('shadow.tif');
imshow('shadow.tif');
Program: RGB Component of an Image
I=imread('autumn.tif');
r=I(:,:,1);
g=I(:,:,2);
b=I(:,:,3);
figure;
imshow(r);
figure;
imshow(g);
figure;
imshow(b);
Program:to convert gray scale image into binary image
clearall;
I = imread('pout.tif');
imshow(I)
info=imfinfo('pout.tif');
imshow('pout.tif');
bw=im2bw(I);
imshow(bw);

Histogram
I=imread('moon.tif');
imshow(I);
figure, imhist(I)
I=imread('circles.png');
imshow(I);
figure, imhist(I)
I=imread('cell.tif');
imshow(I);
figure, imhist(I)
I=imread('moon.tif');
imshow(I);
figure, imcontour(I,3)

% program of Winear filtering


I = im2double(imread('cameraman.tif'));
imshow(I);
title('Original Image (courtesy of MIT)');
LEN = 21;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
imshow(blurred);
title('Blurred Image');
wnr1 = deconvwnr(blurred, PSF, 0);
imshow(wnr1);
title('Restored Image');
noise_mean = 0;
noise_var = 0.0001;
blurred_noisy = imnoise(blurred, 'gaussian', noise_mean, noise_var);
imshow(blurred_noisy)
title('Simulate Blur and Noise')
wnr2 = deconvwnr(blurred_noisy, PSF, 0);
imshow(wnr2)
title('Restoration of Blurred, Noisy Image Using NSR = 0')
signal_var = var(I(:));
wnr3 = deconvwnr(blurred_noisy, PSF, noise_var / signal_var);
imshow(wnr3)
title('Restoration of Blurred, Noisy Image Using Estimated NSR');

%MEDIAN FILTERING
clc;
close all;
I = imread('autumn.tif');
J = imnoise(I,'salt & pepper',0.2);
%
r
g
b

filter each channel separately


= medfilt2(J(:, :, 1), [3 3]);
= medfilt2(J(:, :, 2), [3 3]);
= medfilt2(J(:, :, 3), [3 3]);

% reconstruct the image from r,g,b channels


K = cat(3, r, g, b);%concatenates the arrays r,g,b along 3.
figure
subplot(121);imshow(J);
subplot(122);imshow(K);

%edges of an image using the Prewitt , Sobel and Roberts methods.


clc;
close all;
i = imread('autumn.tif');
I = rgb2gray(i);
BW1 = edge(I,'prewitt');
BW2= edge(I,'sobel');
BW3= edge(I,'roberts');
subplot (2,2,1);
imshow(I);
title('original');
subplot(2,2,2);
imshow(BW1);
title('Prewitt');
subplot(2,2,3);
imshow(BW2);
title('Sobel');
subplot(2,2,4);
imshow(BW3);
title('Roberts');

You might also like