Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Select your favorite topic

Image Shading in MATLAB

         
              Here I 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






Shaded Image

Original Image




like button Like "IMAGE PROCESSING" page

1 comments:

Yoshio de Jesús Astilleros said... Reply to comment

That code can be applied to a real time camera preview?... How?, can you help me?

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com