Mahak DIP
Mahak DIP
Mahak DIP
Branch: CSE
Section: 5CSE-
AI
Year/Semester: III Year/ V
Experiment Submission
S.No. Experiment Name Signature Remark
Date Date
Introduction to MATLAB
1
Histogram Processing
5
Image Enhancement- Spatial filtering
6
7
Image Enhancement-Filtering
in frequency domain
8 Edge detection
Line detection
9
Point detection
10
EXPERIMENT NO.– 01
Introduction to MATLAB
Theory:
- MATLAB (Matrix Laboratory) is a high-performance programming language and computing
environment developed by MathWorks, Inc. in 1984. It is designed for numerical computations, including
matrix manipulations, plotting of functions and data, implementation of algorithms, and creating user
interfaces.
3. Image Enhancement
Adjust contrast with imadjust.
Perform histogram equalization using histeq.
enhanced_img = imadjust(img); % Adjust contrast
eq_img = histeq(img); % Perform histogram equalization
5. Image Transformation
Resize, rotate, or crop images using built-in functions.
resized_img = imresize(img, 0.5); % Scale down the image by half
rotated_img = imrotate(img, 45); % Rotate the image by 45 degreescropped_img = imcrop(img, [x y
width height]); % Crop image to a specific region
3
Mahak Dalal
EN22CS304040
6. Image Segmentation
Convert to binary using imbinarize.
Measure region properties with regionprops.
binary_img = imbinarize(rgb2gray(img)); % Convert to binary image
region_info = regionprops(binary_img, 'Area', 'Centroid'); % Extract region properties
7. Feature Extraction
Detect edges using edge detection algorithms like Canny.
Find corners in the image using detectHarrisFeatures.
edges = edge(rgb2gray(img), 'Canny'); % Detect edges
corners = detectHarrisFeatures(rgb2gray(img)); % Detect corners
9. Morphological Operations
Perform morphological operations like dilation and erosion using imdilate and imerode.
se = strel('disk', 5); % Create a disk-shaped structuring element
dilated_img = imdilate(binary_img, se); % Apply dilation
4
Mahak Dalal
EN22CS304040
13. Integration with Other Tools
Integrate MATLAB with Simulink for real-time processing or with other programming languages like C,
C++, and Python for custom workflows.
% Example: Call external C function in MATLAB
mex myFunction.c % Compile C code to be used in MATLAB
output = myFunction(input); % Call the compiled C function
5
Mahak Dalal
EN22CS304040
EXPERIMENT NO.– 02
Image Sampling and Quantization
Theory:
Image sampling and quantization are fundamental concepts in digital image processing, used to convert
analog images into a digital form that can be processed, stored, and displayed by digital systems. Here's an
overview of these concepts:
Image Sampling:
Sampling refers to the process of converting a continuous image into a discrete image. It involves selecting a
finite number of sample points from the continuous image. In simpler terms, it’s about how often you capture
data points from an image.
1. Grid Formation: The continuous image is divided into a grid of pixels. Each pixel represents a specific area
of the image.
2. Resolution: The resolution of an image is determined by the grid's density. Higher resolution means a higher
number of pixels per unit area, which translates to more detail.
3. Sampling Rate: The sampling rate, or spatial resolution, is the number of samples (pixels) taken per unit
distance in the image. A higher sampling rate captures more detail but requires more data.
Image Quantization:
Quantization refers to the process of mapping the sampled values to a finite range of discrete values. This
step is crucial because it reduces the infinite range of possible colors (or intensities) to a manageable number
of levels that a digital system can handle.
1. Color Depth: The number of bits used to represent each pixel's color or intensity. For instance, an 8-bit depth
allows for 256 possible values (levels), while a 24-bit depth (often used for color images) allows for over 16
million colors.
2. Gray Levels: For grayscale images, quantization determines the number of different shades of gray that can
be represented. A common example is 256 gray levels (8-bit grayscale).
3. Color Quantization: For color images, quantization involves mapping color values to a limited palette of
colors, which simplifies storage and processing but can affect image quality.
CODE:
% Load a grayscale image
img = imread('cameraman.tif'); % You can replace this with your own image file
6
Mahak Dalal
EN22CS304040
% Quantize the image
quantizedImg = round(imgDouble * (numLevels - 1)) / (numLevels - 1);
OUTPUT:
7
Mahak Dalal
EN22CS304040
EXPERIMENT NO.– 03
Intensity Transformation of Images
Theory:
Intensity transformation is a fundamental concept in image processing that involves modifying the brightness and
contrast of an image. It focuses on changing the pixel intensity values to enhance certain features or to prepare the
image for further analysis. Here’s a breakdown of the theory behind intensity transformations:
Basic Concepts
1. Pixel Intensity: Each pixel in an image has an intensity value, typically ranging from 0 (black) to
255 (white) in an 8-bit grayscale image. The intensity determines the brightness of the pixel.
1. Linear Transformations:
- Contrast Stretching: Increases the range of intensity values to improve contrast. The
transformation can be expressed as:
\[ g = \frac{(f - f_{min})}{(f_{max} - f_{min})} \cdot (L - 1) \]
where \( L \) is the number of intensity levels.
2. Non-linear Transformations:
- Logarithmic Transformation: Useful for enhancing dark regions in an image. The transformation function is:
\[ g = c \cdot \log(1 + f)\]
where \( c \) is a constant that adjusts the brightness.
- Power Law (Gamma Correction): Adjusts the brightness and contrast using a power function:
\[g = c \cdot f^\gamma \]
where \( \gamma \) is the gamma value that determines the nature of the transformation (e.g., \( \gamma < 1 \)
for lightening, \( \gamma > 1 \) for darkening).
4. Histogram Equalization
A specific intensity transformation technique aimed at improving contrast is histogram equalization,
which redistributes the intensity values across the histogram for better visual representation. This is achieved by:
8
Mahak Dalal
EN22CS304040
CODE:
% Read the image
img = imread('your_image.jpg'); % Replace with your image path
img_gray = rgb2gray(img); % Convert to grayscale if it's a color image
imshow(img_gray);
% Linear Transformation
% Define the transformation parameters
a = 1; % scaling factor
b = 0; % bias
Output:
9
Mahak Dalal
EN22CS304040
EXPERIMENT NO.– 04
DFT analysis of Images
Theory:
The Discrete Fourier Transform (DFT) is a powerful mathematical tool used in image processing to
analyze the frequency components of digital images. By transforming spatial data (pixel values) into the
frequency domain, DFT allows us to understand how different frequency elements contribute to the overall
image.
Concept of DFT
In the context of images, DFT decomposes an image into its sinusoidal components. Each pixel's
intensity is represented in terms of frequency, where low frequencies correspond to smooth variations
(such as gradual color changes) and high frequencies correspond to sharp edges and noise. The DFT of a 2D
image \( f(x, y) \) is defined as:
where \( M \) and \( N \) are the dimensions of the image, and \( F(u, v) \) represents the frequency
domain representation.
Applications
1. Image Filtering: DFT enables the design of filters to enhance or suppress certain frequencies. Low-pass
filters can smooth images by removing high-frequency noise, while high-pass filters can highlight
edges.
2. Compression: Techniques like JPEG compression utilize DFT (specifically, a related transform
called the Discrete Cosine Transform) to reduce the amount of data required to represent an image
while maintaining visual quality.
3. Feature Extraction: DFT can help in identifying and extracting features from images, which
is crucial in tasks like pattern recognition and computer vision.
Code:
% Read the image
img = imread('your_image.jpg'); % Replace with your image file
gray_img = rgb2gray(img); % Convert to grayscale if it's a color image
1
Mahak Dalal 0
EN22CS304040
% Display the magnitude spectrum
1
Mahak Dalal 1
EN22CS304040
subplot(1, 2, 2);
imshow(magnitude_spectrum, []);
title('Magnitude Spectrum');
colormap jet; % Optional: Change colormap for better visualization
Output:
1
Mahak Dalal 2
EN22CS304040