[Learn one] Matlab GUI study notes Ⅰ

Matlab GUI Study Notes Ⅰ

1. Foreword


  • Is Matlab strictly a programming language? Someone once told me that he learned object-oriented programming through Matlab. I don't believe it, but this still does not prevent its powerful functions in special fields. Because of this 1-credit Matlab GUI design, some people expressed some emotions about the Previous Matlab Blog , so they wrote some Matlab GUI programming learning experience.
  • Although the title is Matlab GUI Study Notes I, it can also be called Image Processing Technology Application Practice - Course Design 1 Guide North.
  • The environment used in this article is the Chinese version of Matlab R2018a.

2. Task


  • Self-study Matlab GUI programming, design and implement an image space transformation system.
  • Require:
    • Can perform translation, rotation, scaling, shearing, projection, affine, transformation and various compound transformations on images;
    • Can save various transformed results as image files;
    • Various transformations can be carried out in the form of buttons or menus;
    • During transformation, users can set simple transformation parameters by themselves.

3. Function


3.1 Create

  • In the command line window, enter and guideselect the new GUI tab Blank GUI (Default)
  • The Chinese version of the Chinese version is relatively complete, and the controls corresponding to all options in the left toolbar have their Chinese names.
  • Right click on the panel -> Inspector -> Name to modify the form title
  • Mainly used AXES, BUTTON controls

3.2 File

The origin of all things.
Realize the effect:

3.2.1 Open picture

  • uigetdir select file (folder)
  • imread()read in image
  • Code:

    [ReadImageFileName,ReadImagePathName,ReadImageFilterIndex] = uigetfile({'*.jpg;*.png;*.tif','ImageFile(*.jpg;*.png;*.tif)';...  
    '*.jpg','JPEGImageFile(*.jpg)';'*.*','AllFile(*.*)'},'ReadImage',...  
    'MultiSelect','off',...       
    'C:\Users\Public\Pictures\Sample Pictures');
     FirstImageFullPath = fullfile(ReadImagePathName,ReadImageFileName); 
    InputImage=imread(FirstImageFullPath);

3.2.2 Save picture

  • uigetdir select file (folder)
  • imwrite()save document
  • Code:

    [SaveImagePathName] = uigetdir('C:\Users\Public\Pictures\Sample Pictures','请选择文件夹');
    filepath=fullfile(SaveImagePathName,'result.jpg');  
    imwrite(ResultImage,filepath,'jpg');

3.2.3 Display pictures

  • axes()positioning display axes
  • imshow()display image
  • Code:

    axes(findobj('tag', 'axes1')); 
    InputImage=imread(FirstImageFullPath);
    imshow(InputImage);  

3.3 Transition

Realize the effect:

3.3.1 Panning

  • imdilate()function to implement image translation
  • Code:

    se=translate(strel(1),[100,100]);  
    ResultImage=imdilate(InputImage,se);

3.3.2 User Interaction

  • inputdlg()Function to open a dialog to interact with the user
  • Set parameters according to the returned value obtained
  • The part that involves user interaction in the following functions is omitted.
  • Code:

    defaulta={'100'};
    a=inputdlg('请输入x轴参数','',1,defaulta);

3.4 rotate

  • Realize the effect:
  • use imrotata()function
  • Code :ResultImage = imrotate(InputImage,90);

3.5 Scale

  • Realize the effect:
  • use resize()function
  • Code :ResultImage=imresize(InputImage,1.5);

3.6 Clipping

Personally think the hardest part.
The final effect:

3.6.1 Button Interaction

  • get(hObject,'String');The return value is the title of the button
  • set(hObject,'String','ChangeToTitle');change button title
  • Use if statement nesting to judge the toggle button title:

    now = get(hObject,'String');
    if now == '剪切'
    set(hObject,'String','确定');
    else
    set(hObject,'String','剪切');
    end

3.6.2 Cut the image

  • imrect()Create image selection using
    egimrect(handle, selection size);
  • getPosition()get location
  • imcrop()clip image
  • Code:

    h=imrect(handles.axes1, [10 10 100 100]);  
    pos=getPosition(h);
    ResultImage=imcrop(InputImage, pos);

3.6.3 Other functions

  • getAPI()get function handle
  • addNewPositionCallback()add listener
  • makeConstrainToRectFcn()listener event

    api = iptgetapi(h);  
    api.addNewPositionCallback(@(p) title(mat2str(p,3)));  %标题显示选区大小
    fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));  
    api.setPositionConstraintFcn(fcn);  %防止选区超出axes范围

3.7 Projection

Realize the effect:

3.7.1 Question Box Interaction

  • questdlg(Title,Text,choice,...,DafaultChoice)Question box function
  • Code :s = questdlg('请选择投影方式','参数','垂直','水平','垂直水平','垂直');

3.7.2 Projection

3.8 Affine & Transformation & ... & Postscript

No longer.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325151982&siteId=291194637