Using ImageMagick

Talk about development tools here

Moderator: BigEvilCorporation

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Using ImageMagick

Post by r57shell » Fri Jun 07, 2013 5:28 pm

I don't know, why there is no such topic. So, I will be one who start it.
Note: \ in the end of line, means to continue line

Quantization and Color reducing
Anyway, for one who interested in imagemagick way:

First, to generate Genesis Colors, according to this:
Put in file genesis_colormap.txt such info:

Code: Select all

# ImageMagick pixel enumeration: 8,1,255,Gray
0,0: (0,0,0)  
1,0: (9,9,9)  
2,0: (16,16,16)  
3,0: (22,22,22)  
4,0: (27,27,27)  
5,0: (32,32,32)  
6,0: (38,38,38)  
7,0: (47,47,47)
Next, build Color map

Code: Select all

convert -size 32x16 xc: \
   -channel R genesis_colormap.txt -fx "v.p{i&7,0}/47*255" \
   -channel G genesis_colormap.txt -fx "v.p{j&7,0}/47*255" \
   -channel B genesis_colormap.txt -fx "v.p{(i>>3)|((j>>3)<<2),0}/47*255" \
   -scale 600%% -filter point genesis_colormap.png
Image

And after it, if you want to translate image into Genesis Colors:

Code: Select all

convert my_img.png -dither Riemersma -remap genesis_colormap.png my_img_gen.png
And if you want to reduce colors:

Code: Select all

convert my_img.png -dither Riemersma -colors 15 +dither -remap genesis_colormap.png my_img_15.png
Original, Genesis colors, Genesis 15 colors, Genesis 30 colors:
Image Image Image Image

Almost all settings:

Code: Select all

сonvert my_img.png -colorspace <colorspace> -quantize <colorspace> -dither <dither> -colors <number> +dither -remap genesis_colormap.png my_img_gen.png
Colorspaces: RGB, YCrCb, YUV, Lab, HSL, and many others...
Dither: Riemersma, FloydSteinberg, None.

Two pass:

Code: Select all

сonvert my_img.png -colorspace <colorspace> -quantize <quantize> +dither -colors <number> -unique-colors _tmp_map.png
сonvert my_img.png -quantize <quantize> -dither <dither> -remap _tmp_map.png my_img_gen.png
I don't know why, but two pass method gives another result.
If someone knows how to set dither strength, then please, let me know too. :)

Random Maps Generation
This is something, that I tested some months ago.
Example result:
Image

I have done it with command:

Code: Select all

convert -size 1000x1000 plasma:gray50-gray50 -blur 0x2 \
                 -channel G -auto-level +channel -set colorspace sRGB \
                 tiles.gif -virtual-pixel tile  -fx "u[floor(7.999*u.g)+1]" \
                 map.png
tiles.gif:
Image

How does this work:
1) ImageMagick generates fractal "plasma": http://en.wikipedia.org/wiki/Diamond-square_algorithm
2) Next, gray channel maps into several levels (7 in this example).
3) Each level will correspond to certain layer (dirt, sand, spice...)

Result of this program obviously rough. But, with making some improvements, and may be pre/post processing, you can get good results.

One more example:

Code: Select all

convert -rotate 45 -size 1415x1415 -seed 12 plasma:gray50-gray50 -blur 0x2 \
                 -channel G -auto-level +channel -set colorspace sRGB \
                 -crop 1000x1000+207+207 -fx 'floor(8.7*u.g)/8'  map1.png
convert -rotate 45 -size 1415x1415 -seed 12 plasma:gray50-gray50 -blur 0x2 \  
                 -channel G -auto-level +channel -set colorspace sRGB \
                 -crop 1000x1000+207+207 \
                 tiles.gif -virtual-pixel tile -fx 'u[floor(8.7*u.g)+1]'  map2.png
Grayscale - layers map, and resulting map.
Image Image
Last edited by r57shell on Sat Jun 08, 2013 8:02 pm, edited 5 times in total.
Image

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Fri Jun 07, 2013 6:22 pm

