MATLAB App Designer-签名字迹提取

所用MATLAB版本 R2021b

MATLAB App Designer-签名字迹提取_第1张图片

实现原理 = GUI交互界面 + 程序算法

MATLAB App Designer-签名字迹提取_第2张图片

MATLAB App Designer-签名字迹提取_第3张图片

MATLAB App Designer-签名字迹提取_第4张图片

 以下是设计的APP界面

MATLAB App Designer-签名字迹提取_第5张图片

 以下是源代码,大部分为app designer自己生成的框架

classdef SignatureExtractionApp_v2 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure         matlab.ui.Figure
        GridLayout       matlab.ui.container.GridLayout
        GridLayout10     matlab.ui.container.GridLayout
        GridLayout13     matlab.ui.container.GridLayout
        GridLayout15     matlab.ui.container.GridLayout
        Button_3         matlab.ui.control.Button
        Button_2         matlab.ui.control.Button
        Button           matlab.ui.control.Button
        vLabel           matlab.ui.control.Label
        GridLayout14     matlab.ui.container.GridLayout
        Button_4         matlab.ui.control.Button
        viLabel_2        matlab.ui.control.Label
        GridLayout11     matlab.ui.container.GridLayout
        GridLayout12     matlab.ui.container.GridLayout
        GridLayout16     matlab.ui.container.GridLayout
        ivButton         matlab.ui.control.Button
        ButtonGroup_4    matlab.ui.container.ButtonGroup
        Label_12         matlab.ui.control.Label
        SauvolaButton    matlab.ui.control.RadioButton
        Label_11         matlab.ui.control.Label
        OtsuButton       matlab.ui.control.RadioButton
        Image_3          matlab.ui.control.Image
        Label_15         matlab.ui.control.Label
        GridLayout2      matlab.ui.container.GridLayout
        GridLayout7      matlab.ui.container.GridLayout
        GridLayout8      matlab.ui.container.GridLayout
        GridLayout9      matlab.ui.container.GridLayout
        iiiButton        matlab.ui.control.Button
        ButtonGroup_3    matlab.ui.container.ButtonGroup
        EditField_2      matlab.ui.control.EditField
        Label_3          matlab.ui.control.Label
        EditField        matlab.ui.control.EditField
        Label_2          matlab.ui.control.Label
        Label_10         matlab.ui.control.Label
        SIZELabel        matlab.ui.control.Label
        pTextArea        matlab.ui.control.TextArea
        pTextAreaLabel   matlab.ui.control.Label
        Label_9          matlab.ui.control.Label
        bButton          matlab.ui.control.RadioButton
        p2TextArea       matlab.ui.control.TextArea
        p2TextAreaLabel  matlab.ui.control.Label
        p1TextArea       matlab.ui.control.TextArea
        Label            matlab.ui.control.Label
        Label_8          matlab.ui.control.Label
        aButton          matlab.ui.control.RadioButton
        Image_2          matlab.ui.control.Image
        Label_14         matlab.ui.control.Label
        GridLayout4      matlab.ui.container.GridLayout
        GridLayout5      matlab.ui.container.GridLayout
        GridLayout6      matlab.ui.container.GridLayout
        TextArea_2       matlab.ui.control.TextArea
        Label_6          matlab.ui.control.Label
        TextArea         matlab.ui.control.TextArea
        Label_5          matlab.ui.control.Label
        Label_4          matlab.ui.control.Label
        iiButton         matlab.ui.control.Button
        iButton          matlab.ui.control.Button
        Image            matlab.ui.control.Image
        Label_13         matlab.ui.control.Label
    end

    % 内部变量
    properties (Access = private)
        img_lu    % 左上
        img_ld    % 左下
        img_r     % 右
        img_bw    % 二值化图像
        rect      % 裁剪的四元素矩阵
        pmid      % 选取的中点
    end

    % 内部函数
    methods (Access = private)

        function LUshow(app) % 左上显示    
            app.Image.ImageSource = app.img_lu;
            [M,N,~] = size(app.img_lu);
            app.TextArea.Value = num2str(N);
            app.TextArea_2.Value = num2str(M);
        end

        function LDshow(app) % 左下显示
            app.Image_2.ImageSource = app.img_ld;
        end

        function Rshow(app) % 右边显示
            [M,N] = size(app.img_r);
            I = zeros(M,N,3);
            I(:,:,1) = app.img_r;
            I(:,:,2) = I(:,:,1);
            I(:,:,3) = I(:,:,1);
            app.Image_3.ImageSource = I;
        end

        function Otsu(app,inputimg) % Otsu算法
            I = inputimg;
            threshold = graythresh(I);
            app.img_bw = imbinarize(I,threshold);
        end

        function Sauvola(app,inputimg) % Sauvola算法
            I = inputimg;
            h = fspecial('average',25);
            mean = double(imfilter(I,h,'replicate'));
            nhood = strel('square',25).Neighborhood;
            std = stdfilt(I,nhood);
            k = 0.3;
            threshold = mean.*(1+k.*(std./128-1));
            I(I>=threshold) = 255;
            I(I

以下是运行示例

i.读入一张图片、旋转(仅90°,暂不支持小角度旋转)

MATLAB App Designer-签名字迹提取_第6张图片

 ii.任选一种剪裁方式剪裁图片

MATLAB App Designer-签名字迹提取_第7张图片

 iii.任选一种方式二值化

MATLAB App Designer-签名字迹提取_第8张图片

光照不均时务必选择Sauvola算法,例如:

MATLAB App Designer-签名字迹提取_第9张图片

 MATLAB App Designer-签名字迹提取_第10张图片

 iv.加粗变细复原,以及将右边图片保存到...

你可能感兴趣的:(matlab)