Image Quantisation

Hi,

I am looking for a compatible image quantiser for solar2d. An algorithm that reduces the number of colours in an image from say 5000 colours to 255 colours. I had a look at impack and I don’t think it has anything implemented. Before I start the process of coding one up just wanted to check there isn’t a plugin with one already done.

Thanks
David

Just a question … what is the main purpose of that? is it just to reduce image size, or something else

Hi kakula… Image Quantisation reduces the number of colours in a image with the minimum perceptual. difference to the viewer. So for instance if an image has 5000 colours after quantisation say to 255 colours the image is close to the original. Used in most image processing packages GIMP, Paint shop pro etc its purpose is in this instance is to reduce the vectorisation overhead in my app PAINTIFY

see this in wikipedia for more details

Hopefully there is a plugin that can do it although it will be strange too write something just for this image processing function … hopefully someone will know

Thanks

Okay looks like I have solved it …

I missed the posterise filter in filter and effects… basically a image quantiser using the GPU, I think… certainly good enough for what I need… super fast… just choose the bits per channel you want and it quantises an image in a heart beat to the colour level … Well Solar2d knew you would be able to do it … onwards …

Topic closed

Actually not totally solved … does anybody know what colorsperchannel actually does in the posterise filter as it gives different results based on the input image ?

Thanks
David

That will divvy up each channel into regions, although with 256 you wouldn’t notice any differents. So say with 8, values like from 0-.124999… would snap to 0, from .125 to .24999… to .125, etc.

An effect wouldn’t really be able to do this since it can only write one output per pixel, and it would be expensive to search many neighbors.

Didn’t have anything specifically dedicated to this in Impack, no, since I was largely just exposing other APIs. I believe GIFs do in fact do this, though, so it might be possible to load an image, save it out to a GIF (in memory), then reload it.

Thanks StarCrunch … Thats a great idea about gifs I hadn’t thought of that … very innovative. The operation is a one off this at the start of processing so that will work great , I will give it a go and check it works okay.

On the posterise function, I am still a little unclear about coloursperchannel… are the channels r,g,b,a or r,g,b… what are the values 12499 and 24999 in your description ?

Many thanks for the GIF idea
David

1 Like

I mentioned 8 as the choice, so in this case I was just listing off the decimal values of 1/8 (or almost, in the …999 cases), 2/8, and so on.

Sorry being thick, didn’t see the tiny decimal point , need glasses, so the posterise just quantises each r,g,b,a channel in decimal form (0-1) by what ever value of colorsperchannel you choose

So if I want an image with 255 unique colours , what value of colorsperchannel do I use ? is that dependent on the image being processed.

Many Thanks
Just trying GIF option

Just an update , finished coding the GIF idea all works well and is quite fast for 255 image quantisation. Couldn’t get memory GIF swap working so used a file instead. Typical example attached

Q2

255 Unique Colour Image Quantised Result shown above

rose

Original image 3400 Unique Colours shown above

Happy to share code if anyone else needs it in the future, will bung it in a lua library. Thanks to impack …a great plugin !!!
Onwards

2 Likes