2016-04-09 8 views
1

私は画像から得た1134行1134行のサイズの行列を持っています(imread関数を使用しています)。今私は、分析のために画像を3行3列の行列に分割したいと考えています。そのためには、mat2cellを次のように使用しようとしました。mat2cell入力引数のエラー

image = imread('C:\Users\ka\Desktop\test\step.png'); 
X = mat2cell(image, [3], [3]); 

しかし、私はエラーを得た:

Error using mat2cell (line 97) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [1134 1134].'

任意の助けをいただければ幸いです。

答えて

0

エラーメッセージには実際にすべてが表示されます。mat2cellへの入力のそれぞれは、イメージ全体のサイズ(この場合は1134(および1134))の合計にする必要があります。詳細については、documentationを参照してください。私はあなたが何をしたいと考えてい

は次のとおりです。

sz = [1134 1134]; % size of input image 
I = rand(sz); % make up some random data for testing 
chunk_size = [3 3]; % your desired size of the chunks image is broken into 
sc = sz ./ chunk_size; % number of chunks in each dimension; must be integer 

% split to chunk_size(1) by chunk_size(2) chunks 
X = mat2cell(I, chunk_size(1) * ones(sc(1),1), chunk_size(2) *ones(sc(2),1)); 

だが、必要に応じて出力されていることを確認してみましょう:

size(X) % == sc 
size(X{1}) % == chunk_size 
sum(chunk_size(1) * ones(sc(1),1)) % 1134, as required 
sum(chunk_size(2) * ones(sc(2),1)) % 1134, as required 
+0

ありがとうございました。あなたの助けに。私はたくさんのことを学んだ。 –

関連する問題