The document is a MATLAB assignment submitted by Hinna Nayab to Dr. Shehzad. It includes constructing matrices, extracting columns, adding noise, and exploring image processing functions in MATLAB such as reading images, morphological operations, thresholding, and histograms. Key steps are constructing a 10x10 diagonal matrix, adding random noise, and practicing demos from the Image and Image Processing toolboxes.
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Vision systems_Image processing tool box in MATLAB
1. “VISION SYSTEMS”
ASSIGNMENT NO: 1
SUBMITTED BY: HINNA NAYAB
REGN. NO: 11PWMCT0143
SUBMITTED TO: DR. SHEHZAD
(9th
March, 2015)
8TH
SEMESTER
(MORNING)
INSTITUTE OF MECHATRONICS ENGINEERING
UET, PESHAWAR
2. MATLAB INTRODUCTION
1. Construct a 10x10 matrix such that the diagonal elements get the value of the indices
(eg. index (3,3) gets the value 3), and the element with index (10,1) gets the value 5.
A matrix was constructed by using ‘rand(n)’ function to form a randomly generated matrix. The
diagonal elements and index(10,1) were specified as directed.
3. 2. Extract the 2,3 and 7 column from the matrix with one command.
3. What is the expected result of matrix multiplication and element-wise multiplication of
this matrix with itself ? Confirm your expectations using Matlab. What is the general
operator for element-wise operations in Matlab?
The general operator for element-wise operations in matlab is ‘.’ e.g
• Multiplication(.*)
• Addition(.+)
• Subtraction(.-)
• Division(./ or.)
4. 4. Show the original matrix as an image.
The original matrix was shown as an image by trying out commands: ‘image(A)’, ‘imagesc(A)’,
‘imshow(A)’.
• >>Image(A)
‘ image(A)’ displays matrix A as an image. Each element of A specifies the color of a rectilinear
patch in the image.
• >>imagesc(A)
‘Imagesc’: “Scale data and display as image.” imagesc(A) is the same as image(A) except the
data is scaled to use the full colormap.
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
5. >> axis image %axis image fits the plot box directly around the data
• >>imshow(A)
(imshow(A) displays the grayscale image A)
‘COLORMAP’ FUNCTION:
M-by-3 matrix specifying a colormap. imshow uses this to set the figure's colormap property.
This parameter is used to view grayscale images in false color.
The colormap matrix for ‘A’ in matlab:
>>cmap=colormap
cmap =
2 4 6 8 10
1
2
3
4
5
6
7
8
9
10
8. 0.5625 0 0
0.5000 0 0
Trying out some basic colormap functions:
>>colormap(cmap) %sets the current figure’s colormap to cmap.
>> colormap('default') %sets the current figure's colormap tothe root's default, whose
setting is JET.
>>colormap(bone) %bone is a grayscale colormap with a higher value for blue component.
(Adds electronic look to grayscale images.)
>>colormap(spring) %spring consistes of colors that are shades of magenta and yellow.
2 4 6 8 10
1
2
3
4
5
6
7
8
9
10
9. >>colormap(autumn) %autumn varies smoothly from orange to red to yellow.
>>colormap(winter) %winter consists of colors that are shades of blue and green.
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
10. >>colormap(copper) %copper varies smoothly from black to bright copper.
>>colormap(gray) %returns a linear grayscale image.
5. Describe the following coordinate systems: Matrix coordinates, Mathematical Cartesian
coordinates, and Matlab image coordinates. For each you must point out where the
coordinates (10,1) is located in a 10x10 coordinate frame. Are there any differences? Which
coordinate system do you prefer?
CARTESIAN COORDINATES:
The Cartesian coordinate system is commonly used in mathematics. The origin is the point (0,
0). In this system, the first component x increases to the right, while the second component y
increases upward. The origin (0, 0) is at the lower-left corner. It is the most common coordinate
system for manipulating mathematical entities, such as parametric surfaces.
(The index (10,1) is located in 1st quadrant, lower right corner)
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
11. MATRIX COORDINATES:
The matrix coordinate system is commonly used for matrices and displays. The origin is at the
upper left corner and usually starts with (1, 1). The matrix coordinate system, also called the
row-column coordinate system, is MATLAB's coordinate system for matrices. MATLAB uses this
system for matrix subscript notation. In this system, the first component (row) increases
downward, while the second component (column) increases to the right.
(The index (10, 1) is located at the lower-left corner)
MATLAB IMAGE (PIXEL) COORDINATES:
The pixel coordinate system is the most common coordinate system for digital image
processing in MATLAB. For pixel coordinates, the first component x increases to the right, while
the second component y increases downward. The origin is at the upper left corner. These
coordinates are typically integers. If we compare it to the row-column system, then row
corresponds to y and column corresponds to x. If we compare it to the Cartesian system, then
the y axis is reversed.
(The index(10,1) is located at the upper-right corner)
MATLAB uses the matrix coordinate system for image matrix manipulation and the pixel
coordinate system for everything else.
The preferred coordinate system is the Matrix coordinate system since it makes the
mathematical computations easy.
6. Add noise to the image Use the Matlab helpdesk to search for functions that generate
random noise. Display the original matrix with noise added.
ADDING NOISE:
Adding ‘Gaussian’ (white noise with constant mean and variance) noise: