コードのあなたのラインが大きく、それが動作しても、私は、コードをより簡単にお勧めしますので、あなたは、パッチの一部の地域かどうかを確認することができます(のインタレストROIのレジオそれを呼びましょう)が低下画像
例外:ここ
im = rand(150, 150); % 150x150 random "image"
[nrows, ncols] = size(im);
% center coordinates of 4 Patches
centerCoord = [50,50; 100,50; 50,100; 100,100];
patchSize = 32;
% results will be stored in matrix Patches
Patches = zeros(patchSize, patchSize, size(centerCoord,1));
for i=1:size(centerCoord,1)
top_left = ceil(centerCoord(i,:) - [patchSize/2, patchSize/2]);
bottom_right = top_left + [patchSize-1, patchSize-1];
if any(top_left <= 0) || any((bottom_right - [nrows, ncols]) > 0)
%some regions of the patch fall outside the image. Handle this case here.
else
Patches(:,:,i) = im(top_left(1):bottom_right(1), top_left(2):bottom_right(2));
end
end
パッチは、あなたの4つのパッチを含む32x32x4行列です。
あなたの 'centerCoord'を、各パッチの中心を格納するマトリックスに変換します。その後、各パッチにコードを適用して保存します(各パッチのサイズは同じです(32 x 32 x Nパッチ)の行列に保存することができます) –