Retro Graphics Toolkit

Talk about development tools here

Moderator: BigEvilCorporation

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

Post by Ti_ » Mon Jun 10, 2013 8:32 am

frederic wrote: The script is here: http://edis.zapto.org/md/bitmap2md.pl
It needs two Perl modules : Image::Magick and Algorithm::Cluster. It should run on Windows.
I've tried to download activeperl, strawberry perl, imagemagick plugin, tried to reinstall image magick with 2 options: install enviroment and install for active perl. Tried to use some scripts that written in readme.
It's wont work in anyway. Can't found damn dlls.

perl.exe - error
CORE_DB_magick_.dll - doesn't found. It even doesn't exist. Where did I get this?

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

Post by r57shell » Mon Jun 10, 2013 1:06 pm

frederic wrote:Finally I made a Perl script that uses ImageMagick and that generates something that the MD can actually display.

The script is here: http://edis.zapto.org/md/bitmap2md.pl
Lines 295,296: you first make remap, then quantize, why not in reverse order?
Oh, and after then, Clustering...
My "vision" of process: all in reverse order.
1) Clustering, n = number of clusters
2) Make n palettes by quantization of original image
3) Remap each palette
4) Make n dithered images.
5) Combine n images into one, by clusters.
I will try to modify your script, and do some experiments.
And, add option for background color :)

But, I think... best results will be with modified scolorq, but I don't know now, how to modify it properly.
Try my modification of scolorq. It is windows exe, but you can use wine, I think.

EDIT: http://code.activestate.com/ppm/Algorithm-Cluster/ Windows does not support :(

EDIT 2: Compiled by "hands" Algorithm-Cluster from sources. Script tested, throws exception at line 61, fixed to:

Code: Select all

sub open_image {
  my $file = shift;
  my $image = Image::Magick->new;
  open(IMG, $file) or die "Can't open $file : $!";
  close(IMG);
  $image->Read($file);
  return $image;
}
Now, it works.
Image

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

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

Here we go!
Battle of converters: 30 colors, each tile - one palette.
Original:
Image
Warriors from left to right:
sega16 with Retro Graphics Toolkit, frederic with bitmap2md.pl, r57shell with modified bitmap2md.pl (mentioned algo before).
Image Image Image
My version works in about 10 seconds, much faster than version by frederic. I have added dither method setting.
It will be better, if Remap dither was equal to Quantize dither in ImageMagick. But, it's not true, I don't know why.
What I mean:

Code: Select all

convert my_img.png -dither Riemersma -colors 30 my_img1.png
convert my_img.png -dither Riemersma -remap my_img1.png my_img2.png
my_img2 will have much more noise than my_img1.
Image

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

Post by frederic » Mon Jun 10, 2013 6:32 pm

sega16 wrote:Goto tilemap actions->Dither tilemap as image
Then pick how you want the tilemap dithered.
So it was me. Thanks.
Ti_ wrote:I've tried to download activeperl, strawberry perl, imagemagick plugin, tried to reinstall image magick with 2 options: install enviroment and install for active perl. Tried to use some scripts that written in readme.
It's wont work in anyway. Can't found damn dlls.
I tried to use the script under Windows. I ran into the problem that you described but I found a way to solve it. I did that under Windows XP, I hope it can work for you also.

