0% found this document useful (0 votes)
12 views18 pages

Image Processing Lab File

The document is a lab manual for an Image Processing course at K. K. College of Engineering & Management, detailing various experiments related to image processing techniques such as image arithmetic, histograms, segmentation, and Fourier transforms. Each experiment includes objectives, resources, program logic, and procedures for implementation using MATLAB and Python. The manual emphasizes the importance of digital image processing in applications like face recognition and image enhancement.

Uploaded by

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

Image Processing Lab File

The document is a lab manual for an Image Processing course at K. K. College of Engineering & Management, detailing various experiments related to image processing techniques such as image arithmetic, histograms, segmentation, and Fourier transforms. Each experiment includes objectives, resources, program logic, and procedures for implementation using MATLAB and Python. The manual emphasizes the importance of digital image processing in applications like face recognition and image enhancement.

Uploaded by

Chandramani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB MANUAL

Image Processing
(Subject Code) - CSC603P

K. K. COLLEGE OF ENGINEERING & MANAGEMENT


DHANBAD

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


INDE
X
SN Description of Experiment Experiment Date Submission Date Remarks/Signature

1. Image Arithmetic

2. Image Histogram

3. Image Segmentation

4. Fourier Transform off Image

5. Colour Image Processing

6. Morphological Operation

7. Point operation

8. Neighbourhood Operation

9. Affine Transformation
Image Processing
Image processing is the process of transforming an image into a digital form and performing certain
operations to get some useful information from it. The image processing system usually treats all images as
2D signals when applying certain predetermined signal processing methods.

Image processing is a method to perform some operations on an image, in order to get an enhanced image or
to extract some useful information from it. It is a type of signal processing in which input is an image and
output may be image or characteristics/features associated with that image.

Digital image processing is the use of a digital computer to process digital images through an algorithm. As a
subcategory or field of digital signal processing, digital image processing has many advantages over analog
image processing.

Digital Image processing is the class of methods that deal with manipulating digital images through the use of
computer algorithms. It is an essential preprocessing step in many applications, such as face recognition,
object detection, and image compression.

HARDWARE USE IN IMAGE PROCESSING LAB

Scilab open source software

SOFTWARE USE IN IMAGE PROCESSING LAB

(a) Computer nodes with proper configuration.


(b) Intel based desktop PC 0f 2.0 Ghz processor with at least 4 GB RAM and 100 GB free disk space.
EXPREMENT NO. 01
Image Arithmetic

OBJECTIVE:
❖​ Arithmetic Operations like Addition, Subtraction, and Bitwise Operations(AND, OR, NOT, XOR) can be
applied to the input images. These operations can be helpful in enhancing the properties of the input
images.

❖​ Image arithmetic is the implementation of standard arithmetic operations, such as addition, subtraction,
multiplication, and division, on images. Image arithmetic has many uses in image processing both as a
preliminary step in more complex operations and by itself.

❖​ Arithmetic functions include operators for simple operations like addition and multiplication, as well as
functions for common calculations like summation, moving sums, modulo operations, and rounding. For
more information, see Array vs. Matrix Operations.

RESOURCE: MATLAB using Python


PROGRAM LOGIC:
Image arithmetic is the application of one or more images to one of the standard arithmetic operations or a
logical operator. The operators are applied pixel by pixel, so the value of a pixel in the output image is
determined solely by the values of the corresponding pixels in the input images.

PROCEDURE:
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine
API for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to
compile a Python package that does not require users to have a MATLAB install.

PROGRAM:
import numpy as np

image1 =

[Link]('[Link]')

image2 =

[Link]('[Link]')

sub = [Link](image1,

image2)

[Link]('Subtracted

Image', sub) if
[Link](0) & 0xff ==

27: [Link]()
EXPREMENT NO.02
Image Histogram
OBJECTIVE:
❖​ An image histogram is a gray-scale value distribution showing the frequency of occurrence of each
gray-level value. For an image size of 1024 × 1024 × 8 bits, the abscissa ranges from 0 to 255; the total
number of pixels is equal to 1024 × 1024. Modification of original histograms very often is used in image
enhancement procedures.

❖​ An image histogram is a gray-scale value distribution showing the frequency of occurrence of each
gray-level value. For an image size of 1024 × 1024 × 8 bits, the abscissa ranges from 0 to 255; the total
number of pixels is equal to 1024 × 1024.

❖​ An image histogram is a type of histogram that acts as a graphical representation of the tonal distribution
in a digital image. It plots the number of pixels for each tonal value.

❖​ An image histogram is a graphical representation of the number of pixels in an image as a function of


their intensity.

RESOURCE: MATLAB using Python


PROGRAM LOGIC:
Image analysis using Matplotlib and OpenCV is discussed. Let’s first understand how to experiment image
data with various styles and how to represent with Histogram.

PROCEDURE:
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine
API for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to
compile a Python package that does not require users to have a MATLAB install.

PROCEDURE:
import cv2

from matplotlib import

pyplot as plt img =

[Link]('[Link]',0)

histr =

[Link]([img],[0],None,[256],[

0,256]) [Link](histr)

[Link]()
EXPREMENT NO.03
Image Segmentation
OBJECTIVE:
❖​ Image segmentation is the process of partitioning a digital image into multiple image segments, also
known as image regions or image objects (sets of pixels). The goal of segmentation is to simplify and/or
change the representation of an image into something that is more meaningful and easier to analyze .

❖​ Image segmentation is a commonly used technique in digital image processing and analysis to partition
an image into multiple parts or regions, often based on the characteristics of the pixels in the image.

❖​ In digital image processing and computer vision, image segmentation is the process of partitioning a
digital image into multiple image segments, also known as image regions or image objects.

❖​ Image segmentation is a commonly used technique in digital image processing and analysis to partition
an image into multiple parts or regions, often based on the characteristics of the pixels in the image.

❖​ Image segmentation could involve separating foreground from background, or clustering regions of
pixels based on similarities in color or shape. For example, a common application of image segmentation
in medical imaging is to detect and label pixels in an image or voxels of a 3D volume that represent
a tumor in a patient’s brain or other organs.

RESOURCE: MATLAB using Python


PROGRAM LOGIC:
Image Segmentation: In computer vision, image segmentation is the process of partitioning an image into
multiple segments. The goal of segmenting an image is to change the representation of an image into
something that is more meaningful and easier to analyze. It is usually used for locating objects and creating
boundaries.

PROCEDURE:
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine API
for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to compile a
Python package that does not require users to have a MATLAB install.

PROGRAM:
from skimage import data

from [Link] import

rgb2gray import

[Link] as plt

[Link](figsize=(15,

15))

coffee = [Link]()
[Link](1, 2, 1)

[Link](coffee)

gray_coffee =

rgb2gray(coffee)

[Link](1, 2, 2)

[Link](gray_coffee, cmap="gray")
EXPREMENT NO. 05
Fourier Transform of Image

OBJECTIVE:
❖​ The Fourier Transform is an important image processing tool which is used to decompose an image into
its sine and cosine components.

❖​ The output of the transformation represents the image in the Fourier or frequency domain, while the input
image is the spatial domain equivalent.

❖​ The Fourier transform is a representation of an image as a sum of complex exponentials of varying


magnitudes, frequencies, and phases. The Fourier transform plays a critical role in a broad range of image
processing applications, including enhancement, analysis, restoration, and compression.

❖​ Fourier Transform is a mathematical model which helps to transform the signals between two different
domains, such as transforming signal from frequency domain to time domain or vice versa. Fourier
transform has many applications in Engineering and Physics, such as signal processing, RADAR, and so
on.

RESOURCE: MATLAB using Python


PROGRAM LOGIC:
The Fourier Transform is a mathematical tool used to decompose a signal into its frequency components. In the
case of image processing, the Fourier Transform can be used to analyze the frequency content of an image,
which can be useful for tasks such as image filtering and feature extraction.

PROCEDURE:
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine API
for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to compile a
Python package that does not require users to have a MATLAB install.

PROGRAM:
import numpy as np
import [Link]
as plotter
samplingFrequency = 100;
samplingInterval​ = 1 /
samplingFrequency; beginTime​ = 0;
endTime​ = 10;
signal1Frequency​ = 4;
signal2Frequency​
= 7; # time
points
time = [Link](beginTime, endTime,
samplingInterval); # Create two sine waves
amplitude1 =
[Link](2*[Link]*signal1Frequency*time)
amplitude2 =
[Link](2*[Link]*signal2Frequency*time)
figure, axis = [Link](4, 1)
plotter.subplots_adjust(hspace=1)
# Time domain representation for sine
wave 1 axis[0].set_title('Sine wave
with a frequency of 4 Hz')
axis[0].plot(time, amplitude1)
axis[0].set_xlabel('Time')
axis[0].set_ylabel('Amplitude')
# Time domain representation for sine
wave 2 axis[1].set_title('Sine wave
with a frequency of 7 Hz')
axis[1].plot(time, amplitude2)
axis[1].set_xlabel('Time')
axis[1].set_ylabel('Amplitude')
amplitude = amplitude1 + amplitude2
# Time domain representation of the
resultant sine wave
axis[2].set_title('Sine wave with multiple
frequencies') axis[2].plot(time,
amplitude)
axis[2].set_xlabel('Ti
me')
axis[2].set_ylabel('Am
plitude')
# Frequency domain representation
fourierTransform =
[Link](amplitude)/len(amplitude)
fourierTransform =
fourierTransform[range(int(len(amplitude)/2))]
tpCount​ = len(amplitude)
values​ =
[Link](int(tpCount/2))
timePeriod =
tpCount/samplingFrequency
frequencies = values/timePeriod
axis[3].set_title('Fourier transform depicting the
frequency components') axis[3].plot(frequencies,
abs(fourierTransform)) axis[3].set_xlabel('Frequency')
axis[3].set_ylabel('Amplitude')
[Link]()​ page no - 4
EXPREMENT NO. 06
Colour Image Processing
OBJECTIVE:
❖​ In color image processing, an abstract mathematical model known as color space is used to characterize the
colors in terms of intensity values. This color space uses a three-dimensional coordinate system.

❖​ In color image processing, an abstract mathematical model known as color space is used to characterize the
colors in terms of intensity values. This color space uses a three-dimensional coordinate system. For
different types of applications, a number of different color spaces exists.

❖​ The human visual system can distinguish hundreds of thousands of different color shades and intensities,
but only around 100 shades of grey. Therefore, in an image, a great deal of extra information may be
contained in the color, and this extra information can then be used to simplify image analysis, e.g. object
identification and extraction based on color.

RESOURCE: MATLAB using Python


PROGRAM LOGIC:
In color image processing, an abstract mathematical model known as color space is used to characterize the
colors in terms of intensity values. This color space uses a three-dimensional coordinate system. For different
types of applications, a number of different color spaces exists.

PROCEDURE:
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine API
for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to compile a
Python package that does not require users to have a MATLAB install.

PROGRAM:
I = imread('[Link]');
% rows and columns in
the image r = size(I, 1);
c = size(I, 2);
% creating zero
matrices R = zeros(r,
c, 3);
G = zeros(r, c, 3);
B = zeros(r, c, 3);
% storing the corresponding color plane
% red plane
R(:, :, 1) = I(:, :, 1);
% green plane
G(:, :, 2) =
I(:, :, 2);
% blue plane
B(:, :, 3) = I(:, :, 3);
% displaying the
images figure,
imshow(uint8(R));
figure,
imshow(uint8(G));
figure,
imshow(uint8(B));
EXPREMENT NO.07
Morphological Operation
OBJECTIVE:
❖​ Morphological Operations is a broad set of image processing operations that process digital images
based on their shapes. In a morphological operation, each image pixel is corresponding to the value of
other pixel in its neighbourhood.

❖​ Mathematical morphology is a theory and technique for the analysis and processing of geometrical
structures, based on set theory, lattice theory, topology, and random functions.

❖​ Morphological operations apply a structuring element to an input image, creating an output image of the
same size. In a morphological operation, the value of each pixel in the output image is based on a
comparison of the corresponding pixel in the input image with its neighbors.

❖​ Morphology is a broad set of image processing operations that process images based on shapes.
Morphological operations apply a structuring element to an input image, creating an output image of the
same size. In a morphological operation, the value of each pixel in the output image is based on a
comparison of the corresponding pixel in the input image with its neighbors.

RESOURCE: MATLAB using Python


PROGRAM LOGIC:
Morphological operations apply a structuring element to an input image, creating an output image of the same
size. In a morphological operation, the value of each pixel in the output image is based on a comparison of the
corresponding pixel in the input image with its neighbors.

PROCEDURE:
There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine API
for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to compile a
Python package that does not require users to have a MATLAB install.

PROGRAM:
I =
imread("[Link]
g"); subplot(2, 3,
1), imshow(I);
title("Original image");

% Dilated Image
se = strel("line", 7, 7);
dilate =
imdilate(I, se);
subplot(2, 3,
2),
imshow(dilate);
title("Dilated
image");
% Eroded image
erode =
imerode(I, se);
subplot(2, 3, 3),
imshow(erode);
title("Eroded
image");

% Opened image
open = imopen(I,
se); subplot(2,
3, 4),
imshow(open);
title("Opened
image");

% Closed image
close =
imclose(I, se);
subplot(2, 3,
5),
imshow(close);
title("Closed
image");
EXPREMENT NO. 08
POINT
OBJECTIVE:
❖​ Point operations are often used to change the grayscale range and distribution. The concept of point operation is
to map every pixel onto a new image with a predefined transformation function.
❖​ Point Operation is the modification of the pixel value without changing in the
size, geometry and local structure of the image. The new pixel value
depends only on the previous value. They are mapped by a function f(a).
❖​

Software Requirements -: MATLAB using Python


Program -:
from skimage import io import
[Link] as plt def
f(x):
return x * 1.5
def point_operation(image, method):
for row in range(0, [Link][0]):
for col in range(0, [Link][1]):
image[row][col] = method(image[row][col])
return image
if name​ == ' main ':
image = [Link]('~/Desktop/Lenna_gray.png')
image_modified = point_operation([Link](), f)
[Link]()
_ = [Link](image)
[Link]()
_ = [Link](image_modified)
[Link]()
1.​Neighbourhood Operation

Description-: Neighbourhood and Block Operations (Image Processing Toolbox) A sliding neighbourhood
operation is an operation that is performed a pixel at a time, with the value of any given pixel in the output image
being determined by applying some algorithm to the values of the corresponding input pixel's neighbourhood.

Software Requirements -: MATLAB using Python


Program -:
I = imread('[Link]');
f = @(x) max(x(:));
I2 = nlfilter(I,[3 3],f);
imshow(I);
figure, imshow(I2);
EPREMENT NO.09
Affine Transformation
OBJECTIVE:
❖​ Affine tíansfoímation is a lineaí mapping method that píeseíves points, stíaight lines, and planes. Sets of paíallel
lines íemain paíallel afteí an affine tíansfoímation . ľhe affine tíansfoímation technique is typically used to coííect
foí geometíic distoítions oí defoímations that occuí with non-ideal cameía angles. Foí example, satellite imageíy
uses affine tíansfoímations to coííect foí wide angle lens distoítion, panoíama stitching, and image íegistíation.
ľíansfoíming and fusing the images to a laíge, flat cooídinate system is desiíable to eliminate distoítion.

import cv2
import numpy as np
from matplotlib import pyplot as plt
img = [Link]('[Link]')
rows, cols, ch = [Link]
pts1 = np.float32([[50, 50],
[200, 50],
[50, 200]])
pts2 = np.float32([[10, 100],
[200, 50],
[100, 250]])
M = [Link](pts1, pts2)
dst = [Link](img, M, (cols, rows))
[Link](121)
[Link](img)
[Link]('Input')
[Link](122)
[Link](dst)
[Link]('Output')
[Link]()
# Displaying the image
while(1):
[Link]('image', img)
if [Link](20) & 0xFF == 27:
break
[Link]()

page no -9

You might also like