Representative Colors from image
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone
What I am trying to do is I have divided my image into 8x8 blocks and I want to find the most representative colors in the image as a tiny image the most simple method is the average of pixel color in block.My code is
rgbImage = imread('lena.bmp');
% For demo purposes, let's resize it to be 64 by 64;
rgbImage = imresize(rgbImage, [64 64]);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
ca=mat2cell(rgbImage,8*ones(1,size(rgbImage,1)/8),8*ones(1,size(rgbImage,2)/8),3);
Now this cell array produces the blocks.and I want to compute the average of the pixel colors in block how can I do this.I have tried this code as well but I am not sure.
fun=@(block_struct) mean2(block_struct.data);
img=blkproc(rgbimage,[8 8],fun);
not sure this is correct or not..
0 个评论
回答(1 个)
Walter Roberson
2013-2-26
blkproc() does not pass a struct into the invoked function. What you have coded for your function would be for blockproc().
You could call cellfun() for your ca cell array, or you can skip the creation of ca and use blockproc() instead.
You need to figure out what you want to do about the fact that your data is 3 dimensional (multiple color planes) but you are using mean2(). Is that what you want?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!