Finding common palette
Just combine all images into one.
http://www.toptenz.net/wp-content/uploa ... acters.png

You can make it in any editor, or use ImageMagick.

Stack images vertical:

Code: Select all

convert img1.png img2.png img3.png ... img_n.png -append out.png
Or stack images horizontal:

Code: Select all

convert img1.png img2.png img3.png ... img_n.png +append out.png
Or make matrix with three columns from images:

Code: Select all

convert \
 ( img1.png img2.png img3.png +append) \
 ( img4.png img5.png img6.png +append) \ 
 ( img7.png img8.png img9.png +append) \
 ... \
 -append out.png
And then, after you combine all images into one, just reduce colors.
Image
And get colors:

Code: Select all

convert mortalkombat_16.png -format
 %c histogram:info:-
It's output:

Code: Select all

    302593: (  0,  0,  0) #000000 black
    234819: ( 49, 49, 49) #313131 srgb(49,49,49)
     80894: ( 49, 49, 87) #313157 srgb(49,49,87)
     88098: ( 87, 49, 49) #573131 srgb(87,49,49)
     88066: ( 87, 87, 49) #575731 srgb(87,87,49)
     60004: ( 87, 87, 87) #575757 grey34
     42590: ( 87, 87,174) #5757AE srgb(87,87,174)
     31732: ( 87,146,174) #5792AE srgb(87,146,174)
     32211: (119,119,119) #777777 srgb(119,119,119)
     54173: (146,119, 87) #927757 srgb(146,119,87)
     67456: (174, 87, 49) #AE5731 srgb(174,87,49)
     52573: (174,146,146) #AE9292 srgb(174,146,146)
     76458: (206,146, 87) #CE9257 srgb(206,146,87)
     57355: (206,206,174) #CECEAE srgb(206,206,174)
     41698: (255,255,206) #FFFFCE srgb(255,255,206)
Or get colors image: Image

Code: Select all

convert mortalkombat_16.png -unique-colors -filter Point -scale 1600% mortalkombat_16_colors.png
Some two colors was remapped into one, so on this image to get 16 colors, I will need to set "-colors" parameter to 17.
Image
Last edited by r57shell on Sat Jun 08, 2013 7:44 pm, edited 1 time in total.
Image

Chilly Willy
Very interested
Posts: 2816
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Jun 07, 2013 7:38 pm

Great posts... some of us use imagemagick and don't think about it, but others could use hints on doing stuff we take for granted. I use imagemagick all the time, but never thought to start a thread on it.
:?

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Sat Jun 08, 2013 7:29 pm

hi ,
First thanks for this tuto , i want to use this way now :D
but when i write this code :

Code: Select all

convert -size 32x16 xc: \
   -channel R genesis_colormap.txt -fx "v.p{i&7,0}/47*255" \
   -channel G genesis_colormap.txt -fx "v.p{j&7,0}/47*255" \
   -channel B genesis_colormap.txt -fx "v.p{(i>>3)|((j>>3)<<2),0}/47*255" \
   -scale 600%% -filter point genesis_colormap.png
it will send me this error :

convert.exe no encode delegate for this image format ...
i sue the lastest version : ImageMagick-6.0.2-Q16

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Sat Jun 08, 2013 7:32 pm

Latest version: ImageMagick-6.8.5
I use: ImageMagick-6.8.3
Note: \ in end of line, means Continue line!
I will add this note in beginning

You can skip this step, just download resulting image.
Image

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Sun Jun 09, 2013 10:13 am

Thnaks you very much !
Now it works very well :P

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Sun Jun 09, 2013 1:32 pm

did you have a way for convert an image into 30 color mode but with 8*8 tiles use only one palette?
Because with this way the palette are mixed into one tiles.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Sun Jun 09, 2013 3:00 pm

