0% found this document useful (0 votes)
5 views13 pages

DIPLAB

The document outlines various experiments conducted in a Digital Image Processing Laboratory, focusing on histogram processing, spatial filtering, frequency domain filtering, edge detection, and line detection using MATLAB. Each experiment includes the aim, theoretical background, and MATLAB code for implementation. The results demonstrate the effectiveness of different image processing techniques in enhancing and analyzing digital images.

Uploaded by

Abinaya C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views13 pages

DIPLAB

The document outlines various experiments conducted in a Digital Image Processing Laboratory, focusing on histogram processing, spatial filtering, frequency domain filtering, edge detection, and line detection using MATLAB. Each experiment includes the aim, theoretical background, and MATLAB code for implementation. The results demonstrate the effectiveness of different image processing techniques in enhancing and analyzing digital images.

Uploaded by

Abinaya C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

EX.NO: 4 HISTOGRAM PROCESSING AND BASIC THRESHOLDING FUNCTIONS

AIM
To study histogram and histogram equalization.

SOFTWARE USED
MATLAB

THEORY

The histogram of a digital image with gray values r0, r1….rL-1 is the discrete function P(rk)=nk/n nk :
Number of pixels with gray value rk . n: Total number of pixels in the image The function P(rk)
represents the fraction of the total number of pixels with gray value rk. Histogram provides a global
description of the appearance of the image. The shape of the histogram provides useful information for
contrast enhancement. The histogram equalization is an approach to enhance a given image. The approach
is to design a transformation T(.) such that the gray values in the output are uniformly distributed in
[0,1].In terms of histograms, the output image will have all gray values in equal proportion.

PROGRAM
% histogram without inbuilt function.
histo=zeros(1,256);
I=imread('cameraman.png');
imshow(I);
si=size(I);
for i=1:si(1)
for j=1:si(2)
for g=1:256
if I(i,j)==g
histo(g)=histo(g)+1;
end
end
end
end
figure,stem(histo)
%histogram with inbuilt function
x=imread('cameraman.png');
imhist(x);
%histogram equalization
I=imread('cameraman.png');
a=histeq(I);
imshow(a);
figure,imhist(a)

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

Result:

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

EX.NO: 7 IMPLEMENTATION OF IMAGE ENHANCEMENT – SPATIAL FILTERING

AIM:
To perform image enhancement by spatial filtering.

SOFTWARE
MATLAB

THEORY:

In Spatial filtering, the filtering operations are performed directly on the pixels of an
image. There are two types of spatial filters, linear and non linear filters. The mechanics of spatial
filtering is that it is the process which consists of simply moving the filter mask from point to
point in an image. At each point (x,y) the response of the filter at that point is calculated using a
predefined relationship. For linear spatial filtering, the response is given by a sum of products of
the filter coefficients and the corresponding image pixels in the area spanned by the filter mask.
Smoothing filters are used for blurring and for noise reduction. The output of a smoothing linear
spatial filter is simply the average of the pixels contained in the neighbourhood of the filter mask.
These filters are called averaging or lowpass filters.
Order statistics filters are non-linear spatial filters whose response is based on ordering
the pixels contained in the image area encompassed by the filter and then replacing the value of
the center pixel with the value determined by the ranking result. Median filter replaces the value
of a pixel with the median of the graylevels in the neighbourhood of the pixel.
PROGRAM:

i=imread('cameraman.png');
imshow(i);
w=fspecial('average',[3 3]);
g=imfilter(i,w,'symmetric');
figure,imshow(g,[]);

i=imread('cameraman.png');
w=fspecial('gaussian',[3 3],0.5);
g=imfilter(i,w,'symmetric');
imshow(g,[]);

i=imread('cameraman.png');
w=fspecial('laplacian', 0.5);
g=imfilter(i,w,'symmetric');
imshow(g,[])

i=imread('cameraman.png');
w=fspecial('sobel');
g=imfilter(i,w,'symmetric');
imshow(g,[])

i=imread('cameraman.png');

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

h=ordfilt2(i,1,ones(3,3));
h1=ordfilt2(i,3*3,ones(3,3));
h2=ordfilt2(i,median(1:3*3),ones(3,3));
subplot(2,2,1)
imshow(i);
subplot(2,2,2)
imshow(h,[]);
subplot(2,2,3)
imshow(h1,[]);
subplot(2,2,4)
imshow(h2,[]);

g=imread('cameraman.png');
m=medfilt2(g,[3 3]);
imshow(m,[]);
Output:

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

Result:
Thus spatial filtering is performed on image using Matlab.

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

Ex. No.8 FREQUENCY DOMAIN FILTERS FROM SPATIAL DOMAIN


AIM
To obtain frequency domain filters from spatial domain.

