How use -clut option

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?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How use -clut option

Post by snibgo »

What version of IM are you using? With v6.8.8-7 on Windows 8.1, I find that your main.png has two colors: 0 (black) and gray 68. Running that command ...

Code: Select all

convert main.png +repage -write mpr:XX -filter spline -resize 2080x1430 +dither -remap mpr:XX m.png
... gives a result with the same two colours only. There is no 34.
snibgo's IM pages: im.snibgo.com
guillaumech
Posts: 32
Joined: 2011-04-23T05:53:09-07:00
Authentication code: 8675308

Re: How use -clut option

Post by guillaumech »

Yes, but with the last file main.png try...
They are the wrong area (right bottom), because they are others values around the 34,34,34 color. Not on the main.png. Difficult to explain...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How use -clut option

Post by snibgo »

main.png has only 2 colours. The output of that command, for me, has only two colours.

What version of IM are you using?
snibgo's IM pages: im.snibgo.com
guillaumech
Posts: 32
Joined: 2011-04-23T05:53:09-07:00
Authentication code: 8675308

Re: How use -clut option

Post by guillaumech »

Apology, the main.png file was wrong on my server, this is the true file : http://nauton.espace-meteo.com/main.png (F5 if there are only two colors)
My IM version is
Version: ImageMagick 6.8.7-8 Q16 x86_64 2014-02-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: fontconfig freetype jng jpeg png x zlib

Thx

Edit: with this command line, is not the number of different colors, but the wrong area with grayscale, while on the main map there are only one color on this area
Wrong area => http://nauton.espace-meteo.com/mWrongArea.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How use -clut option

Post by snibgo »

guillaumech wrote:Apology, the main.png file was wrong on my server, this is the true file
That is the same as the previous file. It has only two colours. The bottom-right is entirely black. It cannot make your result mWrongArea.png
snibgo's IM pages: im.snibgo.com
guillaumech
Posts: 32
Joined: 2011-04-23T05:53:09-07:00
Authentication code: 8675308

Re: How use -clut option

Post by guillaumech »

Are you sure? With F5, clean your cache...
http://nauton.espace-meteo.com/main.png is really the true file, with another area at bottom right
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How use -clut option

Post by snibgo »

That's better. That image has 3 colours: 0 34 and 68.

The output of the command has the same 3 colours.

What is the problem? Perhaps you like some of the gray(34) colors but not all of them. What is the rule for which grey(34) colors are good and which are bad?

The problem is (I think) that you don't want the average of 0 and 68 to be 34. You want it to be 0 or 68.

This means that you want the colours to be treated independently of each other. This is more complex. You probably need to separate the image into component colours, process each colour, then combine them.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How use -clut option

Post by snibgo »

For example, this might do what you want:

Code: Select all

convert ^
  main4.png +repage ^
  -fill Black -filter spline +dither ^
  ( -clone 0 +opaque rgb(34,34,34) -write mpr:X1 -resize "2080x1430^!" -remap mpr:X1 +transparent rgb(34,34,34) ) ^
  ( -clone 0 +opaque rgb(68,68,68) -write mpr:X2 -resize "2080x1430^!" -remap mpr:X2 +transparent rgb(68,68,68) ) ^
  -background Black ^
  -delete 0 ^
  -layers flatten ^
  mout.png
snibgo's IM pages: im.snibgo.com
guillaumech
Posts: 32
Joined: 2011-04-23T05:53:09-07:00
Authentication code: 8675308

Re: How use -clut option

Post by guillaumech »

Yes snibgo, this is exactly the result as I want! :) Thank you.
And now, how built this type of image with many gray values? Because if I've 70 different values, I will have 70 line like that : ( -clone 0 +opaque rgb(68,68,68) -write mpr:X2 -resize "2080x1430^!" -remap mpr:X2 +transparent rgb(68,68,68) )
Hummm... I will try an Awk script, with separate each value on my main file and execute your script. But it will be slow I think.
Scale2x do this, resize without create grayscale, but with strange area.
Thx snibgo.
guillaumech
Posts: 32
Joined: 2011-04-23T05:53:09-07:00
Authentication code: 8675308

Re: How use -clut option

Post by guillaumech »

After thinking, I believe that your last method is too slow for my work...
Rhaa, is there nothing else method?

I just try another main map :
Image

There are 3 different colors : 34, 68, 187 (without black color)
If we forget the failing when we have just 187 value and just that, the resizing create grayscale levels, we can apply this script :

Code: Select all

convert main.png +repage -write mpr:XX -filter Cubic -resize 2080x1430 +dither -remap mpr:XX spline.png;

