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

Paint Application using bwlabel concept

 Fill the image with RGB colors based on user specified color value. Instead of Flood fill algorithm I am using bwlabel function in MATLAB to paint the image. 

This is very simple comparing to the previous application.


function color
global BW L A colorv rgb originalcolor undocolor point filename;
scz=get(0,'ScreenSize');
figure('Position',[round(scz(1,3)/4) round(scz(1,4)/8) 700 500],'MenuBar','None','NumberTitle','off','Name','Paint Application','Resize','off');
originalcolor=[0;0;0;];
ax=axes('Position',[0 0 .7 1],'xtick',[],'ytick',[]);
directory=dir('*.png');
files={directory.name}';
uicontrol('Style','popupmenu','position',[535 430 160 30],'Value',1,'String',files,'Callback',@displayfile);
uicontrol('Style','text','position',[495 400 35 20],'String','RED');
 
R=uicontrol('Style','slider''position',[535 400 160 20],'min', 0.0, 'max',1.0,'Callback',@colorvalue);
 
uicontrol('Style','text','position',[495 360 35 20],'String','GREEN');
G=uicontrol('Style','slider''position',[535 360 160 20],'min', 0.0, 'max',1.0,'Callback',@colorvalue);
 
uicontrol('Style','text','position',[495 320 35 20],'String','BLUE');
B=uicontrol('Style','slider''position',[535 320 160 20],'min', 0.0, 'max',1.0,'Callback',@colorvalue);
 
uicontrol('Style','text','position',[495 280 35 20],'String','Color');
colorv(25,80,1:3)=0;
uicontrol('Style','pushbutton','position',[600, 470, 40,20],'String''UNDO','Callback',@options);
uicontrol('Style','pushbutton','position',[645, 470, 40,20],'String''SAVE','Callback',@options);
uicontrol('Style','pushbutton','position',[540 280 80 30]);



Function ‘colorvalue’ will show the color on the pushbutton.





function colorvalue(obj,event)
        R1=get(R,'value');
        G1=get(G,'value');
        B1=get(B,'value');
        rgb=[ceil(R1*255); ceil(G1*255); ceil(B1*255);];
        colorv(:,:,1)=R1;
        colorv(:,:,2)=G1;
        colorv(:,:,3)=B1;
uicontrol('Style','pushbutton','position',[540 280 80 30],'String','color','CDATA',colorv);
  originalcolor=rgb;
  try
 paintme;
  catch
      originalcolor='null';
  end
    end
    

%User selects the image

function displayfile(obj,event)
        ptr=get(obj,'value');
        filename=char(files(ptr));
        A=imread(filename);
        [BW,L]=bwlabel(im2bw(A),8);
        imshow(BW);
end
    function paintme
        while(originalcolor==rgb)
            getpoints;
       end
    end

               
                       

                                                                                                                                                                 
                                                                                                                                         
                                                                                                                                    %To save the image or to go back to the previous point

function options(obj,event)
        fn=get(obj,'String');
        if(strcmp(fn,'SAVE')==1)
            fname=strcat('my',filename);
           msg=strcat('File name:',fname);
           msgbox(msg,'FILE SAVED');
        elseif(strcmp(fn,'UNDO')==1)
            rgb=undocolor;
            colorfill(point(1),point(2));
            rgb=originalcolor;
       end
    end
    

%Get the point in the image.

function getpoints
     try
         waitforbuttonpress;
         f=get(ax,'CurrentPoint');
         x=round(f(1,2));
         y=round(f(1,1));
        if(x< size(A,1) && y < size(A,2))
          %Check whether x and y are less than the image size
         point(1)=x;
         point(2)=y;
         undocolor=[A(x,y,1); A(x,y,2); A(x,y,3);];
         colorfill(x,y);
        end
     catch
        originalcolor='null';
     end
end



%Fill the image with the RGB value



function colorfill(x,y)
        label=BW(x,y);
        [r c]=find(BW==label);
         for i=1:size(r,1)
            A(r(i,1),c(i,1),:)=rgb;
        end
        imshow(A);
    end
end
Watch the video:                       Painting the image using MATLAB.
GET THE SAMPLE IMAGE AT:http://www.clker.com/clipart-jumping-horse-outline.html

like button Like "IMAGE PROCESSING" page

1 comments:

raj kumar said... Reply to comment

I like your page man its awsome

Enjoyed Reading? Share Your Views

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