Beruflich Dokumente
Kultur Dokumente
INDEX
5. 9-9
Program for dilation of image.
Experiment No: 1
MATLAB Code:
clear,close all;
I=imread('testpat1.png');
figure,imshow(I);
J=imread('rice.png');
figure,imshow(J);
K=imadd(I,J);
figure,imshow(K);
a)Testpat1.png b)
rice.png
Added Image
Experiment No: 2
Aim: Program for bilinear rotation of an image
MATLAB Code:
clear,close all;
I=imread('trees.tif');
J=imrotate(I,35,'bilinear');
imshow(I);
figure,imshow(J);
OUTPUT:
Experiment No: 3
Aim: Program for 2d Median Filtering for Salt and Pepper Noise without using
MEDFILT2 Function.
Theory:
MEDIAN FILTER:
In digital Image processing , removing the noise is one of the preprocessing techniques.
The image noise may be termed as random variation of brightness or color information.
There are various types of image noise.
The random occurrence of black and white pixels is salt and pepper noise.
Median filtering preserves the image without getting blurred. Median filtering is done on an
image matrix by finding the median of the neighborhood pixels by using a window that
slides pixel by pixel.
MATLAB Code:
%READ AN 2D IMAGE
A=imread('zebra.jpg');
title('IMAGE WITH SALT AND PEPPER NOISE');
figure,imshow(A);
for i= 1:size(modifyA,1)-2
for j=1:size(modifyA,2)-2
window=zeros(9);
inc=1;
for x=1:3
for y=1:3
window(inc)=modifyA(i+x-1,j+y-1);
inc=inc+1;
end
end
med=sort(window);
%PLACE THE MEDIAN ELEMENT IN THE OUTPUT MATRIX
B(i,j)=med(5);
end
end
%CONVERT THE OUTPUT MATRIX TO 0-255 RANGE IMAGE TYPE
B=uint8(B);
title('IMAGE AFTER MEDIAN FILTERING');
figure,imshow(B);
Experiment No: 4
MATLAB Code:
%.%
function makecode(sc, codeword)
% Scan the nodes of a Huffman source reduction tree recursively to
% generate the indicated variable length code words.
% Global variable surviving all the recursive calls
global CODE
if isa(sc,cell) % For cell array nodes,
makecode(sc{1},[codeword 0]); % add 0 if the 1st element,
makecode(sc{2}, [codeword 1]); % or a 1 if the 2nd
else % For leaf (numeric) nodes,
CODE{sc} = char(0 + codeword); % create a char code string
end
Result:
Experiment No: 5
Aim: Program for Dilation Operation
MATLAB Code:
I = IMREAD('CAMERAMAN.TIF');
SE = STREL('BALL',5,5);
I2 = IMDILATE(I,SE);
IMSHOW(I), TITLE('ORIGINAL')
FIGURE, IMSHOW(I2), TITLE('DILATED')
OUTPUT
Experiment No: 6
Aim: Program for Erosion operation.
MATLAB Code:
I = imread('cameraman.tif');
se = strel('ball',5,5);
I2 = imerode(I,se);
imshow(I), title('Original');
figure, imshow(I2), title('Eroded');
OUTPUT
Experiment No: 7
MATLAB Code:
clear;
close all;
I= imread('moon.tif');
imshow(I);
figure, imhist(I);
OUTPUT:
Experiment No: 8
MATLAB Code:
clear;
close all;
I = imread('coins.PNG');
k= imcomplement(I);
imview(I);
imview(k);
OUTPUT:
image 1 image2
image 3 image4
Experiment No: 9
Aim: Program for detecting edges in an image
Theory:
Syntax :
BW = edge(I)
BW = edge(I,'sobel')
BW = edge(I,'prewitt')
BW = edge(I,'roberts') etc.
Description :
BW = edge(I) takes a grayscale or a binary image I as its input, and returns a binary image
BW of the same size as I, with 1's where the function finds edges in I and 0's elsewhere.
By default, edge uses the Sobel method to detect edges but the following provides a
complete list of all the edge-finding methods supported by this function:
The Sobel method finds edges using the Sobel approximation to the derivative. It
returns edges at those points where the gradient of I is maximum.
The Prewitt method finds edges using the Prewitt approximation to the derivative. It
returns edges at those points where the gradient of I is maximum.
The Roberts method finds edges using the Roberts approximation to the derivative. It
returns edges at those points where the gradient of I is maximum.
The Laplacian of Gaussian method finds edges by looking for zero crossings after
filtering I with a Laplacian of Gaussian filter.
The zero-cross method finds edges by looking for zero crossings after filtering I with
a filter you specify.
The Canny method finds edges by looking for local maxima of the gradient of I. The
gradient is calculated using the derivative of a Gaussian filter. The method uses two
thresholds, to detect strong and weak edges, and includes the weak edges in the
output only if they are connected to strong edges. This method is therefore less likely
than the others to be fooled by noise, and more likely to detect true weak edges.
The parameters you can supply differ depending on the method you specify. If you do not
specify a method, edge uses the Sobel method.
MATLAB Code:
i = imread('far.jpg');
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');
Result:
The edge detection of the image is done.