MATLAB: How to call a function inside cell array

cell arraysMATLAB

Dear Team ,
My work is as follows , I've to divide an RGB image (256 x 384) into 6 equal sized(each block size 128 x 128) non-overlapping blocks and apply functions like mean, median on R plane , G plane and B plane separately for each block and compare it with another similar block partitioned image.
My doubts:
1. I used cell array for block partition of input image using below code.
img = imresize(I1, [256 384]);
blockSize = 128;
C = mat2cell(img,blockSize*ones(1,size(img,1)/blockSize),blockSize*ones(1,size(img,2)/blockSize),3);
Now i 've find the mean and median of R plane, G plane and B plane for each block. I used the below code
D = cell(2,3);
for i =1:2
for j = 1:3
for k = 1:3
D{i,j} = mean2(C{k}(:,:,1)); /*In this step - I've to find mean, median in one go for each cell - is it possible to call a function here ? I also tried using cellfun(@(x) mean2(x(:)),C) but i dont know how to modify this step for each plane of an RGB image */
end
end
end
/* I'm not getting my output here in expected format 🙁
My expected output in cell array format
Block 1 = [Rmean Gmean Bmean Rmedian Gmedian Bmedian]
Block 2 = [Rmean Gmean Bmean Rmedian Gmedian Bmedian] … …
Block 6
2. How to compare blocks of first image against the blocks of second image (one to one comparison) Block 1 (Image 1) –> Block 1 (Image 2)
Block 2 (Image 1) –> Block 2 (Image 2) ….
Block 6 (Image 1) –> Block 6 (Image 2)
Could you suggest me an algorithm for block matching so that i could take it up as a reference for my work . My guide has asked me to go about one to one block matching but i'm bit puzzled about cell array comparison for image retrieval.How does this comparison help in retrieving relevant images?. Request your suggestion and guidance on this.
Regards, Malini

Best Answer

I think your approach is way more confusing that it needs to be. First of all there is no reason (the badly named) D should be a cell array rather than just a simple numerical array. Secondly you could get the means and medians each in one call to blockproc() - no need for for loops, though with only 9 iterations they don't take much time.