⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 get_features.m

📁 用Cross validation的方法建立人工神经网络的模型!
💻 M
字号:
%
% function [features] = get_features(slice, blocksize): partion the
% 2D slice into certain number of partions, each of given blocksize
% 
%
% Input: slice -- the original 2D slice
%    blocksize -- the size of keyblock is blocksize^2
%
% Output:    
%     features -- n*(blocksize^2), a row vector that stores the mean value for each 
%                 partition
%       n_rows -- number of blocks
%    n_columns -- blocksize^2
%

function [feature, n_rows, n_columns] = get_features(slice, blocksize)

[nr nc] = size(slice);

new_r = round(nr/blocksize);
new_c = round(nc/blocksize);

n_rows = new_r * new_c;
n_columns = blocksize^2;
feature = zeros(0,0);

% encode image here
for r = 1: new_r
    for c = 1: new_c
        r_start = blocksize*(r-1)+1;
        c_start = blocksize*(c-1)+1;
        
        if (r == new_r) & (blocksize*r > nr)
            r_end = nr;
        else
            r_end = blocksize*r;
        end
        
        if (c == new_c) & (blocksize*c > nc)
            c_end = nc;
        else
            c_end = blocksize*c;
        end
        
        sub_part = slice(r_start:r_end, c_start:c_end);
        sub_part = reshape(sub_part, 1, []);
        if size(sub_part,2) < n_columns
            sub_part = [sub_part zeros(1, n_columns-size(sub_part,2))];
        end
        feature = [feature; sub_part];
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -