下面是滿足您的條件的解決方案,除第一個點外
使用IM2COL函數將圖像中不同的圖像塊排列成列,然後將函數應用於存儲單元數組結果的每列。
當然,如果所有的塊裝入內存這僅適用,否則,你將不得不手動編寫一次只抽取一個街區,並以這種方式處理它的代碼...
%# read image
img = im2double(imread('tire.tif'));
%# blocks params
sizBlk = [8 8];
numBlk = ceil(size(img) ./ sizBlk);
%# extract blocks
B = im2col(img, sizBlk, 'distinct');
B = reshape(B, [sizBlk size(B,2)]); %# put blocks on the 3rd dimension
B = squeeze(num2cell(B,[1 2])); %# convert to cell array
B = reshape(B, numBlk); %# reshape as blocks overlayed on image
%# process blocks
myFcn = @(blk) [mean2(blk) std2(blk)]; %# or any other processing function
I = cellfun(myFcn, B, 'UniformOutput',false);
%# in this example, we can show each component separately
subplot(121), imshow(cellfun(@(c)c(1),I)), title('mean')
subplot(122), imshow(cellfun(@(c)c(2),I)), title('std')
另外,您還可以使用BLOCKPROC功能,但你必須把它多次,每次計算一個要素:
%# compute one feature at a time
b1 = blockproc(img, sizBlk, @(b)mean2(b.data), 'PadPartialBlocks',true);
b2 = blockproc(img, sizBlk, @(b)std2(b.data), 'PadPartialBlocks',true);
%# combine into cellarray of features
II = arrayfun(@(varargin)[varargin{:}], b1, b2, 'UniformOutput',false);
%# compare to previous results
isequal(I,II)
我認爲你的單元格數組包含「複雜」的數據,所以你不能把你的函數包裝到['cell2mat']中(http://www.mathworks.de/help/techdoc/ref/cell2mat.html )並使用'blockproc'? –
這就對了@Jonas。我正在尋找一種解決方案,它不會對處理函數(例如類型,內容等)的輸出單元格做出任何假設 –