Matlab图像处理app(截图暂时只能截取原图或灰度图)

因为之前做过一个类似的app,所以我这次在app上的功能只是在灰度图上实现,不能叠加的实现,如果想要所有功能显示叠加效果,可以每次操作后使用一个全局变量将变换后的图片保存即可;

Matlab图像处理app(截图暂时只能截取原图或灰度图)_第1张图片

 边缘提取部分:

function sureButtonPushed(app, event)
            app.bianyuan=app.ListBox.Value;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            switch app.bianyuan
                case 'Roberts'
                    [J, thresh] = edge(app.picture, 'Roberts', 30/255); 
                    imshow(J,'Parent',app.UIAxes2);
                case 'Canny'
                    [J, thresh] = edge(app.picture, 'canny'); 
                    imshow(J,'Parent',app.UIAxes2);
                case 'LOG'
                    [J, thresh] = edge(app.picture, 'log');
                    imshow(J,'Parent',app.UIAxes2);
                case 'Prewit'
                    [J, thresh] = edge(app.picture, 'prewitt');
                    imshow(J,'Parent',app.UIAxes2);
                case 'Sobel'
                    [J, thresh] = edge(app.picture, 'sobel');
                    imshow(J,'Parent',app.UIAxes2);
            end
        end

对比度部分:

 function SliderValueChanging(app, event)
            changingValue = event.Value;
            changingValue=changingValue./100;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            if changingValue<0.5
                duibi=imadjust(app.picture,[changingValue,1-changingValue],[]);
                imshow(duibi,'Parent',app.UIAxes2);
            else
                changingValue=0;
                duibi=imadjust(app.picture,[changingValue,1-changingValue],[]);
                imshow(duibi,'Parent',app.UIAxes2);
            end
        end

直方图均衡化部分:

function ButtonGroupSelectionChanged(app, event)
            selectedButton = app.ButtonGroup.SelectedObject;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            switch selectedButton.Text
                case '是'
                    zhifang=histeq(app.picture);
                    imshow(zhifang,'Parent',app.UIAxes2);
                case '否'
                    imshow(app.picture,'Parent',app.UIAxes2);
                    return;
            end
        end

模糊度部分:

        function Spinner_2ValueChanged(app, event)
            value = app.Spinner_2.Value;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            way=fspecial('motion',value,value);
            picture2=imfilter(app.picture,way);
            imshow(picture2,'Parent',app.UIAxes2);
        end

锐化部分:

 function SpinnerValueChanged(app, event)
            value = app.Spinner.Value;
            value=value./100;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            way=fspecial('sobel');
            picture3=imfilter(app.picture,way);
            picture3=app.picture+uint8(picture3)*value;
            imshow(picture3,'Parent',app.UIAxes2);
        end

亮度部分:

   function Spinner_3ValueChanged(app, event)
            value = app.Spinner_3.Value;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            picture4=imadd(app.picture,value);
            imshow(picture4,'Parent',app.UIAxes2);
        end

