how to call a function inside cell array
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
It looks like it would be much easier if you also split the R,G,B, layers into separate cells. For example, using FEX:mat2tiles
C=mat2tiles(img,[128,128,3]);
Means = cellfun(@(c) mean(c(:)), C);
Medians = cellfun(@(c) median(c(:)), C);
Instead of having separate variables Block1...Block6, it would also be better if you combined all the block data into a 2x3x6 array,
BlockData=cat(3,Means,Medians);
If you do this for several images, you can compare the BlockData arrays as you would any other arrays, e.g.,
BlockDataImage1 >= BlockDataImage2
BlockDataImage1 ~= BlockDataImage2
etc...
2 Commenti
Malini
il 12 Mar 2013
Hi Malini
Is there any other reason for choosing mat2tiles
The only reason for using mat2tiles is that it has an easier interface when all the blocks are of the same size. My good-natured subjective opinion is that the call to mat2cell in your code is really long and ugly whereas mine is really easy and concise :-) But yes, you could apply my same suggestion using mat2cell instead.
If speed is critical for you, however, as you seem to be implying, I would not recommend cutting things into cells at all, nor would I recommend blockproc. I would just apply your triple for loop directly to 'img'
e=0:127;
Means=zeros(2,3,3); Medians = Means;
for i=[1,129]
for j=[1,129,257]
for k=1:3
t=img(i+e,j+e,k);
Means(i,j,k)=mean(t(:));
Medians(i,j,k)=median(t(:));
end
end
end
Could you kindly help me out with the second query in my above question.
As far as I know, I covered everything about that in the second part of my Answer.
Categorie
Scopri di più su Blocked Images in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!