I have 100 images each of size 512 by 512 stored in a cell array.
I want to find the max value and indices for each pixel location by searching all the images.
Here is the sample representation:
My code:
imgs = cell(1,5);
imgs{1} = [2,3,2;3,2,2;3,1,1];
imgs{2} = [2,3,1;4,2,3;2,2,1];
imgs{3} = [3,2,1;5,3,5;3,2,3];
imgs{4} = [4,4,2;5,3,4;4,2,2];
imgs{5} = [4,5,2;4,2,5;3,3,1];
[nrows, ncols] = size(imgs{1});
maxVal_Mat = zeros(nrows,ncols);
maxIdx_Mat = zeros(nrows,ncols);
for nrow = 1:nrows
for ncol = 1:ncols
[maxVal_Mat(nrow, ncol), maxIdx_Mat(nrow, ncol)] = max(cellfun(@(x) x(nrow, ncol) , imgs));
end
end
maxVal_Mat =
4 5 2
5 3 5
4 3 3
maxIdx_Mat =
4 5 1
3 3 3
4 5 3
Any ideas on how to optimize this code to save execution time and memory.
Note: This is a sample demonstration of the problem, the original cell and matrices are quite large.
Thanks,
Gopi