图像分割部分:

 function sureButton_2Pushed(app, event)
            chance=app.ListBox_2.Value;
            size1=size(app.picture);
            if(numel(size1)>2)
                app.picture=rgb2gray(app.picture);
            end
            switch chance
                case 'Otsu'
                    M=graythresh(app.picture);
                    I=im2bw(app.picture,M);
                    imshow(I,'Parent',app.UIAxes2);
                case '迭代阈值分割'
                    I=im2double(app.picture);
                    S=0.1;
                    S1=(max(I(:))+min(I(:)))/2;
                    r1=find(I>S1);
                    r2=find(I<=S1);
                    S2=(mean(I(r1))+mean(I(r2)))/2;
                    while abs(S2-S1)>S
                          S1=S2;
                          r1=find(I>S1);
                          r2=find(I<=S1);
                          S2=(mean(I(r1))+mean(I(r2)))/2;
                    end
                    I=im2bw(I,S2);
                    imshow(I,'Parent',app.UIAxes2);
                case '区域生长法'
                    imshow(app.picture,'Parent',app.UIAxes2);
                    I=im2double(app.picture);
                    [M,N]=size(I);
                    [y,x]=getpts(app.UIAxes2);
                    x1=round(x);
                    y1=round(y);
                    seed=I(x1,y1);
                    grow1=zeros(M,N);%要绘制二值图,就可以先设置为0数组
                    grow1(x1,y1)=1;%种子点设为1,满足条件的点在后续判断中也会设为一
                     
                    growcount=1; %待处理点个数
                    threshold=0.15;%与isinteger相互结合起来理解,如果没有isinteger,该值应该变得很大
                     
                    while growcount>0
                        growcount=0;
                         for i=1:M %让种子去融合图片中满足的所有点
                            for j=1:N
                                if grow1(i,j)==1 %点在"栈"内,即一开始先检测到种子点,然后根据判断条件去判断种子点邻域的点是否满足条件,若满足为1,然后进行下一轮循环进行判断,直到循环时没有点可以满足添加进行融合了
                                    if (i-1)>0&(i+1)0&(j+1)

open:

 function openButtonPushed(app, event)
            [filename,pathname]=uigetfile('*.jpg','picture');
            if isequal(pathname,'')
                msgbox('没有选中图片','nn','warn');
            else
                app.name=strcat(pathname,filename);
                app.EditField.Value=app.name;
                app.picture=imread(app.name);
                imshow(app.picture,'Parent',app.UIAxes);
            end

        end

levelangle:

 function levelangleKnob_2ValueChanging(app, event)
            changingValue = event.Value;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            picture6=imrotate(app.picture,changingValue);
            imshow(picture6,'Parent',app.UIAxes2);
        end

mirror:

  function mirrorKnobValueChanged(app, event)
            value = app.mirrorKnob.Value;
            size1=size(app.picture);
            if numel(size1)>2
                app.picture=rgb2gray(app.picture);
            end
            switch value
                case 'x镜面'
                    picture7=flip(app.picture,1);
                case 'y镜面'
                    picture7=flip(app.picture,2);
            end
            imshow(picture7,'Parent',app.UIAxes2);
        end

灰度图:

  function Button_6Pushed(app, event)
            app.picture=rgb2gray(app.picture);
            imshow(app.picture,'Parent',app.UIAxes2);
        end

截图:

 function Button_5Pushed(app, event)
            savepicture=figure('Visible','on');
            copyobj(app.UIAxes2,savepicture);
            set(gca,'Units','normalized','Position',[0 0 1 1]);
            for i=1:1:2
                [x,y]=getpts;
                if(i==1)
                    app.cut1=x;
                    app.cut2=y;
                else
                    app.cut3=x;
                    app.cut4=y;
                end
            end
%             msgbox(string(app.cut1));
%             msgbox(string(abs(app.cut1-app.cut3)));
%             msgbox(string(abs(app.cut4-app.cut2)));
%             msgbox(string(app.cut2));
%             msgbox(string(app.cut3));
%             msgbox(string(app.cut4));
%             [m,n]=size(app.picture);
%             m=floor(m./2);
%             n=floor(n./2);

% k=findall(gcf,'type','line')
% x=get(k,'xdata');
% y=get(k,'ydata');
% x=cell2mat(x);
% y=cell2mat(y);
              saveas(savepicture,'1.jpg');
%             n=imcrop(savepicture,[app.cut1,app.cut2,app.cut3,app.cut4]);
%             imwrite(k(x(app.cut1:app.cut3),y(app.cut2:app.cut4)),'1.jpg');
              imwrite(app.picture(app.cut1:app.cut3,app.cut2:app.cut4),'0.jpg');
        end

保存:


        function saveButtonPushed(app, event)
            savepicture=figure('Visible','off');
            copyobj(app.UIAxes2,savepicture);
            set(gca,'Units','normalized','Position',[0.2 0.2 0.8 0.8]);
            saveas(savepicture,'nb.jpg');
        end

你可能感兴趣的:(matlab,图像处理)