[SOLVED] multi-colour gradient, dreadful banding

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?".
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

Fred, there is something really weird going on with the images you posted.

I am presuming that you created them using the commands you posted above? Hence ...

your first picture, non-linear created with

Code: Select all

convert \( -size 1100x742 gradient: -rotate 180 \) \
\( -size 1x1 xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a \
xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut \
1tmp2.png
your second picture, linear created with

Code: Select all

convert \( -size 1100x742 gradient:"gray(255)-gray(0)" -rotate 180 \) \
\( -size 1x1 xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a \
xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut \
1tmp3.png
I did not understand your post because this is what these pictures look like when viewed in my browser:
Image
I took a screenshot and placed them side-by-side with gimp. The left picture is your linear image, the right one the non-linear image. Obviously, the colours of the left image look completely wrong. It looks like this in Firefox and in Chrome.

I saved these two images to disc and then opened them with gimp. This is what they look like through gimp and other image viewers:
Image
The colours are correct but the gradients are identical!

Are you sure you used different commands to create them? (The image sizes are different.) What the hell is going on?
Last edited by Draoidh on 2012-08-01T15:47:53-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multi-colour gradient, dreadful banding

Post by fmw42 »

Different viewers handle linear differently. Some may assume it is sRGB.

Here is the exact commands I ran. They both have the same sizes in the commands and the images are the same sizes. Note the colorspaces and gamma values. The first is sRGB with gamma=0.4545. The second is (linear) RGB with gamma=1. If you do not like the linear one, then just use the first one.

IM display, Mac Preview and Safari display then nearly identically. Firefox, show the second one (linear) with the bluish region such as you show. I suspect that Firefox is displaying the linear one wrong and converting it into sRGB. Note that IM display is specifically designed to show the images in the colorspace they indicate and not try to convert them all to sRGB.

created and viewed with IM 6.7.8.7 Q16 Mac OSX Snow Leopard


convert \( -size 400x300 gradient: -rotate 180 \) \
\( -size 1x1 xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a \
xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut \
1tmp2.png

Image: 1tmp2.png
Geometry: 400x300+0+0
Page geometry: 400x300+0+0
Class: DirectClass
Colorspace: sRGB
Type: TrueColor
Depth: 16-bit
Alpha: False
Channels: srgb
Rendering intent: Perceptual
Gamma: 0.45455

Image



convert \( -size 400x300 gradient:"gray(255)-gray(0)" -rotate 180 \) \
\( -size 1x1 xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a \
xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut \
1tmp3.png

Image: 1tmp3.png
Geometry: 400x300+0+0
Page geometry: 400x300+0+0
Class: DirectClass
Colorspace: RGB
Type: TrueColor
Depth: 16-bit
Alpha: False
Channels: rgb
Rendering intent: Undefined
Gamma: 1

Image
Last edited by fmw42 on 2012-08-02T10:16:47-07:00, edited 2 times in total.
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

How did you print the image information?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multi-colour gradient, dreadful banding

Post by fmw42 »

Draoidh wrote:How did you print the image information?
use

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

Re: multi-colour gradient, dreadful banding

Post by anthony »

fmw42 wrote: Anthony can say for sure, but I think I recall that -interpolate bicubic may have changed the formula that is used for the bicubic.

P.S. see viewtopic.php?f=2&t=21118&start=45#p86006

But I do not know if he means that bicubic is now using catrom or bicubic is deprecated and replaced by catrom. In any event, the list of interplation options does not list catrom.

interpolate bicubic is now catrom. It used to be a unnamed cubic function that had a very very strong ringing effect (and should never have been used as a interpolator), and even longer ago (2004 or earily) it was a very blurry 'spline' cubic filter.

Catrom is known as 'the cubic interpolator', and is the right choice.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: multi-colour gradient, dreadful banding

Post by anthony »

I do not believe -clut does any colorspace changes (it shouldn't if all images are the same colorspace).
The gray is linear data and as long as it is not modified when used as a lookup, the result should be a
linear distribution of colors from the CLUT image.

Adding a -set colorspace sRGB just before the -clut should ensure the linear data gradient is in sRGB colorspace, along with the CLUT colors. the result is as per the first image (no banding).

The set is for the 'gray data' and not for the CLUT. Actually any 'set' can be used, as long as you set the final result in
the right colorspace for output.

EG: this will work too! clut operates on all images in the 'right' colorspace.
-set colorspace RGB -clut \) -set colorspace sRGB x.png

clut probably should simply use data values 'as is' and let the user figure out whet the final result should be.
Remember it has to handle not only coloring greyscale, but also using a greyscale 'data modifier', and that modifer may
ne a different gray value for each channel! that is the CLUT image is colorful, but values are really 'greyscale'.

Also remember -clut is a 'channel' operator that is -channel setting effected.
It may even be called on to alply a greyscale modifier to alpha values where the CLUT has no actual alpha enabled!

or add colros with transparency (CLUT) to a greyscale image input image that has no transparency.


Probably what is happening is that the inpout greyscale is being promoted to sRGB! In this case it probably should
not promote the input image (values are what user wants), just set the colorspace for the resulting output image to sRGB!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

Fred, you confused the hell out of me: the second image of your last post should show 1tmp3.png but it links to 1tmp2.png!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multi-colour gradient, dreadful banding

Post by fmw42 »

Draoidh wrote:Fred, you confused the hell out of me: the second image of your last post should show 1tmp3.png but it links to 1tmp2.png!
Sorry, in my cut and paste of images, I accidentally forgot to update the image name. It is fixed now.
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

As I stated earlier, I cannot upgrade to 6.7.8 at present because it's not yet available in Debian testing. 6.7.7.10 produced weird results (posted above). So, I moved back to 6.7.7.2, which gives reasonable results with -interpolate Bilinear.

What I am concerned about is that the images I generate now should look sufficiently similar to what I will be getting when I eventually do upgrade to 6.7.8. I need reproducable results.

The image Fred produced with 6.7.8 (non-linear):

Code: Select all

convert \( -size 400x300 gradient: -rotate 180 \) \
\( -size 1x1 xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a \
xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut \
1tmp2.png
Image

6.7.7.2 with -interpolate Bilinear:

Code: Select all

convert \( -size 400x300 gradient: -rotate 180   \) \( +size   xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e  -append \) -interpolate Bilinear  -clut gradient-6.7.7.2-bilinear.png
Image

That's similar enough.

Bilinear works fine except in combination with -distort Arc, which gives me a grid pattern:

Code: Select all

convert \( -size 400x300 gradient: -rotate 180 -distort Arc '60 0 50 0' -scale 400x300! \) \( +size   xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e  -append \) -interpolate Bilinear  -clut gradient-6.7.7.2-bilinear-arc.png
Image

Here comes the question: how can I fudge the grid away for the time being? I tried -gaussian-blur 2x1, which is not sufficient, but -gaussian-blur 4x2 makes the colours a bit muted.


Fred, could you produce and post the following image so I can see what it should look like?

Code: Select all

convert \( -size 400x300 gradient: -rotate 180 -distort Arc '60 0 50 0' -scale 400x300! \) \( +size   xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a xc:#9e002f xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e  -append \) -interpolate Bicubic  -clut gradient-6.7.8-bicubic-arc.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multi-colour gradient, dreadful banding

Post by fmw42 »

Don't use -scale, use -resize and it will be smooth


convert \( -size 400x300 gradient: -rotate 180 -distort Arc '60 0 50 0' -scale 400x300! \) \
\( +size xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a xc:#9e002f \
xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut gradient-6.7.8-bicubic-arc.png

Image


convert \( -size 400x300 gradient: -rotate 180 -distort Arc '60 0 50 0' -resize 400x300! \) \
\( +size xc:#0c0126 xc:#19022a xc:#27032e xc:#43013a xc:#5f0046 xc:#7e003a xc:#9e002f \
xc:#ce1129 xc:#fe2323 xc:#f6441a xc:#ee6611 xc:#f68617 xc:#ffa61e -append \) \
-interpolate Bicubic -clut gradient-6.7.8-bicubic-arc2.png

Image
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

Magick!

Have a great weekend!
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

Continuing with the gradient topic, here's a different issue:

Code: Select all

convert -alpha set \( -size 400x300 gradient: -rotate 90 \( +size "xc:#00247d" "xc:#00247d"  "xc:#00247d" "xc:#0090fe"  "xc:#0090fe"  -append \) -interpolate Bilinear  -clut \) /tmp/yes/x.png
Note the duplicated colour values. This was an attempt to weight the gradient. However, this causes a "bump". Can this be avoided?
I know this is a rather crude method. In CSS you would specify the position in %. But I really don't want to go down the route of complicating my parameterized script any further.

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multi-colour gradient, dreadful banding

Post by fmw42 »

I get the same results with bilinear, but better results with bicubic

convert \( -size 400x300 gradient:"gray(255)-gray(0)" -rotate 90 \) \
\( -size 1x1 "xc:#00247d" "xc:#00247d" "xc:#00247d" "xc:#0090fe" "xc:#0090fe" -append \) \
-interpolate bicubic -clut gradient-6.7.8.8-bicubic.png

Image
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: multi-colour gradient, dreadful banding

Post by Draoidh »

Good evening Fred, or should I say good morning?

With your linear gradient, the bump looks less pronounced. Even so, the change is much more abrupt than with the 2 colours only being specified once:

Code: Select all

convert -alpha set \( -size 400x300 gradient: -rotate 90 \( +size "xc:#00247d" "xc:#0090fe"  "xc:#0090fe"  -append \) -interpolate Bilinear  -clut \) gradient-nobump.png
Image

Somehow your linear gradient pictures end up in RGB.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multi-colour gradient, dreadful banding

Post by fmw42 »

Sorry I posted the wrong command. I tried both linear and non-linear gradients and they looked much the same at first glance. Here is the non-linear gradient.


convert \( -size 400x300 gradient: -rotate 90 \) \
\( -size 1x1 "xc:#00247d" "xc:#00247d" "xc:#00247d" "xc:#0090fe" "xc:#0090fe" -append \) \
-interpolate bicubic -clut gradient-6.7.8.8-bicubic2.png

Image

As I said before I tried my version of your command with -interpolate bilinear and got similar results to you with the bright vertical region (peak). So I think you need to use bicubic. But if you are still on that old version of IM, it might not work right. So I really suggest that you upgrade your IM.
Post Reply