dip LAB_file_f
dip LAB_file_f
dip LAB_file_f
LAB Report
Section : S
Roll number : 68
Aim:
Introduction to the MATLAB commands
• Matrix representation: a is a 3x3 matrix, commonly used for data storage and
matrix operations.
• Range creation: b and t are arrays generated by np.arange() with evenly spaced
values.
• Step size in arrays: k is an array with a negative step size, showing flexibility in
array generation.
• 2D arrays: x is a 2x4 matrix, storing data in rows and columns.
• 1D array: y is a simple sequence of numbers in a 1D array.
Program code:
3. v =1:15
y = [1 2 5 1] o= [1:4; 5:8]
Conclusion:
Program code:
• a=[1 2 3; 4 5 6; 7 8 9]
• b=[10 11 12; 13 14 15; 16 17
18]
sub=a-b;
• sum= a+b;
mult= a*b;
Analysis:
Conclusion:
Aim:
Write a program to prints out Pascal’s triangle
Theory:
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:
2. Sine Function: np.sin(x) computes sine values for each x, forming the y-axis
data.
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:
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);
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:
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:
This practical demonstrates importing and resizing a digital image by 50%. Image
resizing is useful for reducing computational load or adjusting dimensions.
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);
Analysis:
The image is successfully resized to 50% of its original dimensions, reducing both
file size and resolution.
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:
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:
Binary Conversion: Both input images are converted into binary, simplifying the
image to two intensity levels.
• 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.
Theory:
•
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);
Analysis:
Binary Conversion: The image is transformed into binary, making the pixels
either black or white.
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.
PracticalNo. 13
Theory:
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:
Theory:
The Logarithmic Transformation enhances the details in the darker regions of an
image by compressing the dynamic range of pixel intensities. 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
Theory:
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.