sharma dip
sharma dip
sharma dip
LAB Report
Aim:
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:
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.
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.
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.
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:
1. Addition: Blends images, potentially brightening the result.
2. Subtraction: Highlights differences and creates contrast.
3. Multiplication: Combines images, darkening the result.
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.
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.
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
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.
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”
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”
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);
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.