Assignment: Digital Image Processing(BAUET)

Bangladesh Army University of Engineering & Technology (BAUET)

Department of Computer Science and Engineering

Assignment

Course Title : Digital Image Processing

Submitted By                                                               Submitted to

Name:                                                  

ID:                                                                Senior Lecturer,

Session:2015-2016                                                     Dept of CSE,BAUET

Section: B                                                                     Mithun Kumar

Batch 3rdLecturer                                                     Dept of CSE,BAUET

Image processing

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:

Reading images

Images are read in MATLAB environment using the function ‘imread.’ Syntax of imread is:

imread(‘filename’);

where ‘filename’ is a string having the complete name of the image, including its extension.

For example,

I=imread(‘p.png’);

Imshow(I)

Image display

Images are displayed on the MATLAB desktop using the function imshow, which has the basic syntax:

imshow(f)

where ‘f’ is an image array of data type ‘uint8’ or double. Data type ‘uint8’ restricts the values of integers between 0 and 255.

Writing images

Images are written to the current directory using the imwrite function, which has the following syntax:

imwrite(f, ‘filename’);

F=rand(100);
imwrite(F, ‘random.png’)

RGB image

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’);

Imshow(RGB)

I = rgb2gray(RGB);

figure

imshow(I)

Mirror Image

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.

Source Code

a=imread(‘d.png’);

imshow(a);

title(‘first image’);

[row,coloumn]=size(a);

fori=1:1:row

    k=1;

for j=coloumn:-1:1

        m(i,k)=a(i,j);

        k=k+1;

end

end

subplot(1,2,1),imshow(a);

subplot(1,2,2),imshow(m);

Flipped Image

B = flip(A)

B = flip(A,dim)

B = flip(A) returns array B the same size as A, but with the order of the elements reversed. The dimension that is reordered in B depends on the shape of A:

If A is vector, then flip(A) reverses the order of the elements along the length of the vector.

If A is a matrix, then flip(A) reverses the elements in each column.

If A is an N-D array, then flip(A) operates on the first dimension of A in which the size value is not 1.

example

B = flip(A,dim) 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.

Source Code

I = imread(‘d.png’);

I2 = flipdim(I ,2);           %# horizontal flip

I3 = flipdim(I ,1);           %# vertical flip

I4 = flipdim(I3,2);   %# horizontal+vertical flip

subplot(2,2,1), imshow(I)

subplot(2,2,2), imshow(I2)

subplot(2,2,3), imshow(I3)

subplot(2,2,4), imshow(I4)

Negative Image

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.

Source Code

a=imread(‘d.png’);

imshow(a);

[row,coloumn]=size(a)

A=255-a;

subplot(1,2,1),imshow(a);

subplot(1,2,2),imshow(A);

Convolution

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.

Source Code

A= ones(5);

B= ones(3);

C= paddarray(A,[1 1]);

[rw c1]=size(B);

for k=1:1:5

for l=1:1:5

        sum=0;

fori=1:1:rw

for j=1:1:c1

            sum=sum+(B(i,j)*C(i+l-1,j+k-1));

end

end

    d(l,k)=sum;

end

end

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.

          Source Code

A=ones(50)

B=ones(3)

C=padarray(A,[1 1])

[rw c1]=size(B)

for k=1:1:5

    p=0;

    sum=0;

fori=1:1:rw

for j=1:1:c1

            p=p+1;

            sum(1,p)=(B(i,j)*C(i+1-1,j+k-1));

end

end

    g(k,1)=max(sum);

    f(k,1)=min(sum);

end

end

g

f

Output

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 reverse

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).

Image mirroring

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).

Example

Image shift

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.

Image resize

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 

Negative

Intensity values of image are reversed as linear for negative image (Figure 20).

Histogram

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

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

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.

Updated: March 23, 2020 — 2:21 pm

The Author

Leave a Reply

Your email address will not be published. Required fields are marked *