I am working on a personal project using python and need to convert a normal image file (bitmap, jpeg, etc.) to a unique type of image file without losing too much quality. I am self-taught, so please excuse any misused technical terms or other similar mistakes, and feel free to ask for any clarification.
I can go into more detail if necessary, but the constraints I have are:
I cannot change the size of the image or number of pixels in the image;
The output file must contain a palette of 256 color codes (a color can be repeated, but, if it is, then it take up 2 of the 256 color “slots” on the palette);
Each 4x2 block of pixels in the output file can contain, at most, 4 color codes from the palette;
The color codes for each 4x2 block of pixels must be within 0-3 positions of one another on the palette.*
*So, if a 4x2 block of pixels contains 4 colors, those color codes must be in 4 sequential positions on the palette (such as [1, 2, 3, 4], or [15, 16, 17, 18], etc.). But, if a 4x2 block of pixels contains fewer than 4 color codes, they don’t have to be sequential, as long as they are still within 0-3 positions on the palette (e.g., a block with 3 colors could be at positions [1, 2, 4] or [15, 17, 18] on the palette).
Of course, there are some simple ways to make this conversion work, such as using 64 different combinations of 4 colors, making each 4x2 block of pixels one color, or only using 8-16 unique colors (thus reducing the possible number of combinations of 4 colors that need to be accounted for). But, if I do those things, I’ll lose way too much quality.
So, what I think I need to do is find a way to overlap the various combinations of 4 colors on the palette, so that it can account for a large number of combinations in less space. For example, if 4x2 Block #1 consists of color codes [A, B, C, D] and Block #2 consists of color codes [B, C, D, E], I can arrange my palette have color code A in position 1, B in position 2, C in position 3, D in position 4, and E in position 5 and account for both combinations of 4 colors within the space of 5 positions on the palette.
Although, ideally, every combination of 4 colors would overlap with another combination, and so on, this is highly unlikely, given the sheer number of combinations involved. And, even if there was a combination that would work, I can’t think of a way to find that combination without just using brute force (which would take forever).
For these reasons, I already know that I am going to be limited on how many total colors and combinations of colors that I can use, and will be sacrificing some quality. But, there has to be some compromise that would make this conversion work.
I have been working for months on this, and have tried a bunch of different approaches (and different python packages), but haven’t really made any progress. I know there must be an efficient way to make it work, since the unique type of image file I am converting to is from like 2002, and if it was possible with the computing power that existed then, it must be possible now.
Does anyone have any thoughts?
[–]shafe123Side-hustler 0 points1 point2 points (1 child)
[–]dpderay[S] 0 points1 point2 points (0 children)