SOFTWARE USED
MATLAB

THEORY
Filtering in the frequency domain consists of modifying the Fourier transform of an image and then
computing the inverse transform to obtain the processed result.
Thus a given image of digital f(x,y) of size M x N the basic filtering equation in which interested is
in the form
g(x,y)=F-1[H(u,v) F(u,v)]
F-1 – IDFT, F(u,v) is the DFT of input image f(x,y)
H(u,v) – Filter function
g(x,y) – Filtered (output) image

PROGRAM

f=imread("cameraman.png");
h=fspecial('average',[5 5]);
Fs=size(f);
F=fft2(f);
H=freqz2(h,Fs(1),Fs(2));
G=F.*H;
g=ifft2(G);
imshow(real(g),[]);
figure,imshow(abs(H));

f=imread("cameraman.png");
h=fspecial('gaussian',[3 3],2);
Fs=size(f);
F=fft2(f);
H=freqz2(h,Fs(1),Fs(2));
G=F.*H;
g=ifft2(G);
imshow(real(g),[]);
figure,imshow(abs(H));

f=imread("cameraman.png");
h=fspecial('sobel');
Fs=size(f);
F=fft2(f);
H=freqz2(h,Fs(1),Fs(2));
G=F.*H;
g=ifft2(G);
imshow(real(g),[]);

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

Result:
Thus frequency domain filters are obtained from spatial domain.

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

Ex. No.9a Image Segmentation - EDGE DETECTION


AIM:
To detect edges in the image.

SOFTWARE USED
MATLAB

THEORY
The Sobel and prewitt operators are used in image processing and computer vision, particularly
within edge detection algorithms where they create an image emphasizing edges. They are a discrete
differentiation operator, computing an approximation of the gradient of the image intensity function.
At each point in the image, the result of the Sobel and prewitt operators is either the corresponding
gradient vector or the norm of this vector. The Sobel and prewitt operators are based on convolving
the image with a small, separable, and integer-valued filter in the horizontal and vertical directions.
The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a
wide range of edges in images. Canny edge detection is a technique to extract useful structural
information from different vision objects and dramatically reduce the amount of data to be processed.
Canny uses the calculus of variations – a technique which finds the function which optimizes a given
functional. The optimal function in Canny's detector is described by the sum of four exponential
terms, but it can be approximated by the first derivative of a Gaussian.
The Roberts cross operator is used in image processing and computer vision for edge detection. It is a
differential operator. The gradient of an image is approximated through discrete differentiation which
is achieved by computing the sum of the squares of the differences between diagonally adjacent
pixels.
PROGRAM

a=imread('images.jpg');
imshow(a);
f=rgb2gray(a);
figure,imshow(f);
[g,~]=edge(f,'sobel','vertical');
figure,subplot(3,1,1);
imshow(g);
[g,~]=edge(f,'sobel','horizontal');
ubplot(3,1,2);
imshow(g);
[g,~]=edge(f,'sobel','both');
subplot(3,1,3);
imshow(g);
[g,~]=edge(f,'prewitt','vertical');
figure,subplot(3,1,1);
imshow(g);
[g,~]=edge(f,'prewitt','horizontal');
subplot(3,1,2);
imshow(g);
[g,~]=edge(f,'prewitt','both');
subplot(3,1,3);
imshow(g);
[g,~]=edge(f,'roberts','vertical');
figure,subplot(3,1,1);
imshow(g);

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

[g,~]=edge(f,'roberts','horizontal');
subplot(3,1,2);
imshow(g);
[g,~]=edge(f,'roberts','both');
subplot(3,1,3);
imshow(g);
[g,~]=edge(f,'canny','vertical');

figure,subplot(3,1,1);
imshow(g);
[g,~]=edge(f,'canny','horizontal');
subplot(3,1,2);
imshow(g);
[g,t]=edge(f,'canny','both');
subplot(3,1,3);
imshow(g);

Output:

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

RESULT
Thus the edges are detected using Matlab.

Ex. No.9b LINE DETECTION

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

AIM
To detect lines in the images using Mat lab.

SOFTWARE USED
MATLAB

THEORY
Horizontal mask will result with maximum response when a line is passed through the middle row of
the mask with a constant background. Let R1, R2, R3, R4 denote the response of the horizontal, +45
degree, vertical and +45 degree masks respectively.
|Ri|>|Rj|
For detecting all lines in an image in the direction defined by a given mask, we simply run the mask
through the image and threshold the absolute value of the result.

PROGRAM

St. Joseph’s College of Engineering


DS1409 – DIGITAL IMAGE PROCESSING LABORATORY DEPARTMENT OF AI & DS 2025-2026

St. Joseph’s College of Engineering

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy