Azzera filtri
Azzera filtri

Representative Colors from image

2 visualizzazioni (ultimi 30 giorni)
Algorithms Analyst
Algorithms Analyst il 26 Feb 2013
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..

Risposte (1)

Walter Roberson
Walter Roberson il 26 Feb 2013
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?
  1 Commento
Algorithms Analyst
Algorithms Analyst il 26 Feb 2013
I developed a some code here which divides the image into blocks and finds the average of pixel color in block as
rgbimage=imread('lena.bmp');
fun=@(block_strct) mean2(block_struct.data);
img=BLOCKPROC(rgbimage,[64 64],fun);
imshow(img,[]);
this shows the 8x8 Blocks in image.Is this right I am not sure becasue I wanted to put most representative colors as said in this link and wanted to find the tiny image(<http://en.wikipedia.org/wiki/Color_layout_descriptor>) thanks

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by