Code covered by the BSD License  

Highlights from
Image_processing2.

image thumbnail

Image_processing2.

by

 

gui toolbox for image processing

Image_processing2(varargin)
%Image_processing2 
%% Quick Start
% Click - Open File
% Select an image file
% 
% Then move the slider to select the RGB color filter that you want displayed
% Press the RGB
% Then Mark V mask
% And click the button RGBfilter
% 
% Snapshot - allows to acquire images from the camera
% Play live video - allows to show the changes live video selected
% Stop - Stops the video
% You can make more changes to properties
% And you can also select objects by size
% 
% Created by Oren Berkovitch
% During the period of development-10.31.2013 04.10.2013
% Version 1

function Image_processing2(varargin)

global  r g b rgbimage;
r=zeros();g=zeros();b=zeros();
rgbimage=zeros();
global Rfilter Gfilter Bfilter;
Rfilter=zeros();Gfilter=zeros();Bfilter=zeros();

%% figure propertis
fig=figure...
('resize','off','number','off','name','Image Process','menubar','none','unit','normalized','position',[ 0.296  0.067   0.7   0.883],...
    'renderer','opengl');
htab=uitabpanel('title',{'Process','Help','About Image'},'units','normalized',...
'Parent',fig);

%%
hpanel = getappdata(htab,'panels');
set(hpanel,'backg',[0.502 0.502 0.502])

% child1=get(par{1},'child');
htabw=uitabpanel('title',{'RGB','size filter','propertis'},...
    'units','normalized','position',[0 0 0.3 0.9]);
hpanelw = getappdata(htabw,'panels');
set(hpanelw,'backg',[0.831 0.816 0.784])
set(hpanel(3),'buttondownfcn',@About)
%% Axes , Panel

ax2=axes('parent',hpanel(3),'box','on','units','normalized','color','black',...
    'position',[0.33 0.11 0.65 0.78],'yticklabel','','xticklabel','');
ax=axes('parent',hpanel(1),'box','on','units','normalized','color','black',...
    'position',[0.33 0.25 0.64 0.68],'yticklabel','','xticklabel','');

uipanel('parent',hpanelw(3),'units','normalized','title','Manipuletion','position',[0 0 1 0.65])
ax1=axes('parent',hpanelw(3),'position',[0 0 1 1],'units','normalized');
axis off

uipanel('parent',hpanelw(3),'units','normalized','position',[0 0.6 1 0.35],'title','Reduction')
%face
face=uicontrol('parent',hpanel(1),'style','checkbox',...
    'units','normalized','string','Mask','position',[0.9 0.046 0.124 0.05]);
%% Fill holes
fill=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','Fill','position',[0.01 0.8 0.26 0.05]);

chofill=uicontrol('parent',hpanelw(3),'style','popupmenu',...
    'units','normalized','string',{'holes';'4';'8';'6';'18';'26'},'position',[0.53 0.8 0.3 0.05]);
%% Reduce noise from the image


noise=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','noise','position',[0.01 0.739 0.3 0.05]);
pixsel_noise=uicontrol('parent',hpanelw(3),'style','edit',...
    'units','normalized','string','','position',[0.53 0.739 0.3 0.05]);

%% Clear border from the image

clear_border=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','Clear border','position',[0.01 0.68 0.4 0.05]);

chos_clear=uicontrol('parent',hpanelw(3),'style','popupmenu',...
    'units','normalized','string',{'4';'8';'6';'18';'26'},'position',[0.53 0.68 0.3 0.05]);


uipanel('parent',hpanelw(2),'units','normalized','title','Size Object filter','position',[0 0.6 1 0.35])
%% dilate

dilate=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','Dilate','position',[0.01 0.4 0.3 0.05]);
chos_dilate=uicontrol('parent',hpanelw(3),'style','popupmenu',...
    'units','normalized','string',{'ball';'diamond';'disk';'line';'octagon';'pair';'perodicline';'rectangle';'square'},...
    'position',[0.33 0.4 0.3 0.05]);

dpar1=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.66 0.4 0.1 0.05]);
dpar2=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.76 0.4 0.1 0.05]);
dpar3=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.86 0.4 0.1 0.05]);

set(chos_dilate,'callback',{@streltext,chos_dilate})
%%

erod=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','Erode','position',[0.01 0.3 0.3 0.05]);

chos_erod=uicontrol('parent',hpanelw(3),'style','popupmenu',...
    'units','normalized','string',{'ball';'diamond';'disk';'line';'octagon';'pair';'perodicline';'rectangle';'square'},...
    'position',[0.33 0.3 0.3 0.05]);
% parameterof the strel
epar1=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.66 0.3 0.1 0.05]);
epar2=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.76 0.3 0.1 0.05]);
epar3=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.86 0.3 0.1 0.05]);


set(chos_erod,'callback',{@streltext,chos_erod})
%% open uicontrol
open=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','Open','position',[0.01 0.2 0.3 0.05]);

chos_open=uicontrol('parent',hpanelw(3),'style','popupmenu',...
    'units','normalized','string',{'ball';'diamond';'disk';'line';'octagon';'pair';'perodicline';'rectangle';'square'},...
    'position',[0.33 0.2 0.3 0.05]);

opar1=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.66 0.2 0.1 0.05]);
opar2=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.76 0.2 0.1 0.05]);
opar3=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.86 0.2 0.1 0.05]);

set(chos_open,'callback',{@streltext,chos_open})
%%

clos=uicontrol('parent',hpanelw(3),'style','checkbox',...
    'units','normalized','string','Close','position',[0.01  0.1 0.3 0.05]);

chos_close=uicontrol('parent',hpanelw(3),'style','popupmenu',...
    'units','normalized','string',{'ball';'diamond';'disk';'line';'octagon';'pair';'perodicline';'rectangle';'square'},...
    'position',[0.33 0.1 0.3 0.05]);
cpar1=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.66  0.1 0.1 0.05]);
cpar2=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.76 0.1 0.1 0.05]);
cpar3=uicontrol('parent',hpanelw(3),'style','edit','units','normalized',...
    'position',[0.86 0.1 0.1 0.05]);
set(chos_close,'callback',{@streltext,chos_close})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%get image
uicontrol('parent',hpanel(1),'style','pushbutton',...
    'units','normalized','string','open image','position',[0.8 0.946 0.124 0.05],...
    'callback',@setimage,'back','y');

%rgb filter
uicontrol('parent',hpanel(1),'style','pushbutton',...
    'units','normalized','string','RGB filter','position',[0.76 0.1 0.11 0.075],...
    'callback',@RGBfilter);

%get snapshot

uicontrol('parent',hpanel(1),'style','pushbutton',...
    'units','normalized','string','Snapshot'...
    ,'position',[0.4 0.1 0.11 0.075],...
    'callback',@Playvideo);

% play live video 
live=uicontrol('parent',hpanel(1),'style','togg',...
    'units','normalized','string','Play Live Video','position',[0.52 0.1 0.11 0.074],...
    'callback',@LiveVideo);
%pause
uicontrol('parent',hpanel(1),'style','pus',...
    'units','normalized','string','pause','position',[0.64 0.1 0.11 0.074],...
    'callback',@pause_video);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%get RGBparameter
%%%%%%%%%%%%%%    RGB    %%%%%%%%%%%%%%%/
uicontrol('parent',hpanelw(1),'style','pushbutton',...
    'units','normalized','string','RGB','position',[0.254 0.11 0.31 0.075],...
    'callback',{@RGB});

%RGBimage(rgbimage)
%red

Rmax=uicontrol('parent',hpanelw(1),'style','slider','units','normalized',...
    'backgroundcolor','red','position',[0.254 0.3 0.04 0.6],'Min',0,'Max',256,...
    'value',256,'callback',@Rminimum); % eval('[a1, a2, a3, ...] = function(var)
Rmin=uicontrol('parent',hpanelw(1),'style','slider','units','normalized',...
     'backgroundcolor','red','position',[0.354 0.3 0.04 0.6],'Min',0,'Max',256,...
    'callback',@Rminimum);
editRmax=uicontrol('parent',hpanelw(1),'style','edit','units','normalized',...
    'position',[0.254 0.91 0.15 0.05],'callback',@ScalerRimage);
editRmin=uicontrol('parent',hpanelw(1),'style','edit','units','normalized',...
    'position',[0.254 0.23 0.15 0.05],'callback',@ScalerRimage);

%green
Gmax=uicontrol('parent',hpanelw(1),'style','slider','units','normalized',...
    'backgroundcolor','green','position',[0.454 0.3 0.04 0.6],'Min',0,'Max',256,...
     'value',256,'callback',@Gminimum);
Gmin=uicontrol('parent',hpanelw(1),'style','slider','units','normalized',...
     'backgroundcolor','green','position',[0.554 0.3 0.04 0.6],'Min',0,'Max',256,...
    'callback',@Gminimum);
editGmax=uicontrol('parent',hpanelw(1),'style','edit','units','normalized',...
    'position',[0.454 0.91 0.15 0.05],'callback',@ScalerGimage);
editGmin=uicontrol('parent',hpanelw(1),'style','edit','units','normalized',...
    'position',[0.4544 0.23 0.15 0.05],'callback',@ScalerGimage);
%blue
Bmax=uicontrol('parent',hpanelw(1),'style','slider','units','normalized',...
    'backgroundcolor','blue','position',[0.654 0.3 0.04 0.6],'Min',0,'Max',256,...
    'value',256, 'callback',@Bminimum);
Bmin=uicontrol('parent',hpanelw(1),'style','slider','units','normalized',...
     'backgroundcolor','blue','position',[0.754 0.3 0.04 0.6],'Min',0,'Max',256,...
    'callback',@Bminimum);

editBmax=uicontrol('parent',hpanelw(1),'style','edit','units','normalized',...
    'position',[0.654 0.91 0.15 0.05],'callback',@ScalerBimage);
editBmin=uicontrol('parent',hpanelw(1),'style','edit','units','normalized',...
    'position',[0.654 0.23 0.15 0.05],'callback',@ScalerBimage);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%text
uicontrol('parent',hpanelw(2),'style','text',...
    'units','normalized','string','Number object:','position',[0.08 0.83 0.35 0.044]);

nub=uicontrol('parent',hpanelw(2),'style','text',...
    'units','normalized','string','No:','position',[0.45 0.83 0.15 0.044]);
%Selection of image objects according to the size of objects
%bigger

uicontrol('parent',hpanelw(2),'style','text','units','normalized',...
    'string','Bigger than:','position',[0.05 0.75 0.35 0.044])

Bigger=uicontrol('parent',hpanelw(2),'style','edit',...
    'units','normalized','position',[0.44 0.75 0.35 0.044]);

%smaler

uicontrol('parent',hpanelw(2),'style','text','units','normalized',...
    'string','Smaller than:','position',[0.05 0.65 0.35 0.044])

Smaller=uicontrol('parent',hpanelw(2),'style','edit',...
    'units','normalized','position',[0.44 0.65 0.35 0.044]);
%% perform

    uicontrol('parent',hpanelw(2),'style','pushbutton',...
    'units','normalized','string','Perform:','position',[0.44 0.55 0.35 0.044],...
    'callback',@Object_Size);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     function []=ScalerRimage(~,~)
      scalemin= str2double(get(editRmin,'string'));
      scalemax=str2double(get(editRmax,'string'));
      if (scalemin<0)||(scalemin>256)||(scalemax<0)||(scalemax>256)
      
      else
      set(Rmin,'value',scalemin);
      set(Rmax,'value',scalemax);
      Rminimum
      end

     end
 %red
     function []= Rminimum(~,~)
    color=r;
min=fix(get(Rmin,'value'));
max=fix(get(Rmax,'value'));

if min>max
   smaller=max;
   
   max=min;
   min=smaller;
end
set(editRmax,'string',max);
set(editRmin,'string',min);

[Rfilter] =FilterRGB(color,min,max);
hold(ax,'off');
imshow(Rfilter,'Parent',ax)
     end
%% editGmin
    function []=ScalerGimage(~,~)
      scalemin= str2double(get(editGmin,'string'));
      scalemax=str2double(get(editGmax,'string'));
      if (scalemin<0)||(scalemin>256)||(scalemax<0)||(scalemax>256)
      
      else
      set(Gmin,'value',scalemin);
      set(Gmax,'value',scalemax);
      Gminimum
      end

    end   
    function []= Gminimum(~,~)
    color=g;
min=fix(get(Gmin,'value'));
max=fix(get(Gmax,'value'));

if min>max
   smaller=max;
   
   max=min;
   min=smaller;
end
set(editGmax,'string',max);
set(editGmin,'string',min);

[Gfilter] =FilterRGB(color,min,max);
hold(ax,'off')
imshow(Gfilter,'Parent',ax)
     end
    function []=ScalerBimage(~,~)
      scalemin= str2double(get(editBmin,'string'));
      scalemax=str2double(get(editBmax,'string'));
      if (scalemin<0)||(scalemin>256)||(scalemax<0)||(scalemax>256)
      
      else
      set(Bmin,'value',scalemin);
      set(Bmax,'value',scalemax);
      Bminimum
      end

    end   
    function []= Bminimum(~,~)
    color=b;
min=fix(get(Bmin,'value'));
max=fix(get(Bmax,'value'));

if min>max
   smaller=max;
   
   max=min;
   min=smaller;
end
set(editBmax,'string',max);
set(editBmin,'string',min);

[Bfilter] =FilterRGB(color,min,max);
hold(ax,'off');
imshow(Bfilter,'Parent',ax);
     end
    function  [] = setimage(~,~,~)

   
       [FileName] = uigetfile('*.jpg;*.tif;*.png;*.bmp','Select the RGB image');
       if FileName==0
           return
       end
       rgbimage=imread(FileName);
       imshow(rgbimage,'parent',ax)
       
       try %try to separet to rgb image
           
       rgbimage=getimage(ax);
       [r,g,b]= RGBimage(rgbimage);
       catch err
           errordlg(err.message);
       end
    end
    function [r,g,b]= RGBimage(image,~,~)
  if ndims(image)==3 
        r=image(:,:,1); 
        g=image(:,:,2);
        b=image(:,:,3);
  end
    end
    function [Cfilter] =FilterRGB(color,Min,Max)
    cmax=color<Max;
    cmin=color>Min;
    Cfilter=cmax.*cmin;
    end
    function [rgbfilter] =RGBfilter(~,~,~)
        child_img=get(ax,'child');
        img_pic=get(child_img,'Cdata');
        
        
        if isempty(img_pic)==1 % if ther is no image exit the function
            return
        else
            
        rgbfilter=Rfilter.*Gfilter.*Bfilter;
        [img,flag]=getimage(ax);
            
        if ( ((flag==2)||(flag==5))&&isequal(img,rgbfilter)==0&&isequal(img,Rfilter)==0&&isequal(img,Gfilter)==0&&isequal(img,Bfilter)==0)
        rgbfilter=img;
        else
        end
        
        % check the checkbox of fill
      
       if get(fill,'value') ==1
           
           hol=get(chofill,'string');
           chos_hole=char(hol(get(chofill,'value')));
           
           if strcmp(chos_hole,'holes')==1
           rgbfilter=imfill(rgbfilter,'holes');
           else
                rgbfilter=imfill(rgbfilter,str2double(chos_hole));
           end
               
       end
       
       if get(noise,'value')==1
                 cla(ax1)
                 pixsel=get(pixsel_noise,'string');
                 % in the case nothing wase enter in the edit 
                 if isempty( str2num(pixsel))==1
                    cla(ax1)
                    text(0.1,0.54,{'noise empty or' ;'not numeric parmeter'},'parent',ax1,'color','r')
                    return
                 end    
           
           
       rgbfilter=bwareaopen(rgbfilter,str2num(pixsel)); %#ok<ST2NM>
      
       end
       
       %check the checkbox of clear border
     
       if get(clear_border,'value')==1
   
           
            rgbfilter=   imclearborder(rgbfilter);
       end    
       
       %dilet image
       if get(dilate,'value')==1
            content = get(chos_dilate,'string');
            shape=char(content(get(chos_dilate,'value')));
            try
            [se]=strel_shape(shape,dpar1,dpar2,dpar3) ;
            rgbfilter=imdilate(rgbfilter,se);
            catch  
              cla(ax1)
              text(0.1,0.54,'Streal parmeter is missing','parent',ax1,'color','r','unit','normalized')
            end    
       end
       
       %erod image
        if get(erod,'value')==1
            content = get(chos_erod,'string');
            shape=char(content(get(chos_erod,'value')));
            try
            [se]=strel_shape(shape,epar1,epar2,epar3) ;
            rgbfilter=imerode(rgbfilter,se);
              catch 
                cla(ax1)
              text(0.1,0.54,'Streal parmeter is missing','parent',ax1,'color','r','unit','normalized')
            end
            
       end
       %check the face checkbox 
       if get(open,'value')==1
           content = get(chos_open,'string');
            shape=char(content(get(chos_open,'value')));
            try
            [se]=strel_shape(shape,opar1,opar2,opar3) ;
            
            rgbfilter=imopen(rgbfilter,se);
            catch 
                cla(ax1)
              text(0.1,0.54,'Streal parmeter is missing','parent',ax1,'color','r','unit','normalized')
            end
                
           
       end
       
       if get(clos,'value')==1
            content = get(chos_close,'string');
            shape=char(content(get(chos_close,'value')));
            try
            [se]=strel_shape(shape,cpar1,cpar2,cpar3) ;
            rgbfilter=imopen(rgbfilter,se);
            catch 
                cla(ax1)
              text(0.1,0.54,'Streal parmeter is missing','parent',ax1,'color','r','unit','normalized')
            end
       end
       
      comp = bwconncomp(rgbfilter);
      set(nub,'string',comp.NumObjects)
       
       %
      % 
        if get(face,'value')==0
       imshow(rgbfilter,'parent',ax);
    
        elseif get(face,'value')==1
            
      rgbface=uint8(rgbfilter);
      facefilter=rgbimage;
      
      facefilter(:,:,1)=rgbimage(:,:,1).*rgbface;
      facefilter(:,:,2)=rgbimage(:,:,2).*rgbface;
      facefilter(:,:,3)=rgbimage(:,:,3).*rgbface;
     
      hold off
      imshow(facefilter,'parent',ax)
        end
        end
    end
    function []=Playvideo(~,~)
            
    closepreview
    imaqreset
    try
    vid = videoinput('winvideo', 1, 'YUY2_640x480');
    
    vid.FramesPerTrigger = 18;
    vid.ReturnedColorspace = 'rgb';
    vidRes = get(vid, 'VideoResolution');
    nBands = get(vid, 'NumberOfBands');
    hImage = image( zeros(vidRes(2), vidRes(1), nBands),'parent',ax );

% Display the video data in your GUI.

    preview(vid, hImage);
        
    start(vid);
    
    pause(1)
    stoppreview(vid);
    closepreview
    video = peekdata(vid,1);
    
    video=video(:,:,:,1);
  %  hold off
    imshow(video,'parent',ax);
    flushdata(vid,'all')
   
         
    
    % take the image and seperat to rgb image
   
    %try to separet to rgb image
         
       [rgbimage]=getimage(ax);
       [r,g,b]= RGBimage(rgbimage);

       
      
     
      catch err
         errordlg(err.message);
    end
    
    
    
    
    end
    function [] =RGB(~,~)

Rminimum;
Gminimum;
Bminimum;

    end
%% gui2

%% edite in 28/4/2013 sunday
function LiveVideo(~,~)

   try
       set(live,'enable','off')
       
       
    imaqreset
    vid = videoinput('winvideo', 1, 'YUY2_352x288');
    vid.ReturnedColorspace = 'rgb';
    set(vid,'framesperTrigger',10,'TriggerRepeat',Inf);
    
        catch ex
            set(live,'enable','on','value',0)
            err=errordlg(ex.message);
            uiwait(err)
            
            return
    end

%A cell of commands for efficient function
num=1;% number of commands
command=cell(num);
[rmin,rmax,gmin,gmax,bmin,bmax]= check_slider; 
 

%% Check what the user chose to build the commands,
%     of the function depending on the user's selection.


% check for  noise
if get(noise,'value')==1
   
%check how much noice to reduce    
     pixsel=get(pixsel_noise,'string');
% check if the string is anumber
   if isnumeric(str2double(pixsel))==1   
    command(num)={'bwareaopen'};
    im(num).prop=str2double(pixsel);
    num=num+1;
   elseif isnumeric(str2double(pixsel))==0   
       set(noise,'value',0);
   end
end

% check for clear border
  if get(clear_border,'value')==1
            content= get(chos_clear,'string');
            command(num)=   {'imclearborder'};
            im(num).prop=str2double(content(get(chos_clear,'value')));

            num=num+1;
  end

% check for imfill

  if get(fill,'value')==1
     content= get(chofill,'string');
     
            command(num)=  {'imfill'};
            im(num).prop=char((content(get(chofill,'value'))));
          
  end
  
  %% Manipulation
  % dilate or erode
   if get(dilate,'value')==1

     
            command(num)=  {'imdilate'};
            content=get(chos_dilate,'string');
            shape=char(content(get(chos_dilate,'value')));
            [se]=strel_shape(shape,dpar1,dpar2,dpar3) ;
            im(num).prop=se;
            
            num=num+1;
            
            
   elseif  get(erod,'value')==1

     
            command(num)=  {'imerode'};
            content=get(chos_erod,'string');
            shape=char(content(get(chos_erod,'value')));
            [se]=strel_shape(shape,epar1,epar2,epar3) ;
            im(num).prop=se;
            num=num+1;
            
   end
  
   
   %imopen or imclose
   
      if get(open,'value')==1

     
            command(num)=  {'imopen'};
            shape=char(content(get(chos_open,'value')));
            [se]=strel_shape(shape,opar1,opar2,opar3) ;
            im(num).prop=se;
            
            num=num+1;
            
            
   elseif  get(clos,'value')==1

     
            command(num)=  {'imclose'};
            shape=char(content(get(chos_close,'value')));
            [se]=strel_shape(shape,cpar1,cpar2,cpar3) ;
            im(num).prop=se;
            num=num+1;
            
      end
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
  
  if isempty(command)==0
  com=cellfun(@str2func,command,'UniformOutput', false);
 % if ther is no functoin selected
  elseif   isempty(command)==1
      com=command;
  end

  try
  
  RunCommand
  set(live,'enable','on')
  % in the case one or two function dont work
  catch err
      
       imaqreset
       erro=errordlg(err.message);
       uiwait(erro)
       set(live,'enable','on')
  end
%% Move the cell Command function that runs commands
    function RunCommand(~,~)
if islogging(vid)==0
    start(vid)    
elseif islogging(vid)==1
    stop(vid)
    pause(1)
    start(vid)
end
   while islogging(vid)
       tic
    rgbimage=getdata(vid,1);
    flushdata(vid);
    %% splite the image to RGB frames
     r=rgbimage(:,:,1);
     g=rgbimage(:,:,2);
     b=rgbimage(:,:,3);
    %% Creat mask filter to rgbimage
   [Rfilter] =FilterRGB(r,rmin,rmax);
   [Gfilter] =FilterRGB(g,gmin,gmax);
   [Bfilter] =FilterRGB(b,bmin,bmax);
      rgbfilter=Rfilter.*Gfilter.*Bfilter;
%% applay the functions on the rgbfilter to creat mask
mask=rgbfilter;

for c=1:length(com)
    
    if isempty(com)==1
        break
    end
            mask=com{c}(mask,im(c).prop);
end
%% dress amask on the image
      rgbface=uint8(mask);
      facefilter=rgbimage;
      facefilter(:,:,1)=rgbimage(:,:,1).*rgbface;
      facefilter(:,:,2)=rgbimage(:,:,2).*rgbface;
      facefilter(:,:,3)=rgbimage(:,:,3).*rgbface;
     figure(gcf)
    
      hold off
      imshow(facefilter,'parent',ax)
  end              
    end
end
function [se]=strel_shape(shape,var1,var2,var3)  
        switch shape
           
            case 'ball'
                
                R=str2double(get(var1,'string'));
                H=str2double(get(var2,'string'));
                N=str2double(get(var3,'string'));
                se = strel('ball', R, H, N);
               
                
            case 'diamond'
                
                R=str2double(get(var1,'string'));
                se=strel('diamond',R);
                
            case 'disk'
                
                R= str2double(get(var1,'string'));
                N= str2double(get(var2,'string')); 
                se=strel('disk',R,N);
                
                
            case 'line' 
                
                LEN=str2double(get(var1,'string'));
                DEG=str2double(get(var1,'string'));
                se = strel('line', LEN, DEG);
                
            case 'octagon'
                
                R=str2double(get(var1,'string'));
                se = strel('octagon', 3*R);
                
            case 'pair'
                
                halfwidth= str2double(get(var1,'string'));
                halfhigth= str2double(get(var2,'string'));
                OFFSET=[halfwidth halfhigth];
                se= strel('pair', OFFSET) ;
                
            case 'perodicline'
                
                P=str2double(get(var1,'string'));
                v1=str2double(get(var2,'string'));
                v2=str2double(get(var3,'string'));
                V=[v1 v2];
               se= strel('periodicline', P, V);
                
            case 'rectangle'
                width= str2double(get(var1,'string'));
                higth= str2double(get(var2,'string'));
                wh=[width higth];
                se=strel('rectangle',wh);
                
            case 'square'
                par1= str2double(get(var1,'string'));
                se=strel('square',par1);
                
            otherwise
                se=0;    
                
        end
 
end
function []= SizeFilter(imagefilter,~,~)
        
        
        
        
end
function [rmin,rmax,gmin,gmax,bmin,bmax]= check_slider(~,~,~)
        % red slider
        min=fix(get(Rmin,'value'));
        max=fix(get(Rmax,'value'));
if min>max
   smaller=max;
   rmax=min;
   rmin=smaller;
elseif min<=max
    rmin=min;
    rmax=max;
end
        % green slider
        min=fix(get(Gmin,'value'));
        max=fix(get(Gmax,'value'));
if min>max
   smaller=max;
   gmax=min;
   gmin=smaller;
elseif min<=max
    gmin=min;
    gmax=max;
end
        % blue slider
        min=fix(get(Bmin,'value'));
        max=fix(get(Bmax,'value'));
if min>max
   smaller=max;
   bmax=min;
   bmin=smaller;
elseif min<=max
    bmin=min;
    bmax=max;
end   
    end
function pause_video(~,~,~)
        imaqreset
        set(live,'enable','on')
        return
end
function Object_Size(~,~)
     
       %Check my choice was
       bigger=str2double(get(Bigger,'string'));
       smaller=str2double(get(Smaller,'string'));
       %Check whether the numerical values ??obtained
       if isnumeric(bigger)==1&&isnumeric(smaller)==1
       elseif isnumeric(bigger)==0&&isnumeric(smaller)==1
           
           bigger=0;
           
       elseif isnumeric(bigger)==1&&isnumeric(smaller)==0
           
           smaller=1000000;
       else
           return
       end
       
       %check the image object area
         imglogic=getimage(ax);
        imglogic=logical( imglogic);
       % 
        W=regionprops( imglogic, 'Area');
        cc = bwconncomp( imglogic, 26);
        %Check whether there is an image tripled
        if isempty(find( imglogic, 1))==0
        
%Size of the desired object space
word  = false(size( imglogic));
 for n=1:cc.NumObjects
allowed=W(n).Area<smaller&&W(n).Area>bigger;
word(cc.PixelIdxList{n}) = allowed;
hold on; 
imshow(word,'parent',ax)
 
 end
        end
    end
function getout(~,~,~)
       
        imaqreset
       delete(fig)
       pause(1)
       delete(fig)  
    end
function About(~,~,~)
% Setting the time component
t=timer;
set(t,'executionmode','fixedrate','Period',0.05,'TasksToExecute',120);
set(t,'timerfcn',@StartTimer);
start(t);
tic
function StartTimer(~,~,~)
  cla(ax2)
text(0.35 ,toc/10,{'        created by:';...
                          '     oren berkovich';...
                         'email: orenber@hotmail.com';...
                         '';'';'';'';'';'';
                         '         2013                '},...
                     'color',[1 1 1],'fonts',20,'fontn','freestyle script','parent',ax2)
end
end
function streltext(prop,~,~)
        
 chos=get(prop,'string');
 chose= char(chos(get(prop,'value')));
 
 % Position
 pos1=get(prop,'position');
 
 px1=pos1(1)+0.34;
 px2=pos1(1)+0.45;
 px3=pos1(1)+0.55;
 py1=pos1(2)+0.07;
 
cla(ax1)
 
  switch chose
     
      case 'ball'
          
          text(px1,py1,'R','parent',ax1)
          text(px2,py1,'H','parent',ax1)
          text(px3,py1,'N','parent',ax1)
          
         text(0.1,0.54,{'R- radius';'H- height';'N- even nonnegative'},'parent',ax1)
         
          
      case 'diamond'
          
          text(px1,py1,'R','parent',ax1)
         
          
           text(0.1,0.54,{'R- radius'},'parent',ax1)
          
      case 'disk'
          
          text(px1,py1, 'R','parent',ax1)
          text(px2,py1, 'N','parent',ax1)
          
                text(0.1,0.54,{'R- radius';'N =0,4,6,8'},'parent',ax1)
          
      case 'line'
          
          text(px1,py1, 'LEN','fonts',8,'parent',ax1)
          text(px2,py1, 'DEG','fonts',8,'parent',ax1)
          
                text(0.1,0.54,{'LEN - length';'DEG -angle (in degrees)'},'parent',ax1)
          
      case 'octagon'
          
           text(px1,py1, 'R','parent',ax1)
               text(0.1,0.54,{'R- radius'},'parent',ax1)
           
           
      case 'pair'
          
          text(px1,py1, 'O','parent',ax1)
          text(px2,py1, 'R','parent',ax1)
          
         text(0.1,0.54,{ 'OFFSET -must be a two';'element vector of integers'},'parent',ax1)
          
             
      case 'perodicline'
          
          text(px1,py1, 'P','parent',ax1)
          text(px2,py1, 'V','parent',ax1)
          
          
      case 'rectangle'
          
          text(px1,py1, 'C','parent',ax1)
          text(px2,py1, 'R','parent',ax1)
          
         text(0.1,0.54,{ 'C -number of columns';'R -number of rows'},'parent',ax1)
                    
      case  'square'
          
          text(px1,py1, 'W','parent',ax1)
          text(0.1,0.54,{ 'W -width'},'parent',ax1)
  
  end
          
        
end
end

Contact us