bastien wrote:did you have a way for convert an image into 30 color mode but with 8*8 tiles use only one palette?
It is very complicated problem, and very specific. I don't know "best" way.
But you can:
1) Find 30 colors palette
2) Split 30 colors into two palette depending on your things
3) Map image into each palette independent.
4) Mix by tile. I mean, select tile yourself.
But even splitting 30 colors into two palette has n! / ((n - m)! * m!) = 155117520 variants :).
See this topic, for some another tools.
Image

frederic
Interested
Posts: 23
Joined: Tue May 28, 2013 7:32 pm
Location: France

Post by frederic » Mon Jun 10, 2013 1:04 am

bastien wrote:did you have a way for convert an image into 30 color mode but with 8*8 tiles use only one palette?
Because with this way the palette are mixed into one tiles.
I made a Perl script that does that. The script tries to optimize the palettes so that the image is not altered too much. See this post: viewtopic.php?p=20127#20127.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Mon Jun 10, 2013 3:43 pm

ImageMagick for ActiveState Perl

How to make ImageMagick work with Perl.

For Unix: http://www.imagemagick.org/script/perl-magick.php

For Windows:
1) Download ImageMagick with suffix "-dll.exe" installer. Remember x68 or x64.
2) Install with options: install for ActiveState Perl and remember version.
3) Download ActiveState Perl version needed for ImageMagick.
4) Open "cmd.exe" (WIN+R "cmd.exe")
5) Write "ppm install <path to ImageMagick\PerlMagick\Image-Magick.ppd>" without <>, and press Enter.
This Will show: "Installing package 'Image-Magick.ppd'..."
Installation process done.
Test: goto into ImageMagick\PerlMagick\demo directory, and run any script
Last edited by r57shell on Mon Jun 10, 2013 6:27 pm, edited 1 time in total.
Image

Ti_
Very interested
Posts: 82
Joined: Tue Aug 30, 2011 7:50 am

Post by Ti_ » Mon Jun 10, 2013 4:21 pm

r57shell wrote: Test: goto into ImageMagick\PerlMagick\demo directory, and run any script
This will not help me.
I use trick CORE_DB_magick_.dll renamed to CORE_RL_magick_.dll ;
after that I copied other 5 dlls he wanted to directory with script.

Now it wants cluster. script.
I use other trick: I take it from Cluster.pm and copy it to perl folder, with create other folder called "Algorithm".
But after that it wants other file - I tried to use dll from installed cluster.dll for win. But that dll doesn't work.

Code: Select all

Can't find 'boot_Algorithm__Cluster' symbol in ./Cluster.dll
I've also tried to use what readme says:

Code: Select all

  ppm install http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/cluster/Algorithm-Cluster.ppd
and....
ppm install failed: The PPD does not provide code to install for this platform

:roll:

All soft that wants dll should burn in hell... :twisted:

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Mon Jun 10, 2013 4:23 pm

r57shell wrote:3) Download ActiveState Perl version needed for ImageMagick.
This is your problem.
Image

Ti_
Very interested
Posts: 82
Joined: Tue Aug 30, 2011 7:50 am

Post by Ti_ » Mon Jun 10, 2013 4:38 pm

r57shell wrote:
r57shell wrote:3) Download ActiveState Perl version needed for ImageMagick.
This is your problem.
Can you write which versions of Perl and Magick works with together?

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Mon Jun 10, 2013 6:27 pm

I don't know it.
r57shell wrote:2) Install with options: install for ActiveState Perl and remember version.
Image

Ti_
Very interested
Posts: 82
Joined: Tue Aug 30, 2011 7:50 am

Post by Ti_ » Mon Jun 10, 2013 6:53 pm

r57shell wrote:I don't know it.
r57shell wrote:2) Install with options: install for ActiveState Perl and remember version.
I tried this order (firstly unistalled all), and it show me version 5.16.3 - that was same version that I have.

So, nothing changed - error msg with DLL.

And I aslo tried scripts from folder. (I used trick to get it work with dll again) - what should they do? some doesn't work, some do nothing or print errors, maybe because of wrong DLL.

Code: Select all

Exception 435: unable to open image `black': No such file or directory @ error/b
lob.c/OpenBlob/2644 at demo.pl line 14.

Post Reply