Get rect from mouse

imshow('test.jpg');
rect = getrect;

对话框 dialog box

cc: matlab GUI之对话框

多个string连接

  1. sprintf

    file_temp = sprintf('%s\\*.%s', data_pwd, input_type);
    
  2. strcat

    imgname=strcat(data_pwd,'\\',filearray(i).name);
    

获取文件绝对路径的各个部分 (e.g. 目录path, 文件名, 扩展名)

[pathstr,realname,ext] = fileparts('C:\\images\\test.bmp');

=>

pathstr = 'C:\images\'
realname = 'test'
ext = '.bmp'

UI获取文件名和文件夹

  • 文件

    [filename, pathname] = uigetfile({'*.*';'*.avi';'*.mpg';'*.wmv';'*.asf';'*.asx';'*.mj2'}, 'Select a VIDEO file...');
    video_file_name = fullfile(pathname, filename); % use fullfile for OS independent
    
  • 文件夹

    output_images_folder = uigetdir(pwd, 'Select the FOLDER where to save images...')
    

遍历文件夹内所有(指定类型)文件

data_pwd = uigetdir;
file_temp = sprintf('%s\\*.%s', data_pwd, input_type);
filearray = dir(file_temp);
s=max(size(filearray));
for i=1:1:s
    imgname=strcat(data_pwd,'\\',filearray(i).name);
    ... ...
end

获取image的长, 宽和channel数

img = imread('C:\Users\tommyhu\Desktop\test\frame_0000.bmp');
[h, w, c] = size(img);

遍历video的每一帧

mov = VideoReader(video_file_name);
for i=1:1:mov.numberofframes
    b=read(mov,i);
    ... ...
end

获取用户输入

  • 命令行方式

    strResponse = input('Do you want more? Y/N [Y]: ', 's');
    
  • UI方式

    prompt = { 'from:','to:','step'};
    dlg_title = 'choose images';
    num_lines = [4 1 3]; % can be a scaler number that applies to all
    defAns = {'0', '', '1'};
    options = 'on'; % enable to resize window
    answer = inputdlg(prompt,dlg_title,num_lines,defAns);
    
    from=str2num(cell2mat(answer(1)));
    to=str2num(cell2mat(answer(2)));
    stepsize=str2num(cell2mat(answer(3)));
    

输出到txt

fileID = fopen('faces.txt', 'w');
fprintf(fileID,'[%4.2f,%d,%d,%d]\n', x, y, z, t);
fclose(fileID);

Functions with required and optional inputs

Refer to http://www.mathworks.com/help/matlab/matlab_prog/parse-function-inputs.html.