Matlab Code for Image Shading

Here we tried to shade the RGB image which results in a pencil sketched type image. The user selects the image from the pop-up menu and by adjusting the line value in the slider, the edge thickness is made.
By adjusting the thresh value in the slider the image shade is increased or decreased.
Additional Information:
To make your own pencil sketch without using MATLAB try Autodesk Sketchbook.
Based on the customers review, this software is best to try on low pixel camera images.


Steps To Be Performed:

1.     Input a RGB image
2.     Convert the image to grayscale image.
3.     Find the edges using Sobel Method.[gradient Estimation]
4.     Filter the Image to obtain the image without noise
4.1.          The blurred or unsharp image is subtracted from the image to obtain the sharpened image.
5. Blend the edge and the sharpened image.


MATLAB Code:

function image_shade

The GUI is designed.

global filename A;
scz=get(0,'ScreenSize');
figure('Position',[round(scz(1,3)/4) round(scz(1,4)/8) 700 500],'MenuBar','None','NumberTitle','off','Name','Pencil sketch Application','Resize','off');
axes('Position',[0 0 .7 1],'xtick',[],'ytick',[]);
shade=uicontrol('Style','slider','Position',[500,310 200 20],'Max',1 ,'Min',0.01,'Value',0.56,'Callback',@draw);
thresh=uicontrol('Style','slider','Position',[500,370 200 20],'Max',255,'Min',0,'Value',30,'Callback',@draw);
directory=dir('*.jpg');
files={directory.name}';
tval=uicontrol('style','text','Position',[500,340 100 20]','String','Thresh :');
line=uicontrol('style','text','Position',[500,395 100 20]','String','Line :');
uicontrol('style','text','Position',[500,455 100 20]','String','Filename:');
uicontrol('Style','popupmenu','position',[500 420 160 30],'Value',1,'String',files,'Callback',@displayfile);

    function displayfile(obj,~)
        ptr=get(obj,'value');
        filename=char(files(ptr));
        A=imread(filename);                     
        imshow(A);
    end
    function draw(~,~)
     
        sh=get(shade,'Value');
        thr=get(thresh,'Value');
        thval=strcat('Thresh :', num2str(sh));
        set(tval,'String',thval);
     
        lineval=strcat('Line :', num2str(thr));
        set(line,'String',lineval);
       if(~isempty(A))
        A=imread(filename);
        B=rgb2gray(A);


The Edge of the image is detected using the sobel edge detection method.


C3=~edge(B,'sobel','VERTICAL');
C2=~edge(B,'sobel','HORIZONTAL');
C=uint8(C3.*C2);

The image is sharpened by subtracting the blur image.

F1=uint8(imfilter(B,fspecial('unsharp')/sh));

The blending of the edge and the filtered image is done.

for m=1:size(F1,1)
    for n=1:size(F1,2)
        if(C(m,n)==0)
           F1(m,n)=B(m,n)-thr;
        end
    end
end


imshow(F1);
       end
    end
end

Fig: Shaded Image

Fig: Original Image


Contact:
Mobile: +91-7276355704
WhatsApp: +91-7276355704
Email: roshanphelonde@rediffmail.com
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *