A list,

GUI image Filter based on MATLAB (Mosaic + Blue lens + sketch)

Ii. Source code

% 
%2021/07/21
function varargout = filter_pic(varargin)
% FILTER_PIC MATLAB code for filter_pic.fig
%      FILTER_PIC, by itself, creates a new FILTER_PIC or raises the existing
%      singleton*.
%
%      H = FILTER_PIC returns the handle to a new FILTER_PIC or the handle to
%      the existing singleton*.
%
%      FILTER_PIC('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FILTER_PIC.M with the given input arguments.
%
%      FILTER_PIC('Property'.'Value',...). creates anew FILTER_PIC or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before filter_pic_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to filter_pic_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help filter_pic

% Last Modified by GUIDE v2. 5 21-Jun- 2021. 11:37:31

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @filter_pic_OpeningFcn, ...
                   'gui_OutputFcn',  @filter_pic_OutputFcn, ...
                   'gui_LayoutFcn', [],...'gui_Callback'[]);if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});xw
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before filter_pic is made visible.
function filter_pic_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to filter_pic (see VARARGIN)

% Choose default command line output for filter_pic
handles.output = hObject;

global begin_down begin_start openflag ;
begin_down=0;
begin_start=0;
openflag=0;
set(handles.axes2,'visible'.'off');
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes filter_pic wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = filter_pic_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Open.
function Open_Callback(hObject, eventdata, handles)
% hObject    handle to Open (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 
global  openflag begin_start;
[filename,pathname]=uigetfile({'*.bmp; *.jpg; *.gif'.'(*.bmp; *.jpg; *.gif)';'*.bmp'.'(*.bmp)';'*.jpg'.'(*.jpg)';'*.gif'.'(*.gif)'; },'Open picture');
if isequal(filename,0)||isequal(pathname,0)
  return;
else
openflag=1;
begin_start=0;
RGB=imread([pathname,filename]);
RGB = imresize(RGB, [352 500]); % adjust image size clA (handles. Axes1); axes(handles.axes1); imshow(RGB); handles.image=RGB; guidata(hObject,handles); end % --- Executes on button press in Start.function Start_Callback(hObject, eventdata, handles)
% hObject    handle to Start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global begin_start openflag ;

if   openflag ;
begin_start=1;
handles.begin_point=get(gca,'currentpoint'); Handles. Axes1_point =get(handles. Axes1,'Position'); Guidata (hObject,handles);else
    errordlg('Please Open a File');
end
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global begin_down begin_start;
pt_begine = get(hObject,'CurrentPoint'); %disp(pt_begine(1.1));
if     begin_start...     
       &&pt_begine(1.1)>handles.axes1_point(1)...
       && pt_begine(1.2)>handles.axes1_point(2)... && pt_begine(1.1)<handles.axes1_point(1)+ handles.axes1_point(3)...
       && pt_begine(1.2)<handles.axes1_point(2)+handles.axes1_point(4)
      %disp(pt_begine(1.1));
    begin_down=1;
    
%      %set(handles.axes2,'visible',on);
%      RGB=handles.image;
%      y0=pt_begine(1.2);
%      x0=pt_begine(1.1);
%      x0_width=100;
%      y0_height=100;
%      %RGB_filter=imcrop(RGB,[x0-handles.axes1_point(1) y0-handles.axes1_point(2) x0_width y0_height]);
%      %RGB_filter=imcrop(RGB,[x0-handles.axes1_point(1) handles.axes1_point(4)-(y0-handles.axes1_point(2)) x0_width y0_height]);
%      RGB_filter=imcrop(RGB,[(x0-x0_width-handles.axes1_point(1))  handles.axes1_point(4)-( y0+y0_height-handles.axes1_point(2))  x0_width y0_height]);
% %      Gray=rgb2gray(RGB_filter);
% %       R=RGB_filter(:,:,1); G=RGB_filter(:,:,2); B=RGB_filter(:,:,3);
% %      diff_R=20; diff_G=0; diff_B=0; % Set the red, green, and blue color extraction threshold (the larger the threshold, the more stringent) % % % % Image_B=RGB_filter; % % BP_R=RGB_filter(:,:,1); BP_G=RGB_filter(:,:,2); BP_B=RGB_filter(:,:,3); % % XYB=~((B-R)>diff_B&(B-G)>diff_B); % Mask_B=Gray(XYB); % Mask_B=Gray(XYB); % gray photo mask % % BP_R(XYB)=Mask_B; BP_G(XYB)=Mask_B; BP_B(XYB)=Mask_B; % % Image_B(:,:,1)=BP_R; Image_B(:,:,2)=BP_G; Image_B(:,:,3)=BP_B; 
%     RGB_filter(:,:,1) =0; 
%     cla(handles.axes2);
%     %set(handles.axes2,'Position',[x0 y0-y0_height x0_width y0_height]);
%     set(handles.axes2,'Position',[x0-x0_width y0 x0_width y0_height]);
%     axes(handles.axes2);
%     imshow(RGB_filter);
% %     set(handles.axes2,'Position'[1 1 30 30]);
%     guidata(hObject,handles); 
    
else
    begin_down=0;
end

% --- Executes on mouse motion over figure - except title and menu.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global begin_down;

if begin_down
    pt_process  = get(hObject,'CurrentPoint'); % obtain the coordinates of the current point RGB=handles.image; x0=pt_process(1.1);
    y0=pt_process(1.2);
    x0_width=100;
    y0_height=100;
    if x0<handles.axes1_point(1)+x0_width
        x0=handles.axes1_point(1)+x0_width;
    else if x0>handles.axes1_point(1)+handles.axes1_point(3)
            x0=handles.axes1_point(1)+handles.axes1_point(3);
        end
    end
    if y0<handles.axes1_point(2)
        y0=handles.axes1_point(2);
    else if y0>handles.axes1_point(2)+handles.axes1_point(4)-y0_height;
             y0=handles.axes1_point(2)+handles.axes1_point(4)-y0_height;
        end
    end
   
     %set(handles.axes2,'visible',off); 
     %RGB_filter=imcrop(RGB,[x0-handles.axes1_point(1) y0-handles.axes1_point(2) x0_width y0_height]);
     %RGB_filter=imcrop(RGB,[x0-handles.axes1_point(1) handles.axes1_point(4)-(y0-handles.axes1_point(2)) x0_width y0_height]);
     set(handles.axes2,'visible'.'on');
     RGB_filter=imcrop(RGB,[(x0-x0_width-handles.axes1_point(1))  handles.axes1_point(4)-( y0+y0_height-handles.axes1_point(2)) x0_width y0_height]); Maflag =get(handles. Ma_radiobutton,'Value' );
     blueflag=get( handles.blue_radiobutton,'Value');
     writeflag=get( handles.write_radiobutton,'Value');
     if maflag
     pix_grp = 10;
     height = size(RGB_filter,1);
     width = size(RGB_filter,2);
     mosaic = imresize(RGB_filter,[floor(height/pix_grp) floor(width/pix_grp)]);   
     RGB_filter = imresize(mosaic,[height width],'nearest');
     else if writeflag
        size_info=size(RGB_filter);
        height=size_info(1);
        width=size_info(2);
        spec_img=zeros(height,width,3);
        %img_temp=rgb2gray(RGB_filter);

        for i=2:height- 1
            for j=2:width- 1
                spec_img(i,j,:)=double(RGB_filter(i- 1,j- 1, :))double(RGB_filter(i+1,j+1, :)) +128;
            end
        end
        RGB_filter= spec_img/255;
        else blueflag;
                  RGB_filter(:,:,1) =0;
        end
Copy the code

Third, the operation result

Fourth, note

Version: 2014 a