Pin-art - or how to create images with very few colors

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Locked
Plate1x1
Posts: 2
Joined: 2012-03-05T14:35:40-07:00
Authentication code: 8675308

Pin-art - or how to create images with very few colors

Post by Plate1x1 »

Hi, everybody! (First post.)

I was invited to ask this question here by Anthony, and I hope that means it is an interesting question with some good answers. :)

I am writing concerning this section:

http://www.imagemagick.org/Usage/quantize/#remap

I have been looking into dithering with a very limited palette. I started out being inspired by how you can do this in Photoshop (please watch the video to see the type of effect I am looking to achieve):

http://www.youtube.com/watch?v=USzbw90wOKM

However, I do not want to shell out for a Photoshop license just for this, and Gimp doesn't do this at all well. It would seem that Gimp and ImageMagick use similar (or identical) code for this. The most obvious way to show this is the color green. In the Photoshop example, green is emulated using 50/50 blue and yellow pixels. Using the open source code, you end up with pure yellow.

What I have tried to do is things like this:

Code: Select all

convert myimage.png  -dither Riemersma  -remap 5colors.png remap_Riemersma_myimage.png
(5colors.png contains a black, white, red, yellow and blue pixel like in the Photoshop example.)
(Version: ImageMagick 6.6.0-4 2011-06-15 Q16 on Ubuntu Linux.)

I started out with photos, but I have used simpler images wih pure colors to try to exaggerate and pinpoint the problems. Feel free to use a simple file with some simple areas of color. Some colors will work relatively fine, but as an example, green will not. Or use a picture with some green in the background.

Now, it is my personal "tragedy" that I can't get this rather obscure thing to work, I can always get my hands on some Photoshop somehow, but there is a more important problem here: If the code can not blend blue and yellow to get green, how can we trust it to do anything properly? There should be considerable room for performance improvement which should be relevant for people using more colors as well.

I am hoping that I have simply done a stupid mistake. That will save me craving Photoshop, at least for this application. :)

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Pin-art - or how to create images with very few colors

Post by anthony »

First here are the colors: black, white, blue, red, and yellow....

Code: Select all

echo "P3 1 5 1   0 0 0    1 1 1   0 0 1  1 0 0   1 1 0" > colors_5.ppm
Now the biggest problem with this color map is a distinct shortage of green. But that really should not be too much of a problem.

"Riemersma" dither is the default dither. so..

Code: Select all

convert  rose: -remap colors_5.ppm result.gif
This works though for the scale the result is not really great.

In your test image blobs.png (privately sent to me) you got very bad results. Not really surprising. Their is little for error correction dither to actually work with in that example, so it did very badly.

Generally IM quantization was designed with LOTS of colors in mind. This is an area that needs some redesign for the 'special' situations of very small numbers of colors in both image and pallette.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Plate1x1
Posts: 2
Joined: 2012-03-05T14:35:40-07:00
Authentication code: 8675308

Re: Pin-art - or how to create images with very few colors

Post by Plate1x1 »

Thanks for the helpful input. Here is a follow-up for anybody trying to do similar things:

The distinct lack of green: Yes. Things work a lot better with a green in the palette.

As for other colors: One should really experiment with the available colors. Using gray or orange pins/beads/pixels may give a pleasing result for a desert sunset, but horrible results for a face. I had an initial choice of 12 colors, but I ended up using 8 of them. Trial and error is the way to go. But ImageMagick is definitely happier when you have a more complete set of "primary" colors, or a selection of colors similar to those in the picture at the very least.

Dithering type: FloydSteinberg, period. This produced very similar results as diffusion dithering about 100 % in a version of Photoshop I had access to. In Photoshop Elements 8 (I think it was) you can adjust the diffusion percentage, but 100 % is what looks best for this, so I decided to use ImageMagick. (For the record, it works a lot better than Gimp, IMHO.) You don't want areas with the same color, but rather a seemingly random mess of colors until you take a step back and see the big picture, so as much diffusion as possible is what you want.

This is the command to use:

Code: Select all

convert MyInputImage.png  -dither FloydSteinberg -remap MyPalette.png  MyPinartOutputFile.png
You will probably want to do a bit of manual editing after this. This can highlight smaller details, and tidy up areas where ImageMagick generates stripe- and checkerboard-patterns.

Then, of course, you generate your shopping list:

Code: Select all

convert MyPinart.png  -format %c histogram:info:-
This gives you a neat list of how many brightly colored pieces of plastic you need in each color. Brilliant elegance. :)

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Pin-art - or how to create images with very few colors

Post by anthony »

Plate1x1 wrote:Dithering type: FloydSteinberg, period.
Note that FloydSteinberg dithers is top down, though Im does use a back and forth pattern to it. However it will only spread error correction downward.

As such form some images you may like to try flipping/transpose/transverse (upside down, or diagonal mirrors) the image and try to dither it that way. Sometimes it will come out better!

Landscapes for example has a distinct horizontal change betwwn sky and and land, and transposing the image may actually improve results. Or it may make it worse. Actually I have not tried, but it is worth trying.

Code: Select all

convert MyPinart.png  -format %c histogram:info:-
This gives you a neat list of how many brightly colored pieces of plastic you need in each color. Brilliant elegance. :)
Nice tip. Didn't occur to me, though I knew about how to count colors.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Pin-art - or how to create images with very few colors

Post by anthony »

Hmmm... I just been playing a little 'minecraft'. And I am suprised that we have not seen much 'blocky art' in that game as of yet. But it would be a similar deal.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked