Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

sharma dip

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Digital Image Processing

LAB Report

Name : Mohit Sharma


Sec : X
Roll number : 23
Batch : X1
University Roll No. : 2215001093
Subject : Digital Iamge Procrssing Lab Subject
Code: BCSE0 0131
Submitted to : Dear Bondita Paul
Practical No. 1

Aim:

Introduction to the MATLAB


commands
Software use: R 2021 (MATLAB)
Program code:
• 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
Analysis: This set of commands provides foundational tools for
working in MATLAB, from basic window management (clc, clear) to
more advanced plotting and matrix manipulations (plot, reshape). The
subplot and hold commands allow detailed visual analysis by combining
multiple plots, while linspace, zeros, and ones help with creating and
managing data sets.

Conclusion: This practical covers essential MATLAB commands for


workspace management, matrix manipulation, and data visualization.
Commands like clc and clear help maintain a clean workspace, while
zeros, ones, and reshape facilitate matrix operations. Plotting tools like
plot, subplot, and hold enable effective data visualization, providing a
strong foundation for more advanced MATLAB tasks.
Practical No. 2
Aim:Write a program to represent arrays in different
ways
Software use: R 2021 (MATLAB)
Theory:
1. Matrix representation: a is a 3x3 matrix, commonly used
for data storage and matrix operations.

2. Range creation: b and t are arrays generated by np.arange()


with evenly spaced values.

3. Step size in arrays: k is an array with a negative step


size, showing flexibility in array generation.
4. 2D arrays: x is a 2x4 matrix, storing data in rows and columns.
5. 1D array: y is a simple sequence of numbers in a 1D array.

Program code:
1. x=[1 2 3; 4 5 6; 7 8 9]

2. s=[3 :6]

3. v =1:15
4. y = [1 2 5 1]

5. o= [1:4; 5:8]

Analysis:
The code shows how to create and manipulate arrays in MATLAB
using different formats, ranges, and increments. It demonstrates
efficient data handling with colon notation for arrays and vectors.

Conclusion:
This practical demonstrates MATLAB's versatility in creating arrays
with different notations. The colon syntax simplifies sequence
generation, making matrix and vector creation more efficient for data
manipulation.
Practical No. 3
Aim: Write a program to perform various matrices
arithmetic operation
Software use: R 2021 (MATLAB)
Theory:

1. Matrix Addition: Adds corresponding elements of two


matrices element-wise.

2. Matrix Subtraction: Subtracts corresponding elements of


the matrices.

3. Element-wise Multiplication: Multiplies each element in


one matrix with the corresponding element in another.

Program code:
• a=[1 2 3; 4 5 6; 7 8 9]
• b=[10 11 12; 13 14 15; 16 17 18]
• sum= a+b;

• sub=a-b;

mult= a*b;
Analysis:
This practical demonstrates basic matrix operations: addition,
subtraction, and element-wise multiplication. These operations
are crucial for mathematical modeling and data processing.

Conclusion:
The practical covers fundamental matrix operations in MATLAB,
essential for linear algebra and system simulations.
Practical No. 4
Aim:
Write a program to prints out Pascal’s triangle
Software use: R 2021 (MATLAB)
Theory:
Pascal's Triangle is a triangular array of binomial coefficients. Each
number in the triangle is the sum of the two numbers directly above
it in the previous row. The triangle starts with a single '1' at the top,
and subsequent rows contain numbers that are constructed based
on the previous row.

Program code:
• b=1
• while length(a) < 15
• b = [0 b] + [b 0]
• end
Analysis:
Pascal's Triangle is constructed by summing adjacent numbers from
the previous row. Each row starts and ends with 1, and the internal
elements are derived from the sum of two elements above.

Conclusion:
The program generates Pascal's Triangle up to 10 rows using an
iterative approach, demonstrating efficient list operations in Python
.
Practical No. 5
Aim: Write a program Plot the function sin(x) between
0≤x≤4π using linspace
Software use: R 2021 (MATLAB)
Theory:
1. linspace: np.linspace(0, 4 * np.pi, 100) generates 100 evenly
spaced values between 0 and 4π for the x-axis.

2. Sine Function: np.sin(x) computes sine values for each


x, forming the y-axis data.
3. Plotting: plt.plot(x, y) creates the sine wave plot.

4. Labels and Title: plt.title(), plt.xlabel(), and plt.ylabel()


add labels for clarity.

5. Visualization: plt.show() displays the plot, visualizing the


sine wave over two cycles.

Program code:
• a=linspace(0,4*pi,100);
• b=sin(x);
• plot(y);
Analysis:
The sine function completes two cycles over 0 to 4π, with peaks
at y=1 and troughs at y=-1, showing its periodic behavior.

Conclusion:
The sine function's periodicity is demonstrated, completing two
cycles between 0 and 4π, highlighting the nature of
trigonometric functions.
Practical No. 6
Aim: Write a program Plot the function sin(x) between
0≤x≤4π using stem function
Software use: R 2021 (MATLAB)
Theory:
In this practical, we will plot the sine function using a stem plot. A
stem plot is a graphical representation that displays data as vertical
lines (or "stems") with markers at the top of each line. It is useful
for visualizing discrete data points

Program code:
• x=linspace(0,4*pi,100);
• y=sin(x);
• stem(y);
• stem(x,y);
Analysis: The stem plot of sin(x)\sin(x)sin(x) from 0 to 4π4\pi4π
shows periodic oscillations between -1 and 1, with peaks, troughs,
and zeros at regular intervals.

Conclusion: The stem plot clearly visualizes the sine wave's


periodicity, offering a discrete representation of its behavior over
the interval 0≤x≤4π0 \leq x \leq 4\pi0≤x≤4π.
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
Software use: R 2021 (MATLAB)
Theory:
This practical demonstrates basic image processing: converting an
image to grayscale, binary format, and adjusting intensity levels.
• Original Image: Loaded with imread and displayed.
• Grayscale Image: Converted with rgb2gray,
retaining intensity.
• Binary Image: Converted using im2bw, turning pixels black
(0) or white (1).

• Intensity Adjustment: Enhanced with imadjust,


improving contrast and brightness.
Program code:
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’);
Analysis:
1. Grayscale Conversion: Simplifies the image to a single
intensity channel, aiding analysis.

2. Binary Conversion: Useful for thresholding operations like


edge detection or segmentation.

3. Intensity Adjustment: Enhances image contrast, improving


visual clarity.

Conclusion: The program demonstrates essential image processing


operations, preparing images for further analysis or tasks like
segmentation and feature extraction.
Practical No. 8
Aim:Write a program to import Digital Images and
reduce the size of the image (50%)
Software use: R 2021 (MATLAB)
Theory:
This practical demonstrates importing and resizing a digital image
by 50%. Image resizing is useful for reducing computational load or
adjusting dimensions.

• Original Image: Loaded and displayed using imread


and imshow.
• Resized Image: Resized to 50% using imresize.
• Displaying Images: Both images are shown side by side
for comparison.

• Size Calculation: Sizes of original and resized images


are computed with size to confirm the reduction.
Program code:
• 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);

Analysis:
The image is successfully resized to 50% of its original
dimensions, reducing both file size and resolution.

Conclusion: The program efficiently resizes an image,


demonstrating a basic yet essential image processing technique. The
comparison of image sizes confirms the reduction in dimensions.
Practical No. 9
AIM: Write a program to import Digital Images and
perform arithmetic operations
Software use: R2021 (MATLAB)
Theory:
This practical demonstrates how to perform basic arithmetic
operations on digital images. Image arithmetic operations, such
as addition, subtraction, and multiplication, are useful for tasks
like image blending, enhancement, and analysis.
• Addition: Pixel values of two images are added together.
• Subtraction: Pixel values of one image are subtracted
from another.

• Multiplication: Pixel values of two images are


multiplied element-wise.

Program code:
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’);

Analysis:
1. Addition: Blends images, potentially brightening the result.
2. Subtraction: Highlights differences and creates contrast.
3. Multiplication: Combines images, darkening the result.

Conclusion: The program demonstrates key image arithmetic


operations, essential for image fusion, enhancement, and difference
detection in image processing.
Practical No. 10
AIM: Write a program to import Digital Images and
perform logical AND operations
Software use: R 2021 (MATLAB)
Theory:
This practical demonstrates the application of a logical AND operation
on two binary images. Logical operations on images are commonly
used in masking, feature extraction, and region-of-interest analysis.
• Binary Conversion: The images are converted to binary
format using im2bw, where pixel values are either 0 (black) or
1 (white).
• AND Operation: The AND operation compares corresponding
pixels from two images. If both pixels are 1 (white), the result
is 1; otherwise, it’s 0 (black).

Program code:
• 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);

Analysis:
1. Binary Conversion: Both input images are converted
into binary, simplifying the image to two intensity levels.

2. AND Operation: The logical AND operation produces an


image where only the overlapping white regions of the two
binary images are retained, while other regions turn black.

Conclusion: The program demonstrates the use of a logical AND


operation on binary images. This technique is useful for finding
common features or regions between two images, and is widely used
in image processing tasks such as masking and segmentation.
Practical No. 11
AIM: To import Digital Images and perform
logical OR operations

Software use: R 2021 (MATLAB)


Theory:
This practical demonstrates the application of the logical OR
operation on two binary images. Logical operations like OR are
essential in image processing for tasks such as merging regions
or combining masks.

• Binary Conversion: Both images are converted into binary


format using im2bw, reducing them to two intensity levels
(0 for black and 1 for white).

• OR Operation: The OR operation compares corresponding


pixels from two images. If at least one of the pixels is 1
(white), the resulting pixel is 1; otherwise, it’s 0 (black).

Program code:
• 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‘);

Analysis:
1. Binary Conversion: Both input images are transformed into
binary images, making them simpler for logical operations.

2. OR Operation: The logical OR operation produces a result


where any white pixel in either of the two input images
remains white in the output. This merges the bright regions
from both images.

Conclusion:
The program successfully performs a logical OR operation on two
binary images. This operation combines the white regions from
both images, retaining areas where either image has white pixels. It
is useful in tasks like merging masks and feature extraction.
Practical No. 12
AIM: To import Digital Images and perform logical
NOT operations

Software use: R 2021 (MATLAB)


Theory:
This practical demonstrates the application of the logical NOT
operation on a binary image. The NOT operation inverts the
pixel values: turning white pixels (1) to black (0) and black pixels
(0) to white (1). This is commonly used for image negation,
highlighting background or non-foreground regions.
• Binary Conversion: The image is first converted into
binary format using im2bw, simplifying it to two levels
(black and white).
• NOT Operation: The logical NOT operation inverts the
binary image, swapping the black and white regions.

Program code:
• 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‘);

Analysis:
1. Binary Conversion: The image is transformed into
binary, making the pixels either black or white.

2. NOT Operation: The NOT operation inverts the binary


image, making white regions black and black regions white.
This is useful for highlighting the background or non-active
parts of the image.

Conclusion:
The program successfully demonstrates the logical NOT operation
on a binary image. By inverting the pixel values, this operation
highlights the negative of the image, which can be useful in tasks like
segmentation and background enhancement.
Practical No. 13
AIM: To Select a Digital Image and perform Basic
Intensity Transformation “Image Negative”

Software use: R 2021 (MATLAB)


Theory:
The Image Negative transformation inverts pixel intensities by
subtracting each pixel value from 255. This reverses the
brightness, making dark areas light and light areas dark.

Program code:
a=imread('cameraman.tif');
subplot(1,2,1); imshow(a);
a2=a; for r=1:256 for
c=1:256 a2(r,c)=255-
a2(r,c); end end
subplot(1,2,2);
imshow(a2);
Analysis:
The original image is displayed, and then its negative is generated by
inverting pixel values. The result shows an opposite intensity pattern.

Conclusion:
The program successfully creates an image negative,
highlighting details in dark areas and enhancing contrast for
better image analysis.
Practical No. 14
AIM: To Select a Digital Image and perform Basic
Intensity Transformation “Logarithmic Transformation”

Software use: R 2021 (MATLAB)


Theory:
The Logarithmic Transformation enhances the details in the darker regions
of an image by compressing the dynamic range of pixel intensities. It is useful
for visualizing details in images with high intensity variations. The
transformation is given by S=C⋅log (1+r)S = C \cdot \log(1 + r)S=C⋅log(1+r),
where rrr is the pixel intensity and CCC is a constant to scale the result.

Program code:
img=imread('peppers.png');
subplot(1,2,1); imshow(img);
r=double(img);
g=2.69; % change g to increse/decrease intensity >0 image will
be bright and <0 image will be dark c=1; s=c*(r.^g);
t=255/(c*(255.^g)); o=uint8(t*s); subplot(1,2,2); imshow(o);

title("Power Law Transformation");


Analysis:
The transformation expands darker pixels and compresses
brighter ones, revealing more detail in dark regions.

Conclusion:
The program effectively applies the Logarithmic
Transformation, enhancing details in the darker parts of the
image for better visual clarity.
Practical No. 15
AIM: To Select a Digital Image and perform Basic
Intensity Transformation “Power Law Transformation”
Software use: R 2021 (MATLAB)
Theory:
The Power Law Transformation (Gamma correction) is used to
enhance images by adjusting brightness and contrast. The
transformation is defined as S=C rγS = C \cdot r^\gammaS=C rγ,
where rrr is the pixel intensity and γ\gammaγ is a constant. It
brightens images when γ<1\gamma < 1γ<1 and darkens them
when γ>1\gamma > 1γ>1.

Program code:
a=imread('Gear 5.jpg');
subplot(1,2,1);
imshow(a);
title("Original Image");
r=double(a); c=1;
s=c*log(1+r);
t=255/(c*log(256));
b=uint8(t*s);
subplot(1,2,2);
imshow(b);
title("Log Transformation");
Analysis:
The image undergoes a transformation with γ=0.6\gamma =
0.6γ=0.6, enhancing brightness. This method adjusts contrast
and helps bring out details in specific intensity ranges.

Conclusion:
The program successfully applies Power Law Transformation,
improving the brightness and contrast of the image, making it
useful for image enhancement in various lighting conditions.

You might also like