- Uninstall Perl & ImageMagick (may not be necessary but it's what I did).
- Install Strawberry Perl 5.16.3.1
- Run the command line interface (cmd).
- Type cpan (it should give you a shell).
- Type install Algorithm::Cluster (it will download and compile the module, it may download a C compiler and dmake if needed).
- You can close the command line interface.

Then

- Download ImageMagick and run the installer.
- The installer will ask you to select/unselect a few options. Check "Add application directory to the system path" and "Install developpement headers and librairies for C and C++". Do not check "Install PerlMagick for ActiveState".
- Complete the installation.

Then

- Download PerlMagick here: http://search.cpan.org/CPAN/authors/id/ ... .86.tar.gz
- Uncompress the archive.
- Run a command line interface (cmd).
- Change directory to the folder you got from uncompressing the PerlMagick archive.
- Type "perl Makefile.PL". It may complain about "No library found for -lMagickCore-Q16"
- Edit the file named Makefile (in the same directory).
- Inside this file, find a line that begins with "LDLOADLIBS = ....."
- At the end of this line, add a space, then add -lCORE_RL_Magick_
- Save the file.
- In the command line interface, in the directory where the Makefile is, type dmake and then dmake install
- You're done.

A bug in PerlMagick prevents you from installing the module by typing "install Image::Magick" under the cpan shell. Without this bug, it would that easy.

Re-download my script (that has been modified to run under Windows). You should be able to use it.
r57shell wrote:Lines 295,296: you first make remap, then quantize, why not in reverse order?
I tried different things and doing things this way gave better results.
r57shell wrote:I will try to modify your script, and do some experiments.
I encourage you to do so. It can certainly be improved.
r57shell wrote:Try my modification of scolorq
I'll take a look at it.
r57shell wrote:EDIT 2: Compiled by "hands" Algorithm-Cluster from sources.
To install any Perl module that is on CPAN, just run "cpan" and "install Module::Name". It works with both Activestate and Strawberry Perl.
r57shell wrote:Script tested, throws exception at line 61, fixed
Too bad I didn't saw this earlier, it would have save me some time :-).

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

Post by Ti_ » Mon Jun 10, 2013 7:12 pm

"r57shell": You version looks better!

frederic colors = 29 and artifact on scorpion
sega16 = no visible artifact, but 24 colors.
you version = no visible artifact and 28 colors.

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

Post by frederic » Mon Jun 10, 2013 7:13 pm

r57shell wrote:My version works in about 10 seconds, much faster than version by frederic.
Indeed it is a lot faster. But the results are not as good with some images.

For example, below, the first row of images comes from your script (from left to right: dither=0, dither=1, dither=2). The bottom image comes from my script (dither option disabled). All images are generated with --colors 30.

Image

Try these images:
http://edis.zapto.org/md/images/cat.jpg
http://edis.zapto.org/md/images/forest.jpg
http://edis.zapto.org/md/images/rain.jpg
http://edis.zapto.org/md/images/sunset.jpg

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

Post by Ti_ » Mon Jun 10, 2013 7:22 pm

r57shell wrote:Here we go!
Battle of converters:
Try you converters with this well-known pic:
source:
Image
45 colors half-manual: (4 rows)
Image


frederic wrote: The bottom image comes from my script (dither option disabled). All images are generated with --colors 30.
If dithered disabled, why this image looks dithered? In this case you result much more good.

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

Post by frederic » Mon Jun 10, 2013 7:46 pm

Ti_ wrote:If dithered disabled, why this image looks dithered?
It seems that my algorithm (a series of quantization/remapping applied to the whole picture, then to small parts, then to tiles) induces dithering, though no explicit dithering algorithm is applied.

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

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

frederic wrote:
Ti_ wrote:If dithered disabled, why this image looks dithered?
It seems that my algorithm (a series of quantization/remapping applied to the whole picture, then to small parts, then to tiles) induces dithering, though no explicit dithering algorithm is applied.
What can I say, there's no one ideal algorithm.
It depends on picture, so ultimate utility must use different orders and different algorithms .
Best way if it will produce 4-5 pictures in 1 click with mostly usable methods, after that user can select best looking, and after that try slightly adjust settings manually.

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

Post by r57shell » Mon Jun 10, 2013 8:03 pm

frederic, I have already mentioned why my images have so many noise. I don't know how to avoid this bug.
Ti_ wrote:45 colors half-manual: (4 rows)
What you mean? What source and what properties of this image? Is that true, that each tile uses only one palette?
Ti_ wrote:If dithered disabled, why this image looks dithered? In this case you result much more good.
Because Remap function of ImageMagick used dither by defaut even if dither option not set. It is bug of version by frederic.
Image

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

Post by r57shell » Mon Jun 10, 2013 8:05 pm

Ti_ wrote:What can I say, there's no one ideal algorithm.
Captain obvious.
For now, I think for tiles independed case, scolorq best choice.
Image

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

Post by frederic » Mon Jun 10, 2013 8:05 pm

True, Ti_. r57shell's algorithm seems to be better on some images (drawings with big area of flat colors). See the comparison with the picture you just gave.

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

Post by frederic » Mon Jun 10, 2013 8:08 pm

r57shell wrote:Because Remap function of ImageMagick used dither by defaut even if dither option not set. It is bug of version by frederic.
It's not a bug. The "dither" argument is passed to imagemagick's functions with a false value, to disable dithering (see this). When you enable dithering, the script is much slower.

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

Post by r57shell » Mon Jun 10, 2013 8:16 pm

frederic wrote:It's not a bug.
Your bug. You must turn off dither explicitly.

Code: Select all

Remap(image => $colormap, dither => 0);
Image

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

Post by frederic » Mon Jun 10, 2013 8:21 pm

r57shell wrote:Your bug. You must turn off dither explicitly.
From ImageMagick's documentation :
dither=>{True, False}
In my script, insert this just before Quantize() or Remap() is called:

Code: Select all

if ($options{dither}) {
  print "This is a true value\n";
} else {
  print "This is a false value\n";
}
You'll see that Quantize() and Remap() are called with a "dither" parameter that has a false value (which is set by GetOptions() because the --dither flag is not given).

Post Reply