Forcing one palette per Tiles

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
X-death
Posts: 11
Joined: 2015-06-23T08:59:51-07:00
Authentication code: 6789

Re: Forcing one palette per Tiles

Post by X-death »

Ok according to your reply you have not yet understand what a "tiles" mean.
Take this picture :

Image

and now here is the same picture divised into tiles :

Image

So a "tiles" mean a part of 8*8 pixel of the image.
Do I understand this so far?
Yes it's that ! :D
There are more combinations of colors than the contiguous 16 colors from the 176 colors?
Yes that's true ! thats why it's so hard to have a good result
So there are many many more possible colortables than 11.
Thats's why colormap generation is the critical part
Why are you using the unique colors in the order IM extracts them from the image. I presumed you had 11 fixed colortables.
[/quote]

Because i have not find yet the command for sort it by color and not by order.
colortable are not fixed it can be mixed and same color can be in another colortable for made the best result possible ( but it can be more than 16 colors in a colortable).

It's hard to explain haha 8)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Forcing one palette per Tiles

Post by snibgo »

X-death wrote:So the next step ( if it's possible) is to find the best colortable ( one of the eleven) for each tiles and apply it to the tiles.
I thought that eleven colortables (each containing 16 colors) were known, and the problem was to find which colortable ("-remap") to use for each 8x8 pixel tile.

Perhaps I was wrong. Perhaps the first problem is to find eleven colortables that are suitable for this image. Then the next problem can be solved: which of these colortables to use for each 8x8 tile.

If that is so, I don't know how to find the best eleven colortables. But we can easily find eleven colortables that may not be the best ones. Just take any area in the 15-bit RGB image, use "-colors 16" to reduce the area to 16 colours, "-remap" to the collection of 15-bit colours, and that is one colortable. Do this eleven times, and we have eleven colortables.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Forcing one palette per Tiles

Post by fmw42 »

Perhaps you can do what user snibgo said above for every tile and get the average color of each tile and find its closest color from your 176 colors. Correlate the color to the tile number. Then get the counts for the average colors and pick the 11 most frequent colors. Then for each of the 11 most frequent colors get one set of the 16 colors from any one of the corresponding tiles that belong to the average color to use for your 11 colortables
X-death
Posts: 11
Joined: 2015-06-23T08:59:51-07:00
Authentication code: 6789

Re: Forcing one palette per Tiles

Post by X-death »

Thanks.
I thought that eleven colortables (each containing 16 colors) were known, and the problem was to find which colortable ("-remap") to use for each 8x8 pixel tile.
Exactly !
For an Average result maybe i can made a sorted palette.
11 palette of 16 color sorted by color ( teinte ?) can be made a quite good result.
could you tell me the command for sort a palette with color instead of number ?
fmw42 wrote:Perhaps you can do what user snibgo said above for every tile and get the average color of each tile and find its closest color from your 176 colors. Correlate the color to the tile number. Then get the counts for the average colors and pick the 11 most frequent colors. Then for each of the 11 most frequent colors get one set of the 16 colors from any one of the corresponding tiles that belong to the average color to use for your 11 colortables
that a good ideat but seems to be hard to write the code.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Forcing one palette per Tiles

Post by fmw42 »

Correction: Just get the average color of each tile from the 176 colors remapped image and find the closest color from the 176 colors to the average color. Then make a list of the tile number and the closest of the 176 colors. You can use -fx to do an rmse computation to get the closest color (or use compare with a 1x1 pixel of that color with your SNES image). That should be easy. Then from the list, count how many times each color is used -- a histogram of the colors. You can append each of those colors into an image and just get the textual histogram and sort it by count (the unix sort command). Then select the 11 most used colors. Then find the first instance of each of the 11 colors in the list and find the tile number. Then get one of the tiles from that group of tiles. Use the 11 tiles for your 11 colortables.

see
http://www.imagemagick.org/Usage/files/#histogram
http://www.imagemagick.org/Usage/compare
http://www.imagemagick.org/Usage/transform/#fx_escapes

There is no way that I know to meaningfully sort rgb triplets by color. You can sort by intensity or you can convert to HSL and sort by Hue or Hue and Lightness or any combination you want. But I do not think that will produce a meaningful sort.
X-death
Posts: 11
Joined: 2015-06-23T08:59:51-07:00
Authentication code: 6789

Re: Forcing one palette per Tiles

Post by X-death »

Thanks for your correction.
but i need your help, i have writted the current code for output -metric to a txt file :

Code: Select all

:Comparetiles
compare -metric RMSE Tiles/tiles-%ntiles%.png Tiles/Temp/out-%pal%.png null: 2> result.txt
set /a pal+=1
if %pal% LSS %npal% goto Comparetiles
but only the first line of result.txt is used and it be removed and remplaced each time the function is called.
did IM have a special argument for not rewrite the file and just continue it ?

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Forcing one palette per Tiles

Post by snibgo »

Try:

Code: Select all

2>> result.txt
snibgo's IM pages: im.snibgo.com
X-death
Posts: 11
Joined: 2015-06-23T08:59:51-07:00
Authentication code: 6789

Re: Forcing one palette per Tiles

Post by X-death »

That works thanks :D
Post Reply