Bangladesh Army University of Engineering & Technology (BAUET)
Department of Computer Science and Engineering
Course Title : Digital Image Processing
Submitted By Submitted to
ID: Senior Lecturer,
Session:2015-2016 Dept of CSE,BAUET
Section: B Mithun Kumar
Batch 3rdLecturer Dept of CSE,BAUET
Image processing is the technique to convert an image into digital format and perform operations on it to get an enhanced image or extract some useful information from it. Changes that take place in images are usually performed automatically and rely on carefully designed algorithms.
What is a digital image?
A digital image may be defined as a two-dimensional function f(x,y), where ‘x’ and ‘y’ are spatial coordinates and the amplitude of ‘f’ at any pair of coordinates is called the intensity of the image at that point. When ‘x,’ ‘y’ and amplitude values of ‘f’ are all finite discrete quantities, the image is referred to as a digital image.
A digitised image is represented as:
Each element in the array is referred to as a pixel or an image element.
In MATLAB a digital image is represented as:
Images are read in MATLAB environment using the function ‘imread.’ Syntax of imread is:
where ‘filename’ is a string having the complete name of the image, including its extension.
Images are displayed on the MATLAB desktop using the function imshow, which has the basic syntax:
where ‘f’ is an image array of data type ‘uint8’ or double. Data type ‘uint8’ restricts the values of integers between 0 and 255.
Images are written to the current directory using the imwrite function, which has the following syntax:
An RGB image can be viewed as three different images(a red scale image, a green scale image and a blue scale image) stacked on top of each other, and when fed into the red, green and blue inputs of a color monitor, it produces a color image on the screen.
Gray Scale Image
A Grayscale image can be viewed as a single layered image. In MATLAB, a grayscale image is basically M*N array whose values have been scaled to represent intensities.
Convert RGB to Gray Scale
RGB = imread(‘d.png’);
I = rgb2gray(RGB);
In MATLAB, Images are stored in matrices, in which each element of the matrix corresponds to a single discrete pixel of the image. We can get the mirror image of the given image if we reverse the order of the pixels (elements of the matrix) in each row.
B = flip(A)
B = flip(A,dim)
B = flip
B the same size as
A, but with the order of
the elements reversed. The dimension that is reordered in
on the shape of
vector, then flip
the order of the elements along the length of the vector.
a matrix, then flip
the elements in each column.
an N-D array, then flip
on the first dimension of
which the size value is not
B = flip
) reverses the order of the elements in
A along dimension
dim. For example, if
A is a matrix, then flip
(A,1) reverses the elements in each column, andflip
(A,2) reverses the elements in each row.
I = imread(‘d.png’);
I2 = flipdim(I ,2); %# horizontal flip
I3 = flipdim(I ,1); %# vertical flip
I4 = flipdim(I3,2); %# horizontal+vertical flip
In MATLAB, an RGB image is basically a 3-D image array (M*N*3) of color pixel, where each color pixel is associated with three values which correspond to red,blue and green color component of RGB image at a specified spatial location.
In complement of colors an RGB image, Each color in RGB image is replaced with their complementary color.
In mathematics (in particular, function analysis) convolution is a mathematical operation on two functions (f and g) that produces a third function expressing how the shape of one is modified by the other. The term convolution refers to both the result function and to the process of computing it. It is defined as the integral of the product of the two functions after one is reversed and shifted.
Some features of convolution are similar to cross-correlation for real-valued functions, of a continuous or discrete variable, it differs from cross-correlation only in that either f(x) or g(x) is reflected about the y-axis; thus it is a cross-correlation of f(x)and g(−x), or f(−x) and g(x).[A] For continuous functions, the cross-correlation operator is the adjoint of the convolution operator.
C= paddarray(A,[1 1]);
Dilation & Erosion
Morphology is a broad set of image processing operations that process images based on shapes. Morphological operations apply a structuring element to an input image, creating an output image of the same size. In a morphological operation, the value of each pixel in the output image is based on a comparison of the corresponding pixel in the input image with its neighbors. By choosing the size and shape of the neighborhood, you can construct a morphological operation that is sensitive to specific shapes in the input image.
The most basic morphological operations are dilation and erosion. Dilation adds pixels to the boundaries of objects in an image, while erosion removes pixels on object boundaries. The number of pixels added or removed from the objects in an image depends on the size and shape of the structuring element used to process the image. In the morphological dilation and erosion operations, the state of any given pixel in the output image is determined by applying a rule to the corresponding pixel and its neighbors in the input image. The rule used to process the pixels defines the operation as a dilation or an erosion. This table lists the rules for both dilation and erosion.
Basic image processing with MATLAB
MATLAB is a very simple software for coding. All data variable in MATLAB are thought a matrix and matrix operations are used for analyzing them. MATLAB has the different toolboxes according to application areas. In this section, MATLAB Image Processing Toolbox is presented and the use of its basic functions for digital image is explained.
Image reserve technique, each all elements of the matrix is replaced to be the top row elements to bottom row and the bottom row elements to top row. In the other words, the image rotates on the vertical axis.
MATLAB Image Processing Toolbox does not have function for it. Either the script is written or flipdim function can be used (Figure 12).
Mirroring technique is the rotating of reversed image on the horizontal axis. In MATLAB Image Processing Toolbox has imrotate() function for rotating image. This function needs three properties which are image matrix variable,
rotating angle, and interpolation method (Figure 13).
Sometimes, an image can be wanted to shift up to certain pixel value on the horizontal and vertical axis. imtranslate() function is used to shift of an image. In the Figure 14 the image shifts 15 px right and 25 px bottom.
If an image is displayed big or small size for showing details or general view, its resolution must be changed. These situations are called zoom‐in and zoom‐out. Digital cameras or photosensitive devices use optic lenses for zoom‐in and zoom‐out. But, interpolation methods are only used for digital images. Most common problem of interpolation methods is the changing quality of image
Intensity values of image are reversed as linear for negative image (Figure 20).
Histogram counts the number of gray value of pixels in the images. Each pixel in the image has gray value between 0 and 255. As shown in Table 3, counting pixels give us information about image or objects in the image.
The histogram of image is calculated using imhist(image) function in the MATLAB.
Histogram equalization is defined a technique for adjusting contrast of an image using all gray values to equalize as much as possible. Some situations work fine and image are shown very well; sometimes, it is not good and new image is darker than original image
After histogram equalization is applied to the image, new gray values are shown in
Edge detection is used for finding the border of objects in the image (Figure 39). Common edge detection algorithms are Sobel, Canny, Prewitt, Roberts, etc.