Reducing a matrix size by averaging blocks within the matrix.
Show older comments
I have a 1024x1280 matrix. I want to reduce this to a smaller matrix of 512x640 by taking an average of 2x2 blocks and making that a 1x1 block.
e.g. say the first 2x2 block within the large matrix is [1,3; 7,9]
then this would average that 2x2 block to a 1x1 block of [5]
I have no idea how to do this so any help would be greatly appreciated.
Accepted Answer
More Answers (2)
Image Analyst
on 4 Nov 2015
I just answered this 2 days ago in http://www.mathworks.com/matlabcentral/answers/252349#answer_198175 where I said:
If you have the Image Processing Toolbox (use "ver" to check), then you can use blockproc():
myData = rand(1024,1280); % Sample data
% Define the mean function to be used with blockproc.
myMeanFunction = @(block_struct) mean(block_struct.data);
% Get the means by each 2-by-2 block.
blockMeans = blockproc(myData, [2, 2], myMeanFunction)
You can also use
smallArray = imresize(bigArray, 0.5);
Categories
Find more on Neighborhood and Block Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!