Hi, I want to reduce the size of a 3D image by averaging the values in 3D. For example if the image is 160*216*176. I wrote the code below to process the image to average the values in every 4*4*4 cube thereby creating a new matrix that is 40*54*44 in size.my code is below
X(1:40)=4;
Y(1:54)=4;
Z(1:44)=4;
A=mat2cell(imagestack_1,[X],[Y],[Z]);
average=cellfun(@mean2,A);
But this shows an error
Error using mat2cell (line 97)
Input arguments, D1 through D3, must sum to each dimension of the input matrix size, [160 216 176].'
Anyone who knows Please guide me!!

3 件のコメント

KSSV
KSSV 2017 年 3 月 14 日
What version you are using? Are you sure of size of imagestack_1 ? It worked for me without error on random data of size 160*216*176.
Sandhiya Prakash
Sandhiya Prakash 2017 年 3 月 14 日
I am using MatlabR2016a.
Sandhiya Prakash
Sandhiya Prakash 2017 年 3 月 14 日
I think i must give variable in which 3D image is stored instead of imagestack_1. Kindly guide me.I am new to matlab.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 14 日

0 投票

You probably had previous values in your X, Y, or Z, making them longer than what would be created with just the above code.

6 件のコメント

Walter Roberson
Walter Roberson 2017 年 3 月 14 日
Example:
imagestack_1 = rand(160, 216, 176);
X = 4 * ones(1,40);
Y = 4 * ones(1,54);
Z = 4 * ones(1,44);
A = mat2cell(imagestack_1, X, Y, Z);
average = cellfun(@mean2, A);
Sandhiya Prakash
Sandhiya Prakash 2017 年 3 月 14 日
Thank you sir..its working.I hav anothe doubt.I am having a 160*216*176 input 3D image. For a given voxel i need to consider 26 neighbouring 3x3x3 patch.(now 27 scalar values)Then consider all 26 neighbouring conventional 3x3x3 patches and compute average intensity for all these neighbouring patches.(So totally i have 53 scalar intensity values).How to perform this?
Walter Roberson
Walter Roberson 2017 年 3 月 14 日
What is the difference between a "neighbouring 3x3x3 patch" and a "conventional 3x3x3 patch" ?
Is that 53 scalar intensity values per voxel, or 53 total over the entire data?
It would help if you could give the calculation formula in terms of indexes. For example,
conventional = M(I-1:I+1, J-1:J+1, K-1:K+1);
mean_conventional = mean2(conventional);
unconventional = conventional;
unconventional(2,2,2) = []; %center point not included in mean
mean_unconventional = mean2(unconventional);
Sandhiya Prakash
Sandhiya Prakash 2017 年 3 月 14 日
編集済み: Walter Roberson 2017 年 3 月 14 日
Thank U sir! I have a doubt in looping.
my code is
for I=1:160
for J=1:216
for K=1:176
conventional = data(I-1:I+1, J-1:J+1, K-1:K+1);
mean_conventional = mean2(conventional);
unconventional = conventional;
unconventional(2,2,2) = []; %center point not included in mean
mean_unconventional = mean2(unconventional);
end
end
end
but it gives error like,
Subscript indices must either be real positive integers or logicals.
Walter Roberson
Walter Roberson 2017 年 3 月 14 日
The boundary points do not have 27 neighbors. You should either calculate only on the interior, or you should define what you want the boundary calculation to be.
SojM
SojM 2020 年 7 月 17 日
After the resize of the matrix, how to save new 3D matrix as stack of 2D images?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by