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

Pop-Up Menu


A very simple example to show how the pop-up menu / Drop down list in MATLAB works.



MATLAB CODE:
function Popup_menu
global filename Img  I T;
scz=get(0,'ScreenSize');

figure('Position',[round(scz(1,3)/4) round(scz(1,4)/8) 800 500],'MenuBar','None','NumberTitle','off','Name','PopUpMenu Example','Resize','off');
axes('Position',[0 0 .7 1],'xtick',[],'ytick',[]);

directory=dir('*.jpg');
files={directory.name}';

%Get the File Name
%Position =[X Y length width]
uicontrol('style','text','Position',[565,453 60 20]','String','Filename:');
%The file names are the options here.
uicontrol('Style','popupmenu','position',[628 445 170 30],'Value',1,'String',files,'Callback',@displayfile);

%Select the Conversion type
uicontrol('style','text','Position',[565,415 90 20]','String','Image 
Conversion:');

%The options for image conversion are : Original Image, Convert to grayscale,
Convert to binary, Edge detected Image.
uicontrol('Style','popupmenu','position',[565 375 200 30],'Value',1,'String',{'Convert to GrayScale','Convert to Binary','Original Image','Edge detected Image'},'Callback',@convert);

%Select the edge type
T=uicontrol('Style','popupmenu','position',[565 305 200 30],'Value',1,'String',{'Canny','Sobel','Prewitt','log'},'callback',@findedge);
F=uicontrol('style','text','Position',[565,345 90 20]','String','Edge Type:');

%These components can be made visible or invisible
set(T,'Visible','off');
set(F,'Visible','off');

function displayfile(obj,eve)
        ptr=get(obj,'value');
        filename=char(files(ptr));
        Img=imread(filename);
        imshow(Img);
end

%Switch case
%Value 1 performs the conversion of the orginal image to grayscale image
%Value 2 performs the conversion of the orginal image to binary image
%Value 3 shows the orginal image
%Value 4 performs the edge detection of the image based on the type.




    function convert(obj,eve)
        ptr=get(obj,'value');
        switch ptr
            case {1}
                set(T,'Visible','off');
                set(F,'Visible','off');
                I=rgb2gray(Img);
                imshow(I);
            case {2}
                set(T,'Visible','off');
                set(F,'Visible','off');
                I=im2bw(Img);
                imshow(I);
            case {3}
                set(T,'Visible','off');
                set(F,'Visible','off');
                imshow(Img);
            case {4}
            set(T,'Visible','on');
            set(F,'Visible','on');
   
                           
        end
    end

                                                              
                                                             
                                                              


                                      
                                 
                                      
                                     


       
  %To perform edge detection based on the type
    function findedge(obj,event)
            ptr=get(obj,'value');
            B=rgb2gray(Img);
            switch ptr
                case {1}
                    imshow(~edge(B,'canny'));
                case {2}
                    imshow(~edge(B,'sobel'));
                case {3}
                    imshow(~edge(B,'Prewitt'));
                case {4}
                    imshow(~edge(B,'log'));
                   
            end
           
           
        end
               
   
end




like button Like "IMAGE PROCESSING" page

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
Previous Post Next Post Home
Google ping Hypersmash.com