classdef projekt < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure              matlab.ui.Figure
        ZamknijButton         matlab.ui.control.Button
        Otworz1Button         matlab.ui.control.Button
        Otworz2Button         matlab.ui.control.Button
        Otworz3Button         matlab.ui.control.Button
        KuwaharalButton       matlab.ui.control.Button
        MedianaButton         matlab.ui.control.Button
        SobelButton           matlab.ui.control.Button
        CannyButton           matlab.ui.control.Button
        UnsharpMaskingButton  matlab.ui.control.Button
        WybierzDropDownLabel  matlab.ui.control.Label
        WybierzDropDown       matlab.ui.control.DropDown
        GaussButton           matlab.ui.control.Button
        SzaryButton           matlab.ui.control.Button
        OdbicieButton         matlab.ui.control.Button
        RotacjaButton         matlab.ui.control.Button
        UIAxes                matlab.ui.control.UIAxes
        UIAxes2               matlab.ui.control.UIAxes
        UIAxes3               matlab.ui.control.UIAxes
        UIAxes4               matlab.ui.control.UIAxes
        UIAxes5               matlab.ui.control.UIAxes
        UIAxes6               matlab.ui.control.UIAxes
    end

    
    methods (Access = private)
        
        function results = func(app)
        app.WybierzDropDown = uidropdown(app.UIFigure);
        app.WybierzDropDown.Position = [466 717 100 22];
        app.WybierzDropDown.Items = {'Obraz 1', 'Obraz 2', 'Obraz 3'};
        app.WybierzDropDown.Value = 'Obraz 1'; 
        app.WybierzDropDown.ValueChangedFcn = @app.WybierzDropDownValueChanged;
        app.WybierzDropDown.DropDownOpeningFcn = @app.WybierzDropDownOpening;

        end
        
    end
  

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

        % Button pushed function: ZamknijButton
        function ZamknijButtonPushed(app, event)
            close(app.UIFigure);
        
        end

        % Button pushed function: Otworz1Button
        function Otworz1ButtonPushed(app, event)
            global image1
            [file1,path1]=uigetfile('*.jpg;*.png;*.bmp','Load the image');
            image1=imread([path1,file1]);
            imshow(image1,'Parent',app.UIAxes);
            
            
        
        end

        % Button pushed function: Otworz2Button
        function Otworz2ButtonPushed(app, event)
            global image2
            [file1,path1]=uigetfile('*.jpg;*.png;*.bmp','Load the image');
            image2=imread([path1,file1]);
            imshow(image2,'Parent',app.UIAxes2);
        end

        % Button pushed function: Otworz3Button
        function Otworz3ButtonPushed(app, event)
            global image3
            [file1,path1]=uigetfile('*.jpg;*.png;*.bmp','Load the image');
            image3=imread([path1,file1]);
            imshow(image3,'Parent',app.UIAxes3);
        end

        % Button pushed function: KuwaharalButton
        function KuwaharalButtonPushed(app, event)
            global image1 image2 image3

            [rows, cols, ~] = size(image1);
            areaSize = 3;

            
            resultImage1 = zeros(size(image1));
            resultImage2 = zeros(size(image2));
            resultImage3 = zeros(size(image3));

            for i = 1:2:rows
                for j = 1:2:cols
                    
                    subImage1 = image1(i:min(i+areaSize, end), j:min(j+areaSize, end), :);
                    subImage2 = image2(i:min(i+areaSize, end), j:min(j+areaSize, end), :);
                    subImage3 = image3(i:min(i+areaSize, end), j:min(j+areaSize, end), :);

                    
                    mean1 = mean(subImage1, [1, 2]);
                    mean2 = mean(subImage2, [1, 2]);
                    mean3 = mean(subImage3, [1, 2]);

                    variance1 = var(double(subImage1), 0, [1, 2]);
                    variance2 = var(double(subImage2), 0, [1, 2]);
                    variance3 = var(double(subImage3), 0, [1, 2]);

                    
                    [~, idx1] = min(variance1);
                    [~, idx2] = min(variance2);
                    [~, idx3] = min(variance3);

                    
                    resultImage1(i:min(i+areaSize, end), j:min(j+areaSize, end), :) = mean1(idx1);
                    resultImage2(i:min(i+areaSize, end), j:min(j+areaSize, end), :) = mean2(idx2);
                    resultImage3(i:min(i+areaSize, end), j:min(j+areaSize, end), :) = mean3(idx3);
                    
                  


                end
            end

            imshow(resultImage1, 'Parent', app.UIAxes4);
            imshow(resultImage2, 'Parent', app.UIAxes5);
            imshow(resultImage3, 'Parent', app.UIAxes6);

        end

        % Button pushed function: MedianaButton
        function MedianaButtonPushed(app, event)
             global image1 image2 image3

    
          imshow(image1, 'Parent', app.UIAxes);
          title(app.UIAxes, 'Oryginalny Obraz 1');
    
          imshow(image2, 'Parent', app.UIAxes2);
          title(app.UIAxes2, 'Oryginalny Obraz 2');
    
          imshow(image3, 'Parent', app.UIAxes3);
          title(app.UIAxes3, 'Oryginalny Obraz 3');

    
          windowSize = 3;  

   
         resultImage1 = zeros(size(image1));
         resultImage2 = zeros(size(image2));
         resultImage3 = zeros(size(image3));

    for i = 1:size(image1, 3)
        resultImage1(:,:,i) = medfilt2(image1(:,:,i), [windowSize windowSize]);
        resultImage2(:,:,i) = medfilt2(image2(:,:,i), [windowSize windowSize]);
        resultImage3(:,:,i) = medfilt2(image3(:,:,i), [windowSize windowSize]);
    end

   
        imshow(resultImage1, 'Parent', app.UIAxes4);
        title(app.UIAxes4, 'Filtr Medianowy Obraz 1');
    
        imshow(resultImage2, 'Parent', app.UIAxes5);
        title(app.UIAxes5, 'Filtr Medianowy Obraz 2');
    
        imshow(resultImage3, 'Parent', app.UIAxes6);
        title(app.UIAxes6, 'Filtr Medianowy Obraz 3');

            
        end

        % Button pushed function: SobelButton
        function SobelButtonPushed(app, event)
            global image1 image2 image3

   
    imshow(image1, 'Parent', app.UIAxes);
    title(app.UIAxes, 'Oryginalny Obraz 1');

    imshow(image2, 'Parent', app.UIAxes2);
    title(app.UIAxes2, 'Oryginalny Obraz 2');

    imshow(image3, 'Parent', app.UIAxes3);
    title(app.UIAxes3, 'Oryginalny Obraz 3');

   
    sobelFilterX = [-1 0 1; -2 0 2; -1 0 1];
    sobelFilterY = [-1 -2 -1; 0 0 0; 1 2 1];

    
    resultImage1 = zeros(size(image1));
    resultImage2 = zeros(size(image2));
    resultImage3 = zeros(size(image3));

    for i = 1:size(image1, 3)
        resultImage1(:,:,i) = conv2(double(image1(:,:,i)), sobelFilterX, 'same');
        resultImage2(:,:,i) = conv2(double(image2(:,:,i)), sobelFilterX, 'same');
        resultImage3(:,:,i) = conv2(double(image3(:,:,i)), sobelFilterX, 'same');
    end

    
    gradientMagnitude1 = sqrt(sum(resultImage1.^2, 3));
    gradientMagnitude2 = sqrt(sum(resultImage2.^2, 3));
    gradientMagnitude3 = sqrt(sum(resultImage3.^2, 3));

    
    imshow(gradientMagnitude1, 'Parent', app.UIAxes4);
    title(app.UIAxes4, 'Filtr Sobela Obraz 1');

    imshow(gradientMagnitude2, 'Parent', app.UIAxes5);
    title(app.UIAxes5, 'Filtr Sobela Obraz 2');

    imshow(gradientMagnitude3, 'Parent', app.UIAxes6);
    title(app.UIAxes6, 'Filtr Sobela Obraz 3');
        end

        % Button pushed function: CannyButton
        function CannyButtonPushed(app, event)
            global image1 image2 image3

    
            imshow(image1, 'Parent', app.UIAxes);
            title(app.UIAxes, 'Oryginalny Obraz 1');
        
            imshow(image2, 'Parent', app.UIAxes2);
            title(app.UIAxes2, 'Oryginalny Obraz 2');
        
            imshow(image3, 'Parent', app.UIAxes3);
            title(app.UIAxes3, 'Oryginalny Obraz 3');

            
            resultImage1 = zeros(size(image1));
            resultImage2 = zeros(size(image2));
            resultImage3 = zeros(size(image3));
        
            for i = 1:size(image1, 3)
                resultImage1(:,:,i) = edge(image1(:,:,i), 'Canny');
                resultImage2(:,:,i) = edge(image2(:,:,i), 'Canny');
                resultImage3(:,:,i) = edge(image3(:,:,i), 'Canny');
            end

           
            imshow(resultImage1, 'Parent', app.UIAxes4);
            title(app.UIAxes4, 'Detekcja Krawędzi (Canny) Obraz 1');
        
            imshow(resultImage2, 'Parent', app.UIAxes5);
            title(app.UIAxes5, 'Detekcja Krawędzi (Canny) Obraz 2');
        
            imshow(resultImage3, 'Parent', app.UIAxes6);
            title(app.UIAxes6, 'Detekcja Krawędzi (Canny) Obraz 3');
        end

        % Button pushed function: UnsharpMaskingButton
        function UnsharpMaskingButtonPushed(app, event)
            global image1 image2 image3

       
        imshow(image1, 'Parent', app.UIAxes);
        title(app.UIAxes, 'Oryginalny Obraz 1');
    
        imshow(image2, 'Parent', app.UIAxes2);
        title(app.UIAxes2, 'Oryginalny Obraz 2');
    
        imshow(image3, 'Parent', app.UIAxes3);
        title(app.UIAxes3, 'Oryginalny Obraz 3');
    
        
        filterSize = 5;  
        sigma = 1.5;  
    
        h = fspecial('gaussian', [filterSize, filterSize], sigma);
        unsharpMask = 1.5 * (eye(filterSize) - h);
    
        
        resultImage1 = imfilter(image1, unsharpMask);
        resultImage2 = imfilter(image2, unsharpMask);
        resultImage3 = imfilter(image3, unsharpMask);
    
        
        imshow(resultImage1, 'Parent', app.UIAxes4);
        title(app.UIAxes4, 'Unsharp Masking Obraz 1');
    
        imshow(resultImage2, 'Parent', app.UIAxes5);
        title(app.UIAxes5, 'Unsharp Masking Obraz 2');
    
        imshow(resultImage3, 'Parent', app.UIAxes6);
        title(app.UIAxes6, 'Unsharp Masking Obraz 3');
        end

        % Callback function
        function SredniaButtonPushed(app, event)
          
        
        end

        % Value changed function: WybierzDropDown
        function WybierzDropDownValueChanged(app, event)
            value = app.WybierzDropDown.Value;
        global image1 image2 image3

    
        switch value
        case 'Obraz1'
            set(app.UIAxes, 'Visible', 'on');
            set(app.UIAxes2, 'Visible', 'off');
            set(app.UIAxes3, 'Visible', 'off');
            imshow(image1, 'Parent', app.UIAxes);
            title(app.UIAxes, 'Obraz 1');
        case 'Obraz2'
            
            set(app.UIAxes, 'Visible', 'off');
            set(app.UIAxes2, 'Visible', 'on');
            set(app.UIAxes3, 'Visible', 'off');
            imshow(image2, 'Parent', app.UIAxes2);
            title(app.UIAxes2, 'Obraz 2');
        case 'Obraz3'
          
            set(app.UIAxes, 'Visible', 'off');
            set(app.UIAxes2, 'Visible', 'off');
            set(app.UIAxes3, 'Visible', 'on');
            imshow(image3, 'Parent', app.UIAxes3);
            title(app.UIAxes3, 'Obraz 3');
        otherwise
            
            set(app.UIAxes, 'Visible', 'off');
            set(app.UIAxes2, 'Visible', 'off');
            set(app.UIAxes3, 'Visible', 'off');
    end
        end

        % Drop down opening function: WybierzDropDown
        function WybierzDropDownOpening(app, event)

        availableItems = {'Obraz1', 'Obraz2', 'Obraz3'};
        app.WybierzDropDown.Items = availableItems;

        end

        % Button pushed function: GaussButton
        function GaussButtonPushed(app, event)
            global image1 image2 image3

            [rows, cols, ~] = size(image1);
            filterSize = 5;
            sigma = 1.5;
            
            
            h = fspecial('gaussian', [filterSize, filterSize], sigma);

            
            resultImage1 = imfilter(image1, h);
            resultImage2 = imfilter(image2, h);
            resultImage3 = imfilter(image3, h);

          
            image1 = resultImage1;
            image2 = resultImage2;
            image3 = resultImage3;

            
            imshow(resultImage1, 'Parent', app.UIAxes4);
            imshow(resultImage2, 'Parent', app.UIAxes5);
            imshow(resultImage3, 'Parent', app.UIAxes6);
        
        end

        % Button pushed function: SzaryButton
        function SzaryButtonPushed(app, event)
        global image1 image2 image3

        
        grayImage1 = rgb2gray(image1);
        grayImage2 = rgb2gray(image2);
        grayImage3 = rgb2gray(image3);
    
        resultImage1 = cat(3, grayImage1, grayImage1, grayImage1);
        resultImage2 = cat(3, grayImage2, grayImage2, grayImage2);
        resultImage3 = cat(3, grayImage3, grayImage3, grayImage3);
    
        imshow(resultImage1, 'Parent', app.UIAxes4);
        imshow(resultImage2, 'Parent', app.UIAxes5);
        imshow(resultImage3, 'Parent', app.UIAxes6);
  
        end

        % Button pushed function: OdbicieButton
        function OdbicieButtonPushed(app, event)
            global image1 image2 image3

        resultImage1 = flip(image1, 2);
        resultImage2 = flip(image2, 2);
        resultImage3 = flip(image3, 2);

        imshow(resultImage1, 'Parent', app.UIAxes4);
        imshow(resultImage2, 'Parent', app.UIAxes5);
        imshow(resultImage3, 'Parent', app.UIAxes6);
        end

        % Button pushed function: RotacjaButton
        function RotacjaButtonPushed(app, event)
        global image1 image2 image3

        prompt = 'Podaj kąt rotacji (w stopniach):';
        title = 'Rotacja obrazu';
        angle = str2double(inputdlg(prompt, title, [1 40]));
    
        if isnan(angle)
            errordlg('Podano nieprawidłowy kąt rotacji.', 'Błąd');
            return;
        end

   
        resultImage1 = imrotate(image1, angle, 'bilinear', 'crop');
        resultImage2 = imrotate(image2, angle, 'bilinear', 'crop');
        resultImage3 = imrotate(image3, angle, 'bilinear', 'crop');
    
        figure('Name', 'Rotacja Obraz 1');
        imshow(resultImage1);
        figure('Name', 'Rotacja Obraz 2');
        imshow(resultImage2);
        figure('Name', 'Rotacja Obraz 3');
        imshow(resultImage3);
        end

        % Callback function
        function PrzycinanieButtonPushed(app, event)
       
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 1049 752];
            app.UIFigure.Name = 'MATLAB App';

            % Create ZamknijButton
            app.ZamknijButton = uibutton(app.UIFigure, 'push');
            app.ZamknijButton.ButtonPushedFcn = createCallbackFcn(app, @ZamknijButtonPushed, true);
            app.ZamknijButton.BackgroundColor = [1 0 0];
            app.ZamknijButton.FontWeight = 'bold';
            app.ZamknijButton.Position = [14 574 121 67];
            app.ZamknijButton.Text = 'Zamknij';

            % Create Otworz1Button
            app.Otworz1Button = uibutton(app.UIFigure, 'push');
            app.Otworz1Button.ButtonPushedFcn = createCallbackFcn(app, @Otworz1ButtonPushed, true);
            app.Otworz1Button.BackgroundColor = [0.3922 0.8314 0.0745];
            app.Otworz1Button.FontWeight = 'bold';
            app.Otworz1Button.Position = [14 712 100 22];
            app.Otworz1Button.Text = 'Otworz1';

            % Create Otworz2Button
            app.Otworz2Button = uibutton(app.UIFigure, 'push');
            app.Otworz2Button.ButtonPushedFcn = createCallbackFcn(app, @Otworz2ButtonPushed, true);
            app.Otworz2Button.BackgroundColor = [0.3922 0.8314 0.0745];
            app.Otworz2Button.FontWeight = 'bold';
            app.Otworz2Button.Position = [125 712 100 22];
            app.Otworz2Button.Text = 'Otworz2';

            % Create Otworz3Button
            app.Otworz3Button = uibutton(app.UIFigure, 'push');
            app.Otworz3Button.ButtonPushedFcn = createCallbackFcn(app, @Otworz3ButtonPushed, true);
            app.Otworz3Button.BackgroundColor = [0.3922 0.8314 0.0745];
            app.Otworz3Button.FontWeight = 'bold';
            app.Otworz3Button.Position = [234 712 100 22];
            app.Otworz3Button.Text = 'Otworz3';

            % Create KuwaharalButton
            app.KuwaharalButton = uibutton(app.UIFigure, 'push');
            app.KuwaharalButton.ButtonPushedFcn = createCallbackFcn(app, @KuwaharalButtonPushed, true);
            app.KuwaharalButton.BackgroundColor = [1 1 0.0667];
            app.KuwaharalButton.FontWeight = 'bold';
            app.KuwaharalButton.Position = [193 469 100 22];
            app.KuwaharalButton.Text = 'Kuwaharal';

            % Create MedianaButton
            app.MedianaButton = uibutton(app.UIFigure, 'push');
            app.MedianaButton.ButtonPushedFcn = createCallbackFcn(app, @MedianaButtonPushed, true);
            app.MedianaButton.BackgroundColor = [0 1 1];
            app.MedianaButton.FontWeight = 'bold';
            app.MedianaButton.Position = [303 469 100 22];
            app.MedianaButton.Text = 'Mediana';

            % Create SobelButton
            app.SobelButton = uibutton(app.UIFigure, 'push');
            app.SobelButton.ButtonPushedFcn = createCallbackFcn(app, @SobelButtonPushed, true);
            app.SobelButton.BackgroundColor = [0.7176 0.2745 1];
            app.SobelButton.FontWeight = 'bold';
            app.SobelButton.Position = [414 469 100 22];
            app.SobelButton.Text = 'Sobel';

            % Create CannyButton
            app.CannyButton = uibutton(app.UIFigure, 'push');
            app.CannyButton.ButtonPushedFcn = createCallbackFcn(app, @CannyButtonPushed, true);
            app.CannyButton.BackgroundColor = [0.851 0.3255 0.098];
            app.CannyButton.FontWeight = 'bold';
            app.CannyButton.Position = [523 469 100 22];
            app.CannyButton.Text = 'Canny';

            % Create UnsharpMaskingButton
            app.UnsharpMaskingButton = uibutton(app.UIFigure, 'push');
            app.UnsharpMaskingButton.ButtonPushedFcn = createCallbackFcn(app, @UnsharpMaskingButtonPushed, true);
            app.UnsharpMaskingButton.BackgroundColor = [0.651 0.651 0.651];
            app.UnsharpMaskingButton.FontWeight = 'bold';
            app.UnsharpMaskingButton.Position = [635 469 112 22];
            app.UnsharpMaskingButton.Text = 'UnsharpMasking';

            % Create WybierzDropDownLabel
            app.WybierzDropDownLabel = uilabel(app.UIFigure);
            app.WybierzDropDownLabel.BackgroundColor = [0.7412 0.3333 0.3333];
            app.WybierzDropDownLabel.HorizontalAlignment = 'right';
            app.WybierzDropDownLabel.FontWeight = 'bold';
            app.WybierzDropDownLabel.Position = [15 667 51 22];
            app.WybierzDropDownLabel.Text = 'Wybierz';

            % Create WybierzDropDown
            app.WybierzDropDown = uidropdown(app.UIFigure);
            app.WybierzDropDown.Items = {'Obraz1', 'Obraz2', 'Obraz3', 'Option 4'};
            app.WybierzDropDown.DropDownOpeningFcn = createCallbackFcn(app, @WybierzDropDownOpening, true);
            app.WybierzDropDown.ValueChangedFcn = createCallbackFcn(app, @WybierzDropDownValueChanged, true);
            app.WybierzDropDown.FontWeight = 'bold';
            app.WybierzDropDown.BackgroundColor = [0.7412 0.3333 0.3333];
            app.WybierzDropDown.Position = [70 667 265 22];
            app.WybierzDropDown.Value = 'Obraz1';

            % Create GaussButton
            app.GaussButton = uibutton(app.UIFigure, 'push');
            app.GaussButton.ButtonPushedFcn = createCallbackFcn(app, @GaussButtonPushed, true);
            app.GaussButton.BackgroundColor = [0.1843 0.349 0.5804];
            app.GaussButton.FontWeight = 'bold';
            app.GaussButton.Position = [230 439 100 22];
            app.GaussButton.Text = 'Gauss';

            % Create SzaryButton
            app.SzaryButton = uibutton(app.UIFigure, 'push');
            app.SzaryButton.ButtonPushedFcn = createCallbackFcn(app, @SzaryButtonPushed, true);
            app.SzaryButton.BackgroundColor = [0.5373 0.549 0.5451];
            app.SzaryButton.FontWeight = 'bold';
            app.SzaryButton.Position = [347 439 100 22];
            app.SzaryButton.Text = 'Szary';

            % Create OdbicieButton
            app.OdbicieButton = uibutton(app.UIFigure, 'push');
            app.OdbicieButton.ButtonPushedFcn = createCallbackFcn(app, @OdbicieButtonPushed, true);
            app.OdbicieButton.BackgroundColor = [0.302 0.7216 0.6];
            app.OdbicieButton.FontWeight = 'bold';
            app.OdbicieButton.Position = [462 439 100 22];
            app.OdbicieButton.Text = 'Odbicie';

            % Create RotacjaButton
            app.RotacjaButton = uibutton(app.UIFigure, 'push');
            app.RotacjaButton.ButtonPushedFcn = createCallbackFcn(app, @RotacjaButtonPushed, true);
            app.RotacjaButton.BackgroundColor = [0.3686 0.2431 0.7412];
            app.RotacjaButton.FontWeight = 'bold';
            app.RotacjaButton.Position = [580 439 100 22];
            app.RotacjaButton.Text = 'Rotacja';

            % Create UIAxes
            app.UIAxes = uiaxes(app.UIFigure);
            title(app.UIAxes, 'Obraz 1')
            app.UIAxes.XTick = [];
            app.UIAxes.YTick = [];
            app.UIAxes.Position = [1 213 300 185];

            % Create UIAxes2
            app.UIAxes2 = uiaxes(app.UIFigure);
            title(app.UIAxes2, 'Obraz 2')
            app.UIAxes2.XTick = [];
            app.UIAxes2.YTick = [];
            app.UIAxes2.Position = [300 213 300 185];

            % Create UIAxes3
            app.UIAxes3 = uiaxes(app.UIFigure);
            title(app.UIAxes3, 'Obraz 3')
            app.UIAxes3.XTick = [];
            app.UIAxes3.YTick = [];
            app.UIAxes3.Position = [612 213 300 185];

            % Create UIAxes4
            app.UIAxes4 = uiaxes(app.UIFigure);
            title(app.UIAxes4, 'Wynik 1')
            app.UIAxes4.XTick = [];
            app.UIAxes4.YTick = [];
            app.UIAxes4.Position = [1 16 300 185];

            % Create UIAxes5
            app.UIAxes5 = uiaxes(app.UIFigure);
            title(app.UIAxes5, 'Wynik 2')
            app.UIAxes5.XTick = [];
            app.UIAxes5.YTick = [];
            app.UIAxes5.Position = [300 16 300 185];

            % Create UIAxes6
            app.UIAxes6 = uiaxes(app.UIFigure);
            title(app.UIAxes6, 'Wynik 3')
            app.UIAxes6.XTick = [];
            app.UIAxes6.YTick = [];
            app.UIAxes6.Position = [612 16 300 185];

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

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = projekt

            % Create UIFigure and components
            createComponents(app)

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

            if nargout == 0
                clear app
            end
        end

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

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