Matlab image processing app (screenshots can only capture original images or grayscale images temporarily)

Because I have made a similar app before, so the functions on my app this time are only implemented on the grayscale image, and cannot be superimposed. If you want to display the superimposed effect of all functions, you can use a global variable after each operation. The converted image can be saved;

 Edge extraction part:

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

Contrast section:

 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

Histogram equalization part:

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

Ambiguity part:

        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

Sharpening part:

 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

Brightness section:

   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

Image segmentation part:

 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)<M&(j-1)>0&(j+1)<N %确保可以将8邻域完全放置
                                        for u=-1:1 %8邻域生长
                                            for v=-1:1
                                                if (grow1(i+u,j+v)==0&abs(I(i+u,j+v)-seed)<=threshold)%只有在点为0的时候才进行,否则gowtcount会计算错误
                                                    grow1(i+u,j+v)=1;%种子合并其他点,只要满足条件的点都会和种子点一样置1
                                                    growcount=growcount+1;  %记录此次新生长的点个数
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                    imshow(grow1,'Parent',app.UIAxes2);

                case '分水岭分割'       
                    way=strel('disk',10);
                    I=app.picture;
                    tidu=imgradient(I);
                    fs=imerode(I,way);
                    fscj=imreconstruct(fs,I);
                    pz=imdilate(fscj,way);
                    pzcj=imcomplement(imreconstruct(imcomplement(pz),imcomplement(fscj)));
                    dgm=imregionalmax(pzcj);
                    I2=labeloverlay(I,dgm);
                    se2 = strel(ones(5,5));
                    fgm2 = imclose(dgm,se2);
                    fgm3 = imerode(dgm,se2);
                    fgm4=bwareaopen(fgm3,15);         
                    I(fgm4)=255;
                    bw1=imbinarize(pzcj);
                    D = bwdist(bw1);
                    DL = watershed(D);
                    bgm = DL == 0;
                    gmag2 = imimposemin(tidu, bgm|fgm4);
                    L=watershed(gmag2);
                    labels = imdilate(L==0,ones(3,3)) + 2*bgm + 3*fgm4;
                    I4 = labeloverlay(I,labels);
                    imshow(I4,'Parent',app.UIAxes2);

            end
        end

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

Grayscale image:

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

screenshot:

 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

keep:


        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

Guess you like

Origin blog.csdn.net/new_EAGLE/article/details/125908563