Coarsening a 2D or 3D grid in Matlab
22 次查看(过去 30 天)
显示 更早的评论
Hello,
I have several fields/arrays that are either 2D or 3D. I am looking for a method in which I coarsen the resolution by a factor of 3^2. For example, if I had 699*699 pixels in the old array, I would like to reconstruct that variable such that each pixel in the new array is an average of 3x3 pixels in the old array. What is the best way to do this for 2D as well as 3D arrays?
Thanks.
0 个评论
回答(1 个)
Vinai Datta Thatiparthi
2020-9-17
Hi Sai,
"..each pixel in the new array is an average of 3x3 pixels in the old array.."
inputData = reshape(1:25,5,5);
kernel = ones(3,3);
outputData = conv2(inputData, kernel, 'valid')
% From your description, I felt it is best to set the shape parameter to 'valid'.
% If this doesn't work for you, explore other shape options ['full' & 'same'] as well.
inputData3D = reshape(1:125,5,5,5);
kernel = ones(3,3);
outputData3D = convn(inputData3D, kernel, 'valid')
Hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!