We get a new map with also 3 colors, alright.
But if I want colorize this last map :

Code: Select all

convert spline.png g2.png -interpolate nearestneighbor -clut spline.png;
File gradient =>

Code: Select all

convert xc:#FFFFFF xc:#6EA1FF xc:#3770DF xc:#0040BF xc:#FC85F8 xc:#FD42F7 xc:#FF00F7 xc:#FA8484 +append g2.png
I obtain this map : http://nauton.espace-meteo.com/m3.png
It's not normal to get the same blue (blue with red dot on this image), while on the main map there are two different gray colors for these area...

Edit:
If I use this resize:

Code: Select all

 convert ./processing/map/main.png +repage -filter Cubic -resize 2080x1430 ./processing/map/spline.png;
After clut action, I get this map : http://nauton.espace-meteo.com/Cubic.png

If I use this resize:

Code: Select all

 convert ./processing/map/main.png +repage -filter Box -resize 2080x1430 ./processing/map/spline.png;
After clut action, I get this map : http://nauton.espace-meteo.com/Box.png

I would like keep all values on the main map (but smooth area, not boxes...). With Spline interpolation the purple value disapear...
Problem without end :(

Edit 2:
I try again with this main map : http://nauton.espace-meteo.com/main4.png
And this gradient : http://nauton.espace-meteo.com/g3.png

On this main map I've these values : 0, 1, 2, 5
My gradient have 255 levels of color, so, I have to obtain for each value on my main map a color.

Code: Select all

 convert main.png +repage -filter Spline -resize 2080x1430 Spline.png;
http://nauton.espace-meteo.com/Spline3.png

Code: Select all

 convert main.png +repage -filter Box -resize 2080x1430 Box.png;
http://nauton.espace-meteo.com/Box3.png

Where is my purple value on the Spline map? I understand that create grayscale with spline interpolation, but lose values?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How use -clut option

Post by anthony »

Greeting Guillaume Chanteloube,
Long time no hear.....

The problem is you are blending neighbouring colors, when that is not what you want.

The Problem: If you have two distinct values representing distinct areas, next to each other but have a third distinct value in between those two, then ANY form of resize, blurring or mapping, will not do you any good.

The operators will form a blend of the two original values, which could be mistaken as being that third value that lies in between. This is where things like Scale (just square boxes), and HQX and ScaleX algorithms excel, they are designed to smooth the borders but without blurring the colors, however they generally do so by adding diagonals, whcih means you still get a lot of unwanted bitmap effects.



But for a possibility that you may not have thought of... vectorize the raster image.

That is use a program such as autotrace, or potrace.

This basically converts the bitmap into 'areas of color' rather than individual pixels, that have no specific 'scale' of view. These scale or resize easily, and can then be re-draw at the larger size. There are options for how selecting wheater specific points along the edge should have a sharp corner, or a smooth rounded curve.

IM has some basic autotrace handling, which I demonstrate to smooth a bitmap image into a clean smooth edged version of the same shape, and actually extract a clean thin edge line.
http://www.imagemagick.org/Usage/transform/#edge_vector

While in the example I did not scale the resulting images to a larger size, the vectors have no specific scale and as such using that format you can make that exact same smooth image at any size, without any 'bitmap aliasing' effects.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How use -clut option

Post by fmw42 »

To add to Anthony's suggestions, the vector approach is probably the best, but IM does have -magnify to do art-scaling such as scale2x. See http://www.imagemagick.org/script/comma ... hp#magnify. You would have to repeat it many times to get the large factor you want and so it might still be too blocky for you.

There are some free online raster to vector sites. See
http://www.autotracer.org/
http://vectormagic.com/home
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How use -clut option

Post by anthony »

vectormagick has a free to use online version, but otherwise it isn't free
autotracer.org (not to be confused with "autotrace" software package) seems to be online only.

I did not know magnifier has now implementing the ScaleX algorithm! What version of IM added it?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How use -clut option

Post by fmw42 »

anthony wrote:vectormagick has a free to use online version, but otherwise it isn't free
autotracer.org (not to be confused with "autotrace" software package) seems to be online only.

I did not know magnifier has now implementing the ScaleX algorithm! What version of IM added it?
I don't recall and it is not listed in the changelog.

see
viewtopic.php?f=22&t=23046
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How use -clut option

Post by anthony »

It was suggested to be added to -magnify. I said that should not be modified, but -pixel-scaling be added as a option instead, especially so as to allow selection of multiple methods in the future. No further action was taken. Arrrggghhhh....
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply