Digital Image Processing using Matlab

Here, in this post I will write a code which will find the area in the picture where the sentence “Digital Image Processing” is written and outlines it.

So the result should be the picture where the sentence “Digital Image Processing” is highlighted.

 

%Reading image
I = imread(‘img1.jpg’);

%Show the original image
figure; imshow(I); title(‘Original Image’);

% Add some text on the right side of the picture, if you want to place this code in one
%line, remove dots.

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…
7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Original_Image

%Detect edges using sobel method
Isobel = edge(I,‘sobel’);

%Show image
figure; imshow(Isobel); title(‘Edge Detected Image’);

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…
7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Edge_Detected_Image

%Remove objects which are connected to the border
Inobord = imclearborder(Isobel);

%Show Image
figure; imshow(Inobord); title(‘Border Cleared Image 1’);

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…
7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Bordered_Cleared_Image_1

%Creates a disk-shaped structuring element by radius=15
StructEl1 = strel(‘disk’,15);

%Creates a linear structuring elements
StructEl2 = strel(‘line’, 3, 90);
StructEl3 = strel(‘line’, 3, 0);

%Remove the linear gaps from the picture
Idil = imdilate(Inobord, [StructEl2 StructEl3]);

%Because of, there left extra objects, I will dilate it by disk-shaped structuring element for to %make them connect to the border.
Idil = imdilate(Idil, StructEl1);

%Show image
figure; imshow(Idil); title(‘Dilated Image’);

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…
7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Dilated_Image

%Again remove objects which are connected to the border
Inobord1 = imclearborder(Idil);

%Show image
figure; imshow(Inobord1); title(‘Border Cleared Image 2’);

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…
7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Border_Cleared_Image_2

%Fill existing holes in the picture
Ifilled = imfill(Inobord1, ‘holes’);

%Show image
figure; imshow(Ifilled); title(‘Holes Filled Image’);

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…
7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Holes_Filled_Image

%Find perimeter of “Ifilled” image, with default connectivity 4
Ioutlined = bwperim(Ifilled);%The same as bwperim(Ifilled,4);
IOut = I;

%Highlight the desired area
IOut(Ioutlined) = 255;

%Show image
figure; imshow(IOut); title(‘Sentence Highlighted Image’);

text(size(I,2),size(I,1)+15,‘Edited by Mariam Kupatadze’,…
‘FontSize’,…7,…
‘HorizontalAlignment’,…
‘right’);

Digital_Image_Processing_Sentence_Highlighted_Image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s