MATLAB, TEXT EXTRACTION, COLOR CHANGE, GRAY TO RGB, and Smliye, IMAGE ADD, Addition DIgital Image...

13
for quire contact: [email protected] Project Tasks 1. Remove words 'smschacha.com' 2. Add buhaha along with a smiley face below the good night and above smschacha.com Project Image 1 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

Transcript of MATLAB, TEXT EXTRACTION, COLOR CHANGE, GRAY TO RGB, and Smliye, IMAGE ADD, Addition DIgital Image...

for quire contact: [email protected]

Project Tasks1. Remove words 'smschacha.com'

2. Add buhaha along with a smiley face below the good night and above smschacha.com

Project Image

1 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

SOFTWARE : ---- MATLAB 2013a

BEST OF LUCK.

Engnr Rana Muhammad Shakeel

[email protected]

+92-333-4962507

https://www.facebook.com/EngnrShakeel

plz like my page:

2 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

Project Methodology: Color Image Converted in to Gray scale Then by using “Sobel filter” detected the required

Text Subtract the selected required Text from the Gray

scale starting image Adjust gray color at extracting place with

neighbors color Convert the image again back from gray to RGB scale

by comparing colors of the Starting image Add text “buhahaha ” below the good night location

text Add the smiley to the image

1)Directly ADD the Image of Smiley (or)2)Made simple Smiley by Polygon

Save the final image

MATLAB CODE:clc;clear all;%k=input('Enter the file name','s'); % input image; color image

3 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

im=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\Project_1.jpg');im1=rgb2gray(im);sze=size(im1);im1=medfilt2(im1,[3 3]); %Median filtering the image to remove noise%BW = edge(im1,'sobel'); %finding edges [imx,imy]=size(BW);msk=[0 0 0 0 0 0 0 0 0; 0 1 1 1 1 1 1 1 0; 0 1 1 1 1 1 1 1 0; 0 1 1 1 1 1 1 1 0; 0 1 1 1 1 1 1 1 0; 0 1 1 1 1 1 1 1 0; 0 1 1 1 1 1 1 1 0; 0 0 0 0 0 0 0 1 0;];B=conv2(double(BW),double(msk)); %Smoothing image to reduce the number of connected componentsL = bwlabel(B,8);% Calculating connected componentsmx=max(max(L));% There will be mx connected components.Here U can give a value between 1 and mx for L or in a loop you can extract all connected components [r,c] = find(L==18); rc = [r c];[sx sy]=size(rc);n1=zeros(imx,imy); for i=1:sx x1=rc(i,1); y1=rc(i,2); n1(x1,y1)=255;end % Storing the extracted image in an array figure(1)subplot(2,2,1),imshow(im);title('orignal image');subplot(2,2,2),imshow(B);title('segmented image');imwrite(B,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\segmented Image.jpg');subplot(2,2,3),imshow(n1,[]);title('TEXT DETECTED IMAGE');imwrite(n1,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\Text Detaction.jpg'); %text subtraction and gray colour smoothingfigure(2)a=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\Text Detaction.jpg');im=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\Project_1.jpg');

4 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

im1=rgb2gray(im);subplot(2,2,1),imshow(a);title('text detected image');subplot(2,2,2),imshow(im1);title('orignal rgb to gray image');A = imresize(a, [405 530]);c2=imsubtract(im1,A);subplot(2,2,3),imshow(c2);title('TEXT subtracted IMAGE');imwrite(c2,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXT EXTRECTED.jpg'); siz=size(c2)c2(360:387,369:514)=61; %adjust gray color at extraactig placeimwrite(c2,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXT EXTRECTED gray Image.jpg');T=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXT EXTRECTED gray Image.jpg');subplot(2,2,4),imshow(T);title('Gray colour smothing of Extracted IMAGE'); %colouring the imageim=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\Project_1.jpg');figure(3)subplot(2,2,1),imshow(im);title('Project Orignal IMAGE');T=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXT EXTRECTED gray Image.jpg');subplot(2,2,2),imshow(T);title('Gray colour smothing of Extracted IMAGE'); R=gray2rgb(T,im);imwrite(R,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\gray2rgb.jpg'); r2=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\gray2rgb.jpg'); subplot(2,2,3),imshow(r2);title('gray to rgb convertion with respect to orignal image '); %text addition in imagefigure(4)subplot(1,2,1),imshow(r2);title('gray to rgb convertion with respect to orignal image ');Text = sprintf('Buhahaha');H = vision.TextInserter(Text);H.Color = [1.0 1.0 0];H.FontSize = 20;H.Location = [305 185];I = im2double(r2);InsertedImage = step(H, I);

5 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

imwrite(InsertedImage,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXT added Image.jpg');subplot(1,2,2),imshow(InsertedImage);title('TEXT "Buhahaha" added to IMAGE'); %adding smiley option 1X=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXT added Image.jpg');figure(5)subplot(2,2,1),imshow(InsertedImage);title('TEXT "Buhahaha" added to IMAGE');s=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\smiley.jpg');subplot(2,2,2),imshow(InsertedImage);title('smiley image'); I = imresize(s, [75 75]); I = im2double(imresize(I, 0.2)); E = zeros(405,530,3); E([1:size(I,1)] + 192, [1:size(I,2)] + 409,[1:size(I,3)]) = I; A = imresize(E, [405 530]);imwrite(A,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\sss.jpg'); X=imread('B:\Users\Shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\sss.jpg'); subplot(2,2,3),imshow(X);title('smiley PADDED image');I =imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXTAdded Image.jpg');A = imresize(X, [405 530]);cd=imadd(I,A);subplot(2,2,4),imshow(cd);title('FINAL image');imwrite(cd,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\final image.jpg'); %adding simily option 2X1=imread('B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\TEXTadded Image.jpg');[xoc yoc] = circle([415 192], 12, 100); % outer circlefigure(6)imshow(X1);title('FINAL image'); hold onfill(xoc,yoc,'y') [xoc yoc] = circle([410 190], 2, 100); % inner circlefill(xoc,yoc,'k');[xoc yoc] = circle([420 190], 2, 100); % inner circlefill(xoc,yoc,'k');[xoc yoc] = circle([415 198], 4, 100); % inner circlefill(xoc,yoc,'w');plot(xoc, yoc,'linewidth',1,'color','k');

6 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

hold off;F = getframe;imwrite(F.cdata,'B:\Users\shakeel\Documents\MATLAB\DIP\PROECT FILES\dip project\final image 2.jpg');

Functions Used in MATLAB:

1. For GRAY to RGB conversion function R=gray2rgb(img1,img2)ticclc;warning off;imt=img1;ims=img2;[sx sy sz]=size(imt);[tx ty tz]=size(ims);if sz~=1 imt=rgb2gray(imt);endif tz~=3 disp ('img2 must be a color image (not indexed)');else imt(:,:,2)=imt(:,:,1); imt(:,:,3)=imt(:,:,1); % Converting to ycbcr color space nspace1=rgb2ycbcr(ims); nspace2= rgb2ycbcr(imt); ms=double(nspace1(:,:,1)); mt=double(nspace2(:,:,1)); m1=max(max(ms)); m2=min(min(ms)); m3=max(max(mt)); m4=min(min(mt)); d1=m1-m2; d2=m3-m4;% Normalization dx1=ms; dx2=mt; dx1=(dx1*255)/(255-d1); dx2=(dx2*255)/(255-d2);

7 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

[mx,my,mz]=size(dx2);%Luminance Comparison disp('Please wait..................'); for i=1:mx for j=1:my iy=dx2(i,j); tmp=abs(dx1-iy); ck=min(min(tmp)); [r,c] = find(tmp==ck); ck=isempty(r); if (ck~=1) nimage(i,j,2)=nspace1(r(1),c(1),2); nimage(i,j,3)=nspace1(r(1),c(1),3); nimage(i,j,1)=nspace2(i,j,1); end end end rslt=ycbcr2rgb(nimage) R=uint8(rslt); tocend

2. For Circle made function [X Y] = circle(center,radius,n) THETA = linspace(0, 2 * pi, n);RHO = ones(1, n) * radius;[X Y] = pol2cart(THETA, RHO);X = X + center(1);Y = Y + center(2);end

OUTPUT:

8 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

a) Step 1:

9 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

b) Step 2:

10 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

c) Step 3:

11 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

d) Step 4:

Final Image

12 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]

for quire contact: [email protected]

………………………………THE END…………………………….

13 Engnr Rana M Shakeel, +92-333-4962507 | [email protected]