IPhone context: How do I extract palette information from an image?

Assuming you have a raw 24 bit RGB image and you want to find the number of times each color appears.

Assuming you have a raw 24 bit RGB image and you want to find the number of times each color appears: there are really 2 simple ways of doing this: my favourite is just to create an array of ints for each possible color, then just index into that array and ++ that method does use like 64 meg of memory tho. Another method is to create a linked list, adding to it each time a new color is encountered, the structs stored in the list would store the color and the number of times encountered, its slow to do all the accumulating cause you have to search the whole list for each pixel, but it would be quicker to sort by number of times used, as only colors actually used are in the list (making it more ideal for small images too) I like a compromise between the two: take say, red and green to index into an array of linked lists, that way the array is only 256k (assuming it just stores a pointer to the list) and the lists to search will be relatively short because its only the blue variants of the Red,Green color. If you were only interested in the SINGLE MOST used color, I would just store this in a "max color" variable, that I would compare with each time I iterated over a pixel and incremented a color, that way you don't have to go through the whole structure searching for the most used at the end.

Struct Pixel { byte R,G,B; } const int noPixels = 1024*768; // this is whatever the number of pixels you have is Pixel pixelsnoPixels; // this is your raw array of pixels unsinged int mostUsedCount = 0; Pixel mostUsedColor; struct ColorNode { ColorNode* next; unsigned int count; byte B; } ColorNode* RG = new ColorNode256*256; memset(RG,0,sizeof(ColorNode)*256*256); for(int I = 0; inext) { if(t->B == pixelsi. B) { break; } } if(!t) { t = new ColorNode; t->next = RGidx; RGidx = t; t->B = pixelsi. B; t->count = 0; } t->count++; if(t->count > mostUsedCount) { mostUsedCount = t->count; mostUsedColor = pixelsi; } } you might consider using a Binary Tree, or Tree of some kind too, rather than just searching through a list like that.

But I'm not too knowledgeable on that type of thing... Oh yeah... I forgot about memory management. You could just go through the whole array and delete all the nodes that need deleting, but that would be boring. If possible, allocate all the memory you would possibly need at the beginning, that would be 256k + sizeof(ColorNode) *noPixels ~= 256 + 2 to 3 times the size of your raw image data.

That way you can just pull nodes out using a simple stack method, and then delete everything in one foul swoop. Another thing you could do is also add the nodes to another link list for ALL allocated nodes as well, this increases the iterating process, adds data to Color node, and just saves having to iterate through the entire array to find lists to delete.

Developer.apple. Com/iphone/library/documentation/Cocoa/… – KennyTM Feb 10 '10 at 13:48.

The format is JPG: the image is the one I take from camera...

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions