天天看點

Matlab 進階學習記錄

最近在看 Faster RCNN的Matlab code,發現很多matlab技巧,活到老,學到老。。。

1. conf_proposal  =  proposal_config('image_means', model.mean_image, 'feat_stride', model.feat_stride);

  

The <code>inputParser</code> object allows you to manage inputs to a function by creating an input scheme. To check the input, you can define validation functions for required arguments, optional arguments, and name-value pair arguments. Optionally, you can set properties to adjust the parsing behavior, such as handling case sensitivity, structure array inputs, and inputs that are not in the input scheme.

After calling the <code>parse</code> method to parse the inputs, the <code>inputParser</code> saves names and values of inputs that match the input scheme (stored in <code>Results</code>), names of inputs that are not passed to the function and, therefore, are assigned default values (stored in <code>UsingDefaults</code>), and names and values of inputs that do not match the input scheme (stored in <code>Unmatched</code>).

 http://www.cnblogs.com/heleifz/p/matlab-function-handle.html 

2. assert 語句的使用:

  assert: Generate an error when a condition is violated.  

  assert(EXPRESSION, ERRMSG) evaluates EXPRESSION and, if it is false, displays the string contained in ERRMSG. When ERRMSG is the last input to assert, MATLAB displays it literally, without performing any substitutions on the characters in ERRMSG.

  例如:如果 contion 不成立,則會輸出對應的:提示錯誤資訊。

3.  permute 函數:

 Permute array dimensions.

    B = permute(A,ORDER) rearranges the dimensions of A so that they

    are in the order specified by the vector ORDER.

4. cellfun 函數:

  cellfun: Apply a function to each cell of a cell array. A = cellfun(FUN, C) applies the function specified by FUN to the contents of each cell of cell array C, and returns the results in the array A. 

5. 從清單 A 中去搜尋清單 B 中是否存在有相交元素,即:求 A and B 的差。

6. containers.Map() 的用法

  matlab中的containers.Map()有點類似于C++ STL中的map容器,具有key/value映射的功能.

    num = containers.Map({1, 2, 3}, {'one', 'two', 'three'})   

  myMap = containers.Map(KEYS, VALUES) constructs a Map object myMap that contains one or more keys and a value for each of these keys, as specified in the KEYS and VALUES arguments. 

  例如:從 Map 上提取一個值:myValue = myMap(key) ;

  修改鍵值對 (key-values pairs): myMap(key) = newValue ;

  增加一個新的鍵值對:myMap(key) = newValue ; 

  可以通過 remove 的方法将 values 删除掉。

7. try catch end 機制:

  該機制可以防止由于程式中可能出現的錯誤而終止運作的情況:

  try 

   ld     = load(anchor_cache_file) ; 

     anchors   = ld.anchors ; 

  catch 

   base_anchor  = [1, 1, opts.base_size, opts.base_size] ;

     ratio_anchors     = ratio_jitter(base_anchor, opts.ratios) ; 

  end 

 8. About change the gray image into 3 channel RGB image: 

synthetic is a single channel image, and synthetic2 is a three channel image.  

Another Solution is: 

% if grayscale repeat one channel to match filters size

if(size(im, 3)==1)

  im = repmat(im, [1 1 3]);

end

9. Divided the image into specific patches using matlab function: mat2cell 

Matlab 進階學習記錄

  This is a really cool function. For example, you read one image and divide it into 3*3 = 9 patches, and we assume the resolution of the image is: 100*100, you just need set the vectors M = [20, 30, 50]; N = [20, 20, 60] ; 

Actually, as long as the sum of three values you set  equal to 100 (here is 20, 30, 50), it will be ok. The other vector N have the same reason. 

10. Read images from disks and save these frames into avi video files. 

 12. 根據 attention maps 置信度的高低,生成對應的 bounding box : 

Matlab 進階學習記錄

 13. 将 video 切割為 frame: 

14. divide the total attention maps according to given video frames such as TC128. 

Matlab 進階學習記錄
Matlab 進階學習記錄

View Code

15. count the image list into txt files. 

Matlab 進階學習記錄
Matlab 進階學習記錄

16. load json files using matlab code.

  this used package from: http://blog.csdn.net/sophia_xw/article/details/70141208    

  unzip this file and add path to matlab like this: