% obtain small windows of the image (say 16x16 windows and possibly using the crop function)
[rows columns] = size(B);
blockSizeR = 25; % Rows in block.
blockSizeC = 25; % Columns in block.
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
image3d = zeros(wholeBlockRows, wholeBlockCols);
sliceNumber = 1;
dataStruct = [];
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
col1 = col;
col2 = col1 + blockSizeC - 1;
oneBlock = B(row1:row2, col1:col2);
subplot(4, 4, sliceNumber);
imshow(oneBlock);
caption = sprintf('Block #%d of 16', sliceNumber);
title(caption);
drawnow;
dataStruct = [dataStruct, oneBlock(:)];
sliceNumber = sliceNumber + 1;
end
end
我试图从100x100像素图像中提取16个25x25子窗口,然后将每个子窗口转换为125列向量,但是我附加所有这些向量的数据结构似乎是625 x 16而不是125 x 16。
子窗口似乎在图中显示得很好。关于我哪里出错的任何线索都会非常感激。
答案 0 :(得分:0)
您可以使用mat2cell
和cellfun
:
dataStruct = mat2cell( B, blockSizeR * ones( 1, wholeBlockRows ), ...
blockSizeC * ones( 1, wholeBlockCols ) );
dataStruct = cellfun( @(x) x(:), dataStruct, 'uni', 0 );
dataStruct = [dataStruct{:}];