Image Processing Lab Manual
Image Processing Lab Manual
Image Processing Lab Manual
Lab manual
Overwriting variable
>> t = 5;
>> t = t+1
t =6
Error messages
>> x = 10;
>> 5x
??? 5x
|
.Error: Unexpected MATLAB expression
Getting help
>> help Command
>> lookfor inverse
Mathematical functions
Basic plotting
Example
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)
Adding titles, axis labels, and annotations
Example
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y)
>> xlabel('x = 0:2\pi')
>> ylabel('Sine of x')
>> title('Plot of the Sine function')
Notes:
0:pi/100:2*pi yields a vector that:
starts at 0,
takes steps (or increments)
of ¼=100,
stops when 2¼ is reached.
plot(x,y,'style_color_marker')
Lab#2
Matrix generation
Entering a vector
>> v = [1 4 7 10 13]
v=
1 4 7 10 13
>> A (2,1)
ans =
4
Creating a sub-matrix
Lab#3
Basic functions in matlab
Imread()
img = imread('ImageProcessing_1/BerkeleyTower.png');
>> size(img)
imshow()
To show our image, we the imshow() or imagesc() command. Theimshow() command
shows an image in standard 8-bit format, like it would appear in a web browser.
The imagesc() command displays the image on scaled axes with the min value as black
and the max value as white.
Using imshow(): Using imagesc():
Actually, a color image is a combined image of 3 grayscale images. So, we can display
the individual RGB components of the image using the following script:
subplot(131);
imagesc(img(:,:,1));
title('Red');
subplot(132);
imagesc(img(:,:,2));
title('Green');
subplot(133);
imagesc(img(:,:,3));
title('Blue');
Want to play more? Then, let's make a new image that has more blue by quadrupling the
component. The standard image format is uint8 (8-bit integer), which may not like
arithmetic operation and could give us errors if we try mathematical operations. So, we
may want to do image processing by casting our image matrix to double format before
we do our math. Then we cast back to uint8 format at the end, before displaying the
image.
subplot(211);
imshow(img);
title('Normal RGB');
subplot(212);
blue_img = double(img);
blue_img(:,:,3) = 4*blue_img(:,:,3);
blue_img = uint8(blue_img);
imshow(blue_img);
title('RG 4*B');
Lab#4
imwrite()
To save your new blue image, use the imwrite() command:
rgb2gray()
img = imread('ImageProcessing_1/BerkeleyTower.png');
gray = rgb2gray(img);
imshow(gray);
>> size(gray)
ans =
499 748
Now, we have only one value for each pixel not 3 values. In other words,
the rgb2gray() converted RGB images to grayscale by eliminating the hue and saturation
information while retaining the luminance.
Adding noise to image
Description
J = imnoise(I,type) adds noise of a given type to the intensity image I. type is a
string that specifies any of the following types of noise. Note that certain types of noise
support additional parameters. See the related syntax.
Example
I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
figure, imshow(I)
figure, imshow(J)
Lab Assignment
Add all types of noise of cameraman picture
Lab#5
Removing noise from image
I = imread('eight.tif');
figure, imshow(I)
Lab Assignment
Try to use three other filters to remove noise from image
Lab#6
Image Enhancement
imadjust increases the contrast of the image by mapping the values of the input intensity
image to new values such that, by default, 1% of the data is saturated at low and high intensities of the
input data.
histeq performs histogram equalization. It enhances the contrast of images by transforming
the values in an intensity image so that the histogram of the output image approximately matches a
specified histogram (uniform distribution by default).
adapthisteq performs contrast-limited adaptive histogram equalization. Unlike histeq, it
operates on small data regions (tiles) rather than the entire image. Each tile's contrast is enhanced so
that the histogram of each output region approximately matches the specified histogram (uniform
distribution by default). The contrast enhancement can be limited in order to avoid amplifying the noise
which might be present in the image.
pout_imadjust = imadjust(pout);
pout_histeq = histeq(pout);
pout_adapthisteq = adapthisteq(pout);
imshow(pout);
title('Original');
figure, imshow(pout_imadjust);
title('Imadjust');
Lab Assignment
Lab#7
Image Edge Detection
Compare Edge Detection Using Canny and Prewitt Methods
Read a grayscale image into the workspace and display it.
I = imread('circuit.tif');
imshow(I)