Is there any way to control the concatenation of the blockproc output?

假如想象 提交于 2019-12-02 00:51:31

Maybe reshape you data in the third dimension?

>> A = magic(3)

A =

     8     1     6
     3     5     7
     4     9     2

>> B = blockproc(A, [1 1], @(x)reshape(x.data(:),[1 1 numel(x.data)]), 'BorderSize', [1 1], 'TrimBorder', false, 'PadPartialBlocks', true);

>> whos B
  Name      Size             Bytes  Class     Attributes

  B         3x3x9              648  double  
>> squeeze(B(1,1,:))

ans =

     0
     0
     0
     0
     8
     3
     0
     1
     5

>> 

An alternate using MAT2CELL:

function extractFeatures
images_m{1} = rand(128);
B = blockproc(images_m{1}, [64 64], @processBlock,...
    'BorderSize', [10 10], 'TrimBorder', false,...
    'PadPartialBlocks', true, 'PadMethod', 'replicate');

%B is 2x400 i.e 2x2 blocks of each block being a 1x200 feature vector
m = ones(1,size(B,1));
n = 200*ones(1,size(B,2)/200);
% The MAT2CELL help does a good job, just read it carefully and run the
% examples
feats = mat2cell(B,m,n);
feats = feats(:);

end

function feature = processBlock(bstruct)    
    % I dont know what block_dct2 does:
    %feature = block_dct2(bstruct.data);
    % So I'll put in a place holder which returns a 1x200 'feature'
    % for each overlapping image block
    feature = repmat(mean(bstruct.data(:)), [1 200]);
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!