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

DIP Matlab Program

The document contains descriptions of 25 MATLAB programming practicals involving digital image processing and analysis tasks. The practicals cover topics like importing images, modifying images, applying filters and transformations, performing morphological operations and more.

Uploaded by

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

DIP Matlab Program

The document contains descriptions of 25 MATLAB programming practicals involving digital image processing and analysis tasks. The practicals cover topics like importing images, modifying images, applying filters and transformations, performing morphological operations and more.

Uploaded by

Uday Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Practical No.

1
Aim: Introduction to the MATLAB commands

• clc :Clears command window


• clear : Removes the variables from memory
• cd :Changes the current directory
• date :Displays current date
• delete :Deletes a file
• find Finds the indices of nonzero elements
• max Returns the largest element
• min Returns the smallest element
• plot Generates xy plot
• title Puts title at the top of the plot
• linspace : creates regularly spaced vector
• zeros :Creates a matrix or array filled with zeros of size m-by-n.
• Ones :Creates a matrix or array filled with ones of size m-by-n.
• reshape : Reshapes a matrix or array into a new size specified by m and n.
• subplot :Creates plots in subwindows.
• hold :Hold the current graph, see also figure
Practical No. 2
Aim: Write a program to represent arrays in different ways

• a=[1 2 3; 4 5 6; 7 8 9]
• b=[3 :6]
• t =1:10
• k =2:-0.5:-1
• x= [1:4; 5:8]
• y = [1 2 5 1]
Practical No. 3
Aim: Write a program to perform various matrices arithmetic operation

• a=[1 2 3; 4 5 6; 7 8 9]
• b=[3 4 5; 1 4 5; 3 5 6]
• sum= a+b;
• sub=a-b;
• mult= a*b;
Practical No. 4
Aim: Write a program to prints out Pascal’s triangle:

• a=1
• while length(a) < 10
• a = [0 a] + [a 0]
• end
Practical No. 5
Aim: Write a program Plot the function sin(x) between 0≤x≤4π using linspace

• x=linspace(0,4*pi,100);
• y=sin(x);
• plot(y);
Practical No. 6
Aim: Write a program Plot the function sin(x) between 0≤x≤4π using stem function

