classdef WORK_App1 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        figure1         matlab.ui.Figure
        pushbutton35    matlab.ui.control.Button
        pushbutton34    matlab.ui.control.Button
        uipanel2        matlab.ui.container.Panel
        s3              matlab.ui.control.Button
        s2              matlab.ui.control.Button
        s1              matlab.ui.control.Button
        uipanel1        matlab.ui.container.Panel
        DropDown        matlab.ui.control.DropDown
        DropDownLabel   matlab.ui.control.Label
        a3              matlab.ui.control.Button
        a2              matlab.ui.control.Button
        a1              matlab.ui.control.Button
        text10          matlab.ui.control.Label
        uibuttongroup6  matlab.ui.container.ButtonGroup
        text9           matlab.ui.control.Label
        slider5         matlab.ui.control.Slider
        text8           matlab.ui.control.Label
        text7           matlab.ui.control.Label
        text6           matlab.ui.control.Label
        slider4         matlab.ui.control.Slider
        slider3         matlab.ui.control.Slider
        slider2         matlab.ui.control.Slider
        text5           matlab.ui.control.Label
        slider1         matlab.ui.control.Slider
        uibuttongroup5  matlab.ui.container.ButtonGroup
        b3              matlab.ui.control.Button
        b2              matlab.ui.control.Button
        b1              matlab.ui.control.Button
        uibuttongroup4  matlab.ui.container.ButtonGroup
        m5              matlab.ui.control.Button
        m4              matlab.ui.control.Button
        m3              matlab.ui.control.Button
        m2              matlab.ui.control.Button
        m1              matlab.ui.control.Button
        uibuttongroup3  matlab.ui.container.ButtonGroup
        m10             matlab.ui.control.Button
        m9              matlab.ui.control.Button
        m8              matlab.ui.control.Button
        uibuttongroup2  matlab.ui.container.ButtonGroup
        f3              matlab.ui.control.Button
        f1              matlab.ui.control.Button
        f2              matlab.ui.control.Button
        text3           matlab.ui.control.Label
        text2           matlab.ui.control.Label
        reset           matlab.ui.control.Button
        save            matlab.ui.control.Button
        exit            matlab.ui.control.Button
        load            matlab.ui.control.Button
        g2              matlab.ui.control.UIAxes
        g1              matlab.ui.control.UIAxes
        ContextMenu     matlab.ui.container.ContextMenu
        Menu            matlab.ui.container.Menu
        Menu2           matlab.ui.container.Menu
    end

    
    methods (Access = private)
        function rgb = hsi2rgb(app, hsi)
            % HSI 到 RGB 的转换函数
            
                H = hsi(:,:,1) * 2 * pi;
                S = hsi(:,:,2);
                I = hsi(:,:,3);
            
                R = zeros(size(H));
                G = zeros(size(H));
                B = zeros(size(H));
            
                % RG sector (0 <= H < 2*pi/3)
                idx = (H < 2*pi/3);
                B(idx) = I(idx) .* (1 - S(idx));
                R(idx) = I(idx) .* (1 + S(idx) .* cos(H(idx)) ./ cos(pi/3 - H(idx)));
                G(idx) = 3*I(idx) - (R(idx) + B(idx));
            
                % GB sector (2*pi/3 <= H < 4*pi/3)
                idx = (2*pi/3 <= H) & (H < 4*pi/3);
                H(idx) = H(idx) - 2*pi/3;
                R(idx) = I(idx) .* (1 - S(idx));
                G(idx) = I(idx) .* (1 + S(idx) .* cos(H(idx)) ./ cos(pi/3 - H(idx)));
                B(idx) = 3*I(idx) - (R(idx) + G(idx));
            
                % BR sector (4*pi/3 <= H < 2*pi)
                idx = (4*pi/3 <= H) & (H < 2*pi);
                H(idx) = H(idx) - 4*pi/3;
                G(idx) = I(idx) .* (1 - S(idx));
                B(idx) = I(idx) .* (1 + S(idx) .* cos(H(idx)) ./ cos(pi/3 - H(idx)));
                R(idx) = 3*I(idx) - (G(idx) + B(idx));
            
                rgb = cat(3, R, G, B);
                rgb = max(min(rgb, 1), 0);
        end
        
        function hsi = rgb2hsi(app, rgb)
            % RGB 到 HSI 的转换函数
            
                rgb = im2double(rgb);
                R = rgb(:,:,1);
                G = rgb(:,:,2);
                B = rgb(:,:,3);
            
                num = 0.5*((R - G) + (R - B));
                den = sqrt((R - G).^2 + (R - B).*(G - B));
                theta = acos(num./(den + eps));
            
                H = theta;
                H(B > G) = 2*pi - H(B > G);
                H = H/(2*pi);
            
                num = min(min(R, G), B);
                den = R + G + B;
                den(den == 0) = eps;
                S = 1 - 3.* num./den;
            
                H(S == 0) = 0;
                I = (R + G + B)/3;
            
                hsi = cat(3, H, S, I);
        end
        
        % function updateg4(app, handles)
        %     %示波器g4彩色图象更新函数
        % 
        %     r=handles.img(:,:,1);
        %     g=handles.img(:,:,2);
        %     b=handles.img(:,:,3);
        %     x=size(r);
        %     x=(1:x(1,2));
        %     r=r(1,:);
        %     g=g(1,:);
        %     b=b(1,:);
        %     axes(handles.g4);
        %     cla;
        %     plot(x,r,'r');
        %     hold on
        %     plot(x,g,'g');
        %     plot(x,b,'b');
        %     hold off;
        % 
        %     ImageData1 = reshape(handles.img(:,:,1), [size(handles.img, 1) * size(handles.img, 2) 1]);
        %     ImageData2 = reshape(handles.img(:,:,2), [size(handles.img, 1) * size(handles.img, 2) 1]);
        %     ImageData3 = reshape(handles.img(:,:,3), [size(handles.img, 1) * size(handles.img, 2) 1]);
        %     [H1, X1] = hist(ImageData1, 1:5:256);
        %     [H2, X2] = hist(ImageData2, 1:5:256);
        %     [H3, X3] = hist(ImageData3, 1:5:256);
        %     axes(handles.g5);
        %     cla;
        %     hold on;
        %     plot(X1, H1, 'r');
        %     plot(X2, H2, 'g');
        %     plot(X3, H3, 'b');
        %     axis([0 256 0 max([H1 H2 H3])]);
        % end
        % 
        % function updateg4_1(app, handles)
        %     %示波器灰色图象更新函数
        % 
        % 
        %     k=handles.img(:,:,1);
        %     x=size(k);
        %     x=(1:x(1,2));
        %     k=k(1,:);
        %     axes(handles.g4);
        %     cla;
        %     plot(x,k,'k');
        % 
        %     ImageData = reshape(handles.img, [size(handles.img, 1) * size(handles.img, 2) 1]);
        %     [H, X] = hist(ImageData, 1:5:256);
        %     axes(handles.g5);
        %     cla;
        %     hold on;
        %     plot(X, H, 'k');
        %     axis([0 256 0 max(H)]);
        % end
        % 
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function WORK_OpeningFcn(app, varargin)
            % --- Executes just before WORK is made visible.
            
            % Ensure that the app appears on screen when run
            movegui(app.figure1, 'onscreen');
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app); %#ok<ASGLU>
            
            % 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 WORK (see VARARGIN)
            % Choose default command line output for WORK
            
            handles.output = hObject;
            
            set(handles.save,'Enable','on');
            set(handles.exit,'Enable','on');
            set(handles.reset,'Enable','on');
            set(handles.g1,'Visible','on');
            set(handles.g2,'Visible','on');
            set(handles.a1,'Enable','on');
            set(handles.a2,'Enable','on');
            set(handles.a3,'Enable','on');
 %           set(handles.a4,'Enable','on');
            set(handles.b1,'Enable','on');
            set(handles.b2,'Enable','on');
            set(handles.b3,'Enable','on');
            set(handles.f1,'Enable','on');
            set(handles.f2,'Enable','on');
            set(handles.f3,'Enable','on');
            set(handles.slider1,'Enable','on');
            set(handles.slider2,'Enable','on');
            set(handles.slider3,'Enable','on');
            set(handles.slider4,'Enable','on');
            set(handles.slider5,'Enable','on');
            set(handles.m1,'Enable','on');
            set(handles.m2,'Enable','on');
            set(handles.m3,'Enable','on');
            set(handles.m4,'Enable','on');
            set(handles.m5,'Enable','on');
            set(handles.m8,'Enable','on');
            set(handles.m9,'Enable','on');
            set(handles.m10,'Enable','on');
            set(handles.s1,'Enable','on');
            set(handles.s2,'Enable','on');
            set(handles.s3,'Enable','on');
            % Update handles structure
            guidata(hObject, handles);
        end

        % Button pushed function: a1
        function a1_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            handles.img=imadjust(handles.img,[0.2 0.5],[0 1]);
            axes(handles.g2); cla; imshow(handles.img);
            guidata(hObject,handles);           
        end

        % Button pushed function: a2
        function a2_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
         %   mysize=size(handles.img);
          %  if numel(mysize)>2
           %     handles.img=rgb2gray(handles.img);
            %end
            
            a = 1.5;
            b = 50;
            handles.img = a * handles.img+ b;
            axes(handles.g2); cla; imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: a3
        function a3_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            
            I=double(handles.img);
            z=ones(15);
            a=fix(15/2)+1;
            b=fix(15/2)+1;
            z(a,b)=1-15*15;
            w=z;
            handles.wq=conv2(I,w,'same');
            axes(handles.g2); cla; imshow(handles.wq);
            guidata(hObject,handles);
            handles.wq=handles.img;
        end

        % Callback function: not associated with a component
        function a4_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
                      
            handles.img=histeq(handles.img);
            axes(handles.g2); cla; imshow(handles.img);
            imhist(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: b1
        function b1_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            [M,N]=graythresh(handles.img);
            handles.img=im2bw(handles.img,M);
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: b2
        function b2_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            I1=handles.img;
            count=0;
            T=mean2(I1);
            done =false;
            while ~done
                count=count+1;
                g=I1>T;
                Tnext=0.5*(mean(I1(g))+mean(I1(~g)));
                done =abs(T-Tnext)<0.5;
                T=Tnext;
            end
            handles.img=im2bw(I1,T/255);
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: b3
        function b3_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
                handles.img = im2double(handles.img);
                if size(handles.img, 3) == 3
                    handles.img = rgb2gray(handles.img);
                end
                se = strel('disk', 10);  % 圆盘形状的结构元素，半径为10
                handles.img = imtophat(handles.img, se);
                handles.img = mat2gray(handles.img);
                handles.img = uint8(255 * handles.img);
                Th = adaptthresh(handles.img, 0.5);
                G = imbinarize(handles.img, Th);
                axes(handles.g2);
                cla;
                imshow(G);
                handles.img = G;
                guidata(hObject, handles);
        end

        % Button pushed function: exit
        function exit_Callback(app, event)
            %退出
            % --- Executes on button press in exit.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            close all;
        end

        % Button pushed function: f1
        function f1_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            h=fspecial('average');
            handles.img=imfilter(handles.img,h,'replicate');
            axes(handles.g2); cla; imshow(handles.img)
            guidata(hObject,handles);
        end

        % Button pushed function: f2
        function f2_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            hsize=[8 8]; sigma=1.7;
            h=fspecial('gaussian',hsize,sigma);
            handles.img=imfilter(handles.img,h,'replicate');
            axes(handles.g2); cla; imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: f3
        function f3_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            r=medfilt2(handles.img(:,:,1));
            g=medfilt2(handles.img(:,:,2));
            b=medfilt2(handles.img(:,:,3));
            handles.img=cat(3,r,g,b);
            axes(handles.g2); cla; imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: load
        function load_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            [file path]=uigetfile({'*.jpg';'*.bmp';'*.jpeg';'*.png';'*.tiff';'*.tif'}, '打开文件');
            image=[path file];
            handles.file=image;
            if (file==0)
                warndlg('请选择一张图片...') ;
            end
            [fpath, fname, fext]=fileparts(file);
            validex=({'.bmp','.jpg','.jpeg','.png','.tiff','.tif'});
            found=0;
            for (x=1:length(validex))
               if (strcmpi(fext,validex{x}))
                   found=1;
            
            set(handles.save,'Enable','on');
            set(handles.exit,'Enable','on');
            set(handles.reset,'Enable','on');
            set(handles.g1,'Visible','on');
            set(handles.g2,'Visible','on');
            set(handles.a1,'Enable','on');
            set(handles.a2,'Enable','on');
            set(handles.a3,'Enable','on');
            %set(handles.a4,'Enable','on');
            set(handles.b1,'Enable','on');
            set(handles.b2,'Enable','on');
            set(handles.b3,'Enable','on');
            set(handles.f1,'Enable','on');
            set(handles.f2,'Enable','on');
            set(handles.f3,'Enable','on');
            set(handles.slider1,'Enable','on');
            set(handles.slider2,'Enable','on');
            set(handles.slider3,'Enable','on');
            set(handles.slider4,'Enable','on');
            set(handles.slider5,'Enable','on');
            set(handles.m1,'Enable','on');
            set(handles.m2,'Enable','on');
            set(handles.m3,'Enable','on');
            set(handles.m4,'Enable','on');
            set(handles.m5,'Enable','on');
            set(handles.m8,'Enable','on');
            set(handles.m9,'Enable','on');
            set(handles.m10,'Enable','on');
            
            handles.img=imread(image);
            handles.i=imread(image);
            h = waitbar(0,'等待...');
            steps = 100;
            
            for step = 1:steps
                waitbar(step / steps)
            end
            close(h)
            axes(handles.g1);
            cla;
            imshow(handles.img);
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
            break;
            end
            end
            if (found==0)
                 errordlg('文件扩展名不正确，请从可用扩展名[.jpg、.jpeg、.bmp、.png、.tiff、.tif]中选择文件','Image Format Error');
            end
            

            
           
        end

        % Button pushed function: m10
        function m10_Callback(app, event)
            %灰度
            % --- Executes on button press in m10.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            handles.img = rgb2gray(handles.img);
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
            % updateg4_1(app, handles);
        end

        % Button pushed function: m1
        function m1_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            handles.img=edge(handles.img,'sobel');
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: m2
        function m2_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            handles.img=edge(handles.img,'roberts');
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: m3
        function m3_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            handles.img=edge(handles.img,'prewitt');
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: m4
        function m4_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            handles.img=edge(handles.img,'log');
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: m5
        function m5_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            mysize=size(handles.img);
            if numel(mysize)>2
                handles.img=rgb2gray(handles.img);
            end
            handles.img=edge(handles.img,'canny');
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: m8
        function m8_Callback(app, event)
            %左右翻转
            % --- Executes on button press in m8.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            handles.img=fliplr(handles.img);
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
            
            mysize=size(handles.img);
            % if numel(mysize)>2
            %     updateg4(app, handles)
            % else
            %     updateg4_1(app, handles)
            % end
        end

        % Button pushed function: m9
        function m9_Callback(app, event)
            %上下翻转
            % --- Executes on button press in m9.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            handles.img=flipud(handles.img);
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
            
            mysize=size(handles.img);
            % if numel(mysize)>2
            %     updateg4(app, handles)
            % else
            %     updateg4_1(app, handles)
            % end
        end

        % Button pushed function: pushbutton34
        function pushbutton34_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            img = handles.img;
            
            if size(img, 3) == 3
                % 将 RGB 图像转换为 HSI 图像
                hsi = rgb2hsi(app, img);
                H = hsi(:,:,1);
                S = hsi(:,:,2);
                I = hsi(:,:,3);
                figure, subplot(1,3,1), imshow(H), title('H分量');
                subplot(1,3,2), imshow(S), title('S分量');
                subplot(1,3,3), imshow(I), title('I分量');
            
                I_eq = histeq(I);
                hsi_enhanced = hsi;
                hsi_enhanced(:,:,3) = I_eq;
                % 将增强后的 HSI 图像转换回 RGB
                rgb_enhanced = hsi2rgb(app,hsi_enhanced);
                axes(handles.g2);cla;imshow(rgb_enhanced);
               %figure, imshow(rgb_enhanced), title('增强后的RGB图像');
            else
                msgbox('请先选择一个彩色图像。', '错误', 'error');
            end
            guidata(hObject, handles);
        end

        % Button pushed function: pushbutton35
        function pushbutton35_Callback(app, event)
            % --- Executes on button press in pushbutton35.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            % hObject    handle to pushbutton35 (see GCBO)
            % eventdata  reserved - to be defined in a future version of MATLAB
            % handles    structure with handles and user data (see GUIDATA)
                axes_handle = handles.img;
            
                histogram(axes_handle);
        end

        % Button pushed function: reset
        function reset_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            handles.img=handles.i;
            axes(handles.g2);
            cla;
            imshow(handles.img);
            % updateg4(app, handles);
            guidata(hObject,handles);
        end

        % Button pushed function: s1
        function s1_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            h = waitbar(0,'等待...');
            steps = 200;
            for step = 1:steps
                waitbar(step / steps)
            end
            close(h)
            handles.img = imnoise(handles.img,'salt & pepper',0.02);
            axes(handles.g2); cla; imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: s2
        function s2_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            h = waitbar(0,'等待...');
            steps = 200;
            for step = 1:steps
                waitbar(step / steps)
            end
            close(h)
            handles.img = imnoise(handles.img,'gaussian');
            axes(handles.g2);
            cla;
            imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: s3
        function s3_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            h = waitbar(0,'等待...');
            steps = 200;
            for step = 1:steps
                waitbar(step / steps)
            end
            close(h)
            handles.img = imnoise(handles.img,'poisson');
                axes(handles.g2); cla; imshow(handles.img);
            guidata(hObject,handles);
        end

        % Button pushed function: save
        function save_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            [file path]= uiputfile('*.jpg','Save Image as');
            save=[path file]; imwrite(handles.img,save,'jpg');
        end

        % Value changed function: slider1
        function slider1_Callback(app, event)
            %旋转
            % --- Executes on slider movement.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            rrv=(get(hObject,'Value'));
            handles.rot=handles.img;
            handles.rot=imrotate(handles.rot,rrv);
            axes(handles.g2); cla; imshow(handles.rot);
            guidata(hObject,handles)
        end

        % Value changed function: slider2
        function slider2_Callback(app, event)
            %R滑动条
            % --- Executes on slider movement.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            % hObject    handle to slider2 (see GCBO)
            % eventdata  reserved - to be defined in a future version of MATLAB
            % handles    structure with handles and user data (see GUIDATA)
            x=get(hObject,'Value');
            r=handles.img(:,:,1);
            g=handles.img(:,:,2);
            b=handles.img(:,:,3);
            r1=r+x;
            rcon=cat(3,r1,g,b);
            axes(handles.g2);
            cla;
            imshow(rcon)
            handles.img=rcon;
            r=handles.img(:,:,1);
            g=handles.img(:,:,2);
            b=handles.img(:,:,3);
            x=size(r);
            x=(1:x(1,2));
            r=r(1,:);
            g=g(1,:);
            b=b(1,:);
            %axes(handles.g4);
           % plot(x,r,'r');
           % hold on
           % plot(x,g,'g');
           % plot(x,b,'b');
           % hold off;
        end

        % Value changed function: slider3
        function slider3_Callback(app, event)
            %G滑动条
            % --- Executes on slider movement.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            x=get(hObject,'Value');
            r=handles.img(:,:,1);
            g=handles.img(:,:,2); b=handles.img(:,:,3);
            g1=g+x; gcon=cat(3,r,g1,b);
            axes(handles.g2); cla; imshow(gcon)
            handles.img=gcon;
            
            % updateg4(app, handles)
        end

        % Value changed function: slider4
        function slider4_Callback(app, event)
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>

            x=get(hObject,'Value');
            r=handles.img(:,:,1);
            g=handles.img(:,:,2); b=handles.img(:,:,3);
            b1=b+x; bcon=cat(3,r,g,b1);
            axes(handles.g2); cla; imshow(bcon)
            handles.img=bcon;
        end

        % Value changed function: slider5
        function slider5_Callback(app, event)
            %亮度滑动条
            % --- Executes on slider movement.
            
            % Create GUIDE-style callback args - Added by Migration Tool
            [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
            
            
            x=get(hObject,'Value');
            img=handles.img;
            img=img+x;
            axes(handles.g2); cla; imshow(img)
            handles.img=img;
            % updateg4(app, handles)
        end

        % Value changed function: DropDown
        function DropDownValueChanged(app, event)
            value = app.DropDown.Value;
            switch value
                case '图像'
                    [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event);
                    handles.img=histeq(handles.img);
                    axes(handles.g2); cla; imshow(handles.img);
                    guidata(hObject,handles);
                case '直方图'
                    [hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event);
                    handles.img=histeq(handles.img);
                    axes(handles.g2); cla; 
                    imhist(handles.img);
                    guidata(hObject,handles);
            end
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create figure1 and hide until all components are created
            app.figure1 = uifigure('Visible', 'off');
            app.figure1.Position = [680 356 925 742];
            app.figure1.Name = 'WORK';
            app.figure1.Resize = 'off';
            app.figure1.HandleVisibility = 'callback';
            app.figure1.Tag = 'figure1';

            % Create g1
            app.g1 = uiaxes(app.figure1);
            app.g1.FontSize = 12;
            app.g1.NextPlot = 'replace';
            app.g1.Tag = 'g1';
            app.g1.Position = [65 309 216 236];

            % Create g2
            app.g2 = uiaxes(app.figure1);
            app.g2.FontSize = 12;
            app.g2.NextPlot = 'replace';
            app.g2.Tag = 'g2';
            app.g2.Position = [271 309 217 236];

            % Create load
            app.load = uibutton(app.figure1, 'push');
            app.load.ButtonPushedFcn = createCallbackFcn(app, @load_Callback, true);
            app.load.Tag = 'load';
            app.load.FontSize = 20;
            app.load.Position = [9.125 499.333333333333 60 39];
            app.load.Text = '打开';

            % Create exit
            app.exit = uibutton(app.figure1, 'push');
            app.exit.ButtonPushedFcn = createCallbackFcn(app, @exit_Callback, true);
            app.exit.Tag = 'exit';
            app.exit.FontSize = 20;
            app.exit.Position = [10.375 450.428571428571 60 39];
            app.exit.Text = '退出';

            % Create save
            app.save = uibutton(app.figure1, 'push');
            app.save.ButtonPushedFcn = createCallbackFcn(app, @save_Callback, true);
            app.save.Tag = 'save';
            app.save.FontSize = 20;
            app.save.Position = [10.375 398.428571428571 60 39];
            app.save.Text = '保存';

            % Create reset
            app.reset = uibutton(app.figure1, 'push');
            app.reset.ButtonPushedFcn = createCallbackFcn(app, @reset_Callback, true);
            app.reset.Tag = 'reset';
            app.reset.FontSize = 20;
            app.reset.Position = [11.625 340.238095238095 60 39];
            app.reset.Text = '清除';

            % Create text2
            app.text2 = uilabel(app.figure1);
            app.text2.Tag = 'text2';
            app.text2.HorizontalAlignment = 'center';
            app.text2.VerticalAlignment = 'top';
            app.text2.WordWrap = 'on';
            app.text2.FontSize = 26.6666666666667;
            app.text2.FontColor = [0.0745098039215686 0.623529411764706 1];
            app.text2.Position = [100 541 135 33];
            app.text2.Text = '原始图片';

            % Create text3
            app.text3 = uilabel(app.figure1);
            app.text3.Tag = 'text3';
            app.text3.HorizontalAlignment = 'center';
            app.text3.VerticalAlignment = 'top';
            app.text3.WordWrap = 'on';
            app.text3.FontSize = 26.6666666666667;
            app.text3.FontColor = [0.0745098039215686 0.623529411764706 1];
            app.text3.Position = [325 541 164 35];
            app.text3.Text = '效果预览';

            % Create uibuttongroup2
            app.uibuttongroup2 = uibuttongroup(app.figure1);
            app.uibuttongroup2.Title = '空间滤波器/去噪';
            app.uibuttongroup2.Tag = 'uibuttongroup2';
            app.uibuttongroup2.FontSize = 16;
            app.uibuttongroup2.Position = [363 141 125 156];

            % Create f2
            app.f2 = uibutton(app.uibuttongroup2, 'push');
            app.f2.ButtonPushedFcn = createCallbackFcn(app, @f2_Callback, true);
            app.f2.Tag = 'f2';
            app.f2.FontSize = 16;
            app.f2.Position = [25 57 80 26];
            app.f2.Text = '高斯滤波';

            % Create f1
            app.f1 = uibutton(app.uibuttongroup2, 'push');
            app.f1.ButtonPushedFcn = createCallbackFcn(app, @f1_Callback, true);
            app.f1.Tag = 'f1';
            app.f1.FontSize = 16;
            app.f1.Position = [25 97 80 26];
            app.f1.Text = '均值滤波';

            % Create f3
            app.f3 = uibutton(app.uibuttongroup2, 'push');
            app.f3.ButtonPushedFcn = createCallbackFcn(app, @f3_Callback, true);
            app.f3.Tag = 'f3';
            app.f3.FontSize = 16;
            app.f3.Position = [25 16 80 26];
            app.f3.Text = '中值滤波';

            % Create uibuttongroup3
            app.uibuttongroup3 = uibuttongroup(app.figure1);
            app.uibuttongroup3.Title = '基础功能';
            app.uibuttongroup3.Tag = 'uibuttongroup3';
            app.uibuttongroup3.FontSize = 16;
            app.uibuttongroup3.Position = [240 141 110 156];

            % Create m8
            app.m8 = uibutton(app.uibuttongroup3, 'push');
            app.m8.ButtonPushedFcn = createCallbackFcn(app, @m8_Callback, true);
            app.m8.Tag = 'm8';
            app.m8.FontSize = 16;
            app.m8.Position = [15 99 80 26];
            app.m8.Text = '左右翻转';

            % Create m9
            app.m9 = uibutton(app.uibuttongroup3, 'push');
            app.m9.ButtonPushedFcn = createCallbackFcn(app, @m9_Callback, true);
            app.m9.Tag = 'm9';
            app.m9.FontSize = 16;
            app.m9.Position = [15 59 80 26];
            app.m9.Text = '上下翻转';

            % Create m10
            app.m10 = uibutton(app.uibuttongroup3, 'push');
            app.m10.ButtonPushedFcn = createCallbackFcn(app, @m10_Callback, true);
            app.m10.Tag = 'm10';
            app.m10.FontSize = 16;
            app.m10.Position = [15 18 80 26];
            app.m10.Text = '灰度';

            % Create uibuttongroup4
            app.uibuttongroup4 = uibuttongroup(app.figure1);
            app.uibuttongroup4.Title = '边缘检测';
            app.uibuttongroup4.Tag = 'uibuttongroup4';
            app.uibuttongroup4.FontSize = 16;
            app.uibuttongroup4.Position = [742 348 125 209];

            % Create m1
            app.m1 = uibutton(app.uibuttongroup4, 'push');
            app.m1.ButtonPushedFcn = createCallbackFcn(app, @m1_Callback, true);
            app.m1.Tag = 'm1';
            app.m1.FontSize = 16;
            app.m1.Position = [22 156 80 26];
            app.m1.Text = 'Sobel';

            % Create m2
            app.m2 = uibutton(app.uibuttongroup4, 'push');
            app.m2.ButtonPushedFcn = createCallbackFcn(app, @m2_Callback, true);
            app.m2.Tag = 'm2';
            app.m2.FontSize = 16;
            app.m2.Position = [22 122 80 26];
            app.m2.Text = 'Roberts';

            % Create m3
            app.m3 = uibutton(app.uibuttongroup4, 'push');
            app.m3.ButtonPushedFcn = createCallbackFcn(app, @m3_Callback, true);
            app.m3.Tag = 'm3';
            app.m3.FontSize = 16;
            app.m3.Position = [22 87 80 26];
            app.m3.Text = 'Prewitt';

            % Create m4
            app.m4 = uibutton(app.uibuttongroup4, 'push');
            app.m4.ButtonPushedFcn = createCallbackFcn(app, @m4_Callback, true);
            app.m4.Tag = 'm4';
            app.m4.FontSize = 16;
            app.m4.Position = [22 52 80 26];
            app.m4.Text = 'LOG';

            % Create m5
            app.m5 = uibutton(app.uibuttongroup4, 'push');
            app.m5.ButtonPushedFcn = createCallbackFcn(app, @m5_Callback, true);
            app.m5.Tag = 'm5';
            app.m5.FontSize = 16;
            app.m5.Position = [22 18 80 26];
            app.m5.Text = 'Canny';

            % Create uibuttongroup5
            app.uibuttongroup5 = uibuttongroup(app.figure1);
            app.uibuttongroup5.Title = '图像分割';
            app.uibuttongroup5.Tag = 'uibuttongroup5';
            app.uibuttongroup5.FontSize = 16;
            app.uibuttongroup5.Position = [742 195 124 137];

            % Create b1
            app.b1 = uibutton(app.uibuttongroup5, 'push');
            app.b1.ButtonPushedFcn = createCallbackFcn(app, @b1_Callback, true);
            app.b1.Tag = 'b1';
            app.b1.FontSize = 13.3333333333333;
            app.b1.Position = [11 79 101.875 19.8095238095238];
            app.b1.Text = 'ostu算法';

            % Create b2
            app.b2 = uibutton(app.uibuttongroup5, 'push');
            app.b2.ButtonPushedFcn = createCallbackFcn(app, @b2_Callback, true);
            app.b2.Tag = 'b2';
            app.b2.FontSize = 13.3333333333333;
            app.b2.Position = [10 51 103.125 19.8095238095238];
            app.b2.Text = '基本全局阈值法';

            % Create b3
            app.b3 = uibutton(app.uibuttongroup5, 'push');
            app.b3.ButtonPushedFcn = createCallbackFcn(app, @b3_Callback, true);
            app.b3.Tag = 'b3';
            app.b3.FontSize = 13.3333333333333;
            app.b3.Position = [10 21 102.5 19.8095238095238];
            app.b3.Text = '局部阈值法';

            % Create slider1
            app.slider1 = uislider(app.figure1);
            app.slider1.Limits = [-180 180];
            app.slider1.MajorTicks = [];
            app.slider1.ValueChangedFcn = createCallbackFcn(app, @slider1_Callback, true);
            app.slider1.MinorTicks = [];
            app.slider1.FontSize = 10.6666666666667;
            app.slider1.Tag = 'slider1';
            app.slider1.Position = [271 102 179 3];

            % Create text5
            app.text5 = uilabel(app.figure1);
            app.text5.Tag = 'text5';
            app.text5.HorizontalAlignment = 'center';
            app.text5.VerticalAlignment = 'top';
            app.text5.WordWrap = 'on';
            app.text5.FontSize = 16;
            app.text5.Position = [230 91 30 37];
            app.text5.Text = '旋转';

            % Create uibuttongroup6
            app.uibuttongroup6 = uibuttongroup(app.figure1);
            app.uibuttongroup6.Title = '颜色/亮度调整';
            app.uibuttongroup6.Tag = 'uibuttongroup6';
            app.uibuttongroup6.FontSize = 16;
            app.uibuttongroup6.Position = [9 91 210 208];

            % Create slider2
            app.slider2 = uislider(app.uibuttongroup6);
            app.slider2.Limits = [-200 200];
            app.slider2.MajorTicks = [];
            app.slider2.ValueChangedFcn = createCallbackFcn(app, @slider2_Callback, true);
            app.slider2.MinorTicks = [];
            app.slider2.FontSize = 10.6666666666667;
            app.slider2.Tag = 'slider2';
            app.slider2.Position = [45 149 150 3];

            % Create slider3
            app.slider3 = uislider(app.uibuttongroup6);
            app.slider3.Limits = [-200 200];
            app.slider3.MajorTicks = [];
            app.slider3.ValueChangedFcn = createCallbackFcn(app, @slider3_Callback, true);
            app.slider3.MinorTicks = [];
            app.slider3.FontSize = 10.6666666666667;
            app.slider3.Tag = 'slider3';
            app.slider3.Position = [45 109 150 3];

            % Create slider4
            app.slider4 = uislider(app.uibuttongroup6);
            app.slider4.Limits = [-200 200];
            app.slider4.MajorTicks = [];
            app.slider4.ValueChangedFcn = createCallbackFcn(app, @slider4_Callback, true);
            app.slider4.MinorTicks = [];
            app.slider4.FontSize = 10.6666666666667;
            app.slider4.Tag = 'slider4';
            app.slider4.Position = [45 68 150 3];

            % Create text6
            app.text6 = uilabel(app.uibuttongroup6);
            app.text6.Tag = 'text6';
            app.text6.HorizontalAlignment = 'center';
            app.text6.VerticalAlignment = 'top';
            app.text6.WordWrap = 'on';
            app.text6.FontSize = 16;
            app.text6.Position = [10 144 30 26];
            app.text6.Text = 'R';

            % Create text7
            app.text7 = uilabel(app.uibuttongroup6);
            app.text7.Tag = 'text7';
            app.text7.HorizontalAlignment = 'center';
            app.text7.VerticalAlignment = 'top';
            app.text7.WordWrap = 'on';
            app.text7.FontSize = 16;
            app.text7.Position = [10 104 30 26];
            app.text7.Text = 'G';

            % Create text8
            app.text8 = uilabel(app.uibuttongroup6);
            app.text8.Tag = 'text8';
            app.text8.HorizontalAlignment = 'center';
            app.text8.VerticalAlignment = 'top';
            app.text8.WordWrap = 'on';
            app.text8.FontSize = 16;
            app.text8.Position = [10 63 30 26];
            app.text8.Text = 'B';

            % Create slider5
            app.slider5 = uislider(app.uibuttongroup6);
            app.slider5.Limits = [-150 150];
            app.slider5.MajorTicks = [];
            app.slider5.ValueChangedFcn = createCallbackFcn(app, @slider5_Callback, true);
            app.slider5.MinorTicks = [];
            app.slider5.FontSize = 10.6666666666667;
            app.slider5.Tag = 'slider5';
            app.slider5.Position = [45 28 150 3];

            % Create text9
            app.text9 = uilabel(app.uibuttongroup6);
            app.text9.Tag = 'text9';
            app.text9.HorizontalAlignment = 'center';
            app.text9.VerticalAlignment = 'top';
            app.text9.WordWrap = 'on';
            app.text9.FontSize = 16;
            app.text9.Position = [9 10 30 43.3333333333333];
            app.text9.Text = '亮度';

            % Create text10
            app.text10 = uilabel(app.figure1);
            app.text10.Tag = 'text10';
            app.text10.HorizontalAlignment = 'center';
            app.text10.VerticalAlignment = 'top';
            app.text10.WordWrap = 'on';
            app.text10.FontSize = 53.3333333333333;
            app.text10.FontColor = [0.0745098039215686 0.623529411764706 1];
            app.text10.Position = [230 594 452 65];
            app.text10.Text = '数字图像增强系统';

            % Create uipanel1
            app.uipanel1 = uipanel(app.figure1);
            app.uipanel1.Title = '图像增强';
            app.uipanel1.Tag = 'uipanel1';
            app.uipanel1.FontSize = 16;
            app.uipanel1.Position = [533 378 164 179];

            % Create a1
            app.a1 = uibutton(app.uipanel1, 'push');
            app.a1.ButtonPushedFcn = createCallbackFcn(app, @a1_Callback, true);
            app.a1.Tag = 'a1';
            app.a1.FontSize = 16;
            app.a1.Position = [24 110 110 23.5238095238095];
            app.a1.Text = '灰度拉伸';

            % Create a2
            app.a2 = uibutton(app.uipanel1, 'push');
            app.a2.ButtonPushedFcn = createCallbackFcn(app, @a2_Callback, true);
            app.a2.Tag = 'a2';
            app.a2.FontSize = 16;
            app.a2.Position = [23 79 111.25 24.1428571428571];
            app.a2.Text = '动态范围调整';

            % Create a3
            app.a3 = uibutton(app.uipanel1, 'push');
            app.a3.ButtonPushedFcn = createCallbackFcn(app, @a3_Callback, true);
            app.a3.Tag = 'a3';
            app.a3.FontSize = 16;
            app.a3.Position = [25 49 111.25 24.1428571428571];
            app.a3.Text = '拉普拉斯锐化';

            % Create DropDownLabel
            app.DropDownLabel = uilabel(app.uipanel1);
            app.DropDownLabel.HorizontalAlignment = 'right';
            app.DropDownLabel.Position = [27 20 77 22];
            app.DropDownLabel.Text = '直方图均衡化';

            % Create DropDown
            app.DropDown = uidropdown(app.uipanel1);
            app.DropDown.Items = {'图像', '直方图'};
            app.DropDown.ValueChangedFcn = createCallbackFcn(app, @DropDownValueChanged, true);
            app.DropDown.Position = [119 20 20 21];
            app.DropDown.Value = '图像';

            % Create uipanel2
            app.uipanel2 = uipanel(app.figure1);
            app.uipanel2.Title = '添加噪声';
            app.uipanel2.Tag = 'uipanel2';
            app.uipanel2.FontSize = 16;
            app.uipanel2.Position = [526 198 171 162];

            % Create s1
            app.s1 = uibutton(app.uipanel2, 'push');
            app.s1.ButtonPushedFcn = createCallbackFcn(app, @s1_Callback, true);
            app.s1.Tag = 's1';
            app.s1.FontSize = 16;
            app.s1.Position = [30 106 94.375 27.8571428571429];
            app.s1.Text = '椒盐噪声';

            % Create s2
            app.s2 = uibutton(app.uipanel2, 'push');
            app.s2.ButtonPushedFcn = createCallbackFcn(app, @s2_Callback, true);
            app.s2.Tag = 's2';
            app.s2.FontSize = 16;
            app.s2.Position = [32 65 92.5 30.3333333333333];
            app.s2.Text = '高斯噪声';

            % Create s3
            app.s3 = uibutton(app.uipanel2, 'push');
            app.s3.ButtonPushedFcn = createCallbackFcn(app, @s3_Callback, true);
            app.s3.Tag = 's3';
            app.s3.FontSize = 16;
            app.s3.Position = [30 26 93.75 28.4761904761905];
            app.s3.Text = '泊松噪声';

            % Create pushbutton34
            app.pushbutton34 = uibutton(app.figure1, 'push');
            app.pushbutton34.ButtonPushedFcn = createCallbackFcn(app, @pushbutton34_Callback, true);
            app.pushbutton34.Tag = 'pushbutton34';
            app.pushbutton34.FontSize = 10.6666666666667;
            app.pushbutton34.Position = [543 125 138 37];
            app.pushbutton34.Text = 'RGB转换HIS';

            % Create pushbutton35
            app.pushbutton35 = uibutton(app.figure1, 'push');
            app.pushbutton35.ButtonPushedFcn = createCallbackFcn(app, @pushbutton35_Callback, true);
            app.pushbutton35.Tag = 'pushbutton35';
            app.pushbutton35.FontSize = 10.6666666666667;
            app.pushbutton35.Position = [731 128 146 32];
            app.pushbutton35.Text = '直方图统计';

            % Create ContextMenu
            app.ContextMenu = uicontextmenu(app.figure1);

            % Create Menu
            app.Menu = uimenu(app.ContextMenu);
            app.Menu.Text = 'Menu';

            % Create Menu2
            app.Menu2 = uimenu(app.ContextMenu);
            app.Menu2.Text = 'Menu2';

            % Show the figure after all components are created
            app.figure1.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = WORK_App1(varargin)

            runningApp = getRunningApp(app);

            % Check for running singleton app
            if isempty(runningApp)

                % Create UIFigure and components
                createComponents(app)

                % Register the app with App Designer
                registerApp(app, app.figure1)

                % Execute the startup function
                runStartupFcn(app, @(app)WORK_OpeningFcn(app, varargin{:}))
            else

                % Focus the running singleton app
                figure(runningApp.figure1)

                app = runningApp;
            end

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.figure1)
        end
    end
end