• x=linspace(0,4*pi,100);
• y=sin(x);
• stem(y);
• stem(x,y);
Practical No. 7
Aim: Write a program to import Digital Images and convert the class of image into gray, and binary, also adjust the
intensity levels
a = imread('peppers.png');
subplot(1,4,1);
imshow(a);
title(‘Original Imae’);
b = rgb2gray(a);
subplot(1,4,2);
imshow(b);
title(‘Gray Image’);
c = im2bw(a);
subplot(1,4,3);
imshow(c);
title(‘Binary Image’);
d = imadjust(b);
subplot(1,4,4);
imshow(d);
title(‘Intensity Adjust’);
Practical No. 8
Aim: Write a program to import Digital Images and reduce the size of the image
(50%)
• I = imread('peppers.png’);
• J = imresize(I, 0.5);
• Subplot(1,2,1);
• imshow(I);
• title('Original Image’);
• Subplot(1,2,2);
• imshow(J);
• title(‘Resize Image’);
• sz1=size(I);
• sz2=size(J);

8
Practical No. 9
AIM: Write a program to import Digital Images and
clear perform arithmetic operations
close all;
a=imread('cameraman.tif');
b=imread('rice.png');
c=a+b; % addition
subplot(1,3,1);
imshow(c);
title(‘ADD. of Image 1 & 2’);
d=a-b; % subtraction
subplot(1,3,2);
imshow(d);
title(‘SUB. of Image 1 & 2’);
e=a.*b; % multiplication
subplot(1,3,3);
imshow(e);
title(‘Mult. of Image 1 & 2’);
9
Practical No. 10
AIM: Write a program to import Digital Images and
perform logical AND operations
• a= imread('cameraman.tif’);
• b= imread 'rice.png’);
• a1=im2bw(a);
• Subplot(1,3,1);
• imshow(a1);
• title(‘Binary Image a’);
• b1=im2bw(b);
• Subplot(1,3,2);
• imshow(b1);
• title(‘Binary Image b’);
• C=and(a1,b1);
• Subplot(1,3,3);
• imshow(c);
Practical No. 11
AIM: To import Digital Images and perform logical
OR operations
• a= imread('cameraman.tif’);
• b= imread(‘'rice.png’);
• a1=im2bw(a);
• Subplot(1,3,1);
• imshow(a1);
• title(‘Binary Image a’);
• b1=im2bw(b);
• Subplot(1,4,2);
• imshow(b1);
• title(‘Binary Image b’);
• C=or(a1,b1);
• Subplot(1,3,2);
• imshow(c);
• title(‘OR Image‘);
Practical No. 12
AIM: To import Digital Images and perform logical
NOT operations
• a= imread('cameraman.tif’);
• a1=im2bw(a);
• subplot(1,2,1);
• imshow(a1);
• title(‘Binary Image a’);
• C=not(a1);
• subplot(1,2,2);
• imshow(C);
• title(‘NOT Image‘);
Practical No. 13
AIM: To Select a Digital Image and perform Basic
Intensity Transformation “Image Negative”
I1=imread(‘tree.jpg’);
Subplot(1,2,1);
Imshow(i1);
I2=i1;
For r =1:256
For c =1:256
I2(r,c)=255-i2(r,c);
End
End
Subplot(1,2,2);
Imshow(i2);
Practical No. 14
AIM: To Select a Digital Image and perform Basic
Intensity Transformation “Logarithmic Transformation”
img = imread('Sampleimage.jpg');
r = double(img);
C = 1;
S = C * log(1 + r);
T = 255/(C * log(256));
B = uint8(T * S);
imshow(B);
title('Log Transformation');
Practical No. 15
AIM: To Select a Digital Image and perform Basic
Intensity Transformation “Power Law Transformation”
img = imread('Sampleimage.jpg’);
subplot(1,2,1);
imshow(img);
r = double(img);
G = 0.6;
S = C * (r .^G);
T = 255/(C * (255 .^G));
O = uint8(T * S);
subplot(1,2,2);
imshow(O);
title('Power Law Transformation');
Practical No. 16
Aim: To Select a Digital Image and Plot a Histogram
• I = imread("pout.tif");
• subplot(1,3,1);
• imshow(I);
• subplot(1,3,2:3);
• imhist(I)
Practical No. 17
Aim: To Select a Digital Image, perform Histogram
Equalization and plot the histogram.
• I = imread(“abc.tif");
• subplot(1,3,1)
• imshow(I)
• subplot(1,3,2:3)
• imhist(I)
• J = histeq(I);
• subplot(1,3,1)
• imshow(J)
• subplot(1,3,2:3)
• imhist(J)
Practical No. 18
Aim: To import a Digital Image and apply an image averaging
filter.
• I = imread('cameraman.tif’);
• subplot (1, 2, 1);
• imshow(I);
• title('Original Image');
• C=fspecial('average’,[3,3]);
• d=imfilter(I,C);
• subplot (1, 2, 2);
• imshow(d);
• title(‘3x3 average filter’);
Practical No. 19
Aim: To import a Digital Image and apply a median
filter.
• I = imread('cameraman.tif’);
• subplot (1, 3, 1);
• imshow(I);
• title('Original Image');
• J = imnoise(I,'salt & pepper',0.02);
• subplot (1, 3, 2);
• imshow(J);
• title(‘Noise Image');
• K = medfilt2(J);
• subplot (1, 3, 3);
• imshow(K);
• title('filtered image');
Practical No. 20
Aim: To import a Digital Image and apply a min and
• Original=imread('cameraman.tif’);
• BW = im2bw(Original,0.6);
max filter.
• minf=@(x) min(x(:));
• maxf=@(x)max(x(:));
• min_Image=nlfilter(BW,[3 3],minf);
• max_Image=nlfilter(BW,[3 3],maxf);
• subplot(2,2,1);
• imshow(BW);
• title('Original');
• subplot(2,2,2);
• imshow(min_Image);
• title('Min');
• subplot(2,2,3);
• imshow(max_Image);
• title('Max');
Practical No. 21
Aim: To import a Digital Image and apply a
Laplacian filter.
• A = imread('peppers.png');
• sigma = 0.4;
• alpha = 0.5;
• B = locallapfilt(A, sigma, alpha);
• imshowpair(A, B, 'montage')
Practical No. 22
Aim: To import a Digital Image and apply a FFT.
• I=imread('cameraman.tif');
• F=fft2(double(I));
• S=fftshift(F);
• L=log2(S);
• A=abs(L);
• imagesc(A)
Practical No. 23
Aim: To import a Digital Image and apply a frequency
domain filter.
• I = imread("cameraman.tif");
• I = im2double(I);
• F = fspecial("average",3);
• Ipad = padarray(I,[3-1 3-1],0,"post");
• Fpad = padarray(F,[256-1 256-1],0,"post");
• Ifft = fft2(Ipad);
• Ffft = fft2(Fpad);
• Offt = Ifft.*Ffft;
• Opad = ifft2(Offt);
• O = Opad(2:end-1,2:end-1);
Practical No. 24
Aim: To import a Digital Image and Perform various Morphological operation erosion
• I=imread(‘cameraman.tif');
• I=im2bw(I);
• se=ones(5, 5);
• [P, Q]=size(se);
• In=zeros(size(I, 1), size(I, 2));
• for i=ceil(P/2):size(I, 1)-floor(P/2)
• for j=ceil(Q/2):size(I, 2)-floor(Q/2)
• on=I(i-floor(P/2):i+floor(P/2), j-floor(Q/2):j+floor(Q/2));
• nh=on(logical(se));
• In(i, j)=min(nh(:));
• end
• end
• imshow(In);
Practical No. 25
Aim: To import a Digital Image and Perform various Morphological operation dilation
• I=imread(‘cameraman.tif');
• I=im2bw(I);
• se=ones(5, 5);
• [P, Q]=size(se);
• In=zeros(size(I, 1), size(I, 2));
• for i=ceil(P/2):size(I, 1)-floor(P/2)
• for j=ceil(Q/2):size(I, 2)-floor(Q/2)
• on=I(i-floor(P/2):i+floor(P/2), j-floor(Q/2):j+floor(Q/2));
• nh=on(logical(se));
• In(i, j)=max(nh(:));
• end
• end
• imshow(In);

You might also like