Page 1 of 1
Create multi color transparent gradient with sparse-color
Posted: 2010-10-12T03:16:18-07:00
by haarts
I want to create a gradient with more than two colors and one of the colors should be transparent. Searching the forum I found that -sparse-color in combination with the Shepard method could do the trick. So I tried:
Code: Select all
convert -size 50x500 xc: -channel RGBA -sparse-color Shepards '0,0 rgb(0,255,0,1) 0,250 rgb(255,255,255,0) 0,500 rgb(255,0,0,1)' test.png
The resulting test.png doesn't include the alpha channel. I don't quite understand why. The docs state that one should define -channel and the colors are correct as well as far as I can tell.
Re: Create multi color transparent gradient with sparse-colo
Posted: 2010-10-12T03:58:18-07:00
by haarts
On a related note, I'm trying to understand the -fx operator. I have:
This means that of the second image (v) the pixelvalue (p{}) is used for the resulting image. But I'm unclear on what pixelvalue is used. The first column obviously, but what row? u is the first image, v the second and h the height? If the first image is greyscale and the second a gradient image as described in my previous post what is the result? I assumed this was a color replacement. A mapping of greyscale to color space. But in that light the multiplier does not make sense to me.
Re: Create multi color transparent gradient with sparse-colo
Posted: 2010-10-12T09:50:18-07:00
by fmw42
haarts wrote:I want to create a gradient with more than two colors and one of the colors should be transparent. Searching the forum I found that -sparse-color in combination with the Shepard method could do the trick. So I tried:
Code: Select all
convert -size 50x500 xc: -channel RGBA -sparse-color Shepards '0,0 rgb(0,255,0,1) 0,250 rgb(255,255,255,0) 0,500 rgb(255,0,0,1)' test.png
The resulting test.png doesn't include the alpha channel. I don't quite understand why. The docs state that one should define -channel and the colors are correct as well as far as I can tell.
try adding -alpha set or -matte after -channel RGBA
Re: Create multi color transparent gradient with sparse-colo
Posted: 2010-10-12T19:31:53-07:00
by anthony
haarts wrote:On a related note, I'm trying to understand the -fx operator. I have:
This means that of the second image (v) the pixelvalue (p{}) is used for the resulting image. But I'm unclear on what pixelvalue is used. The first column obviously, but what row? u is the first image, v the second and h the height? If the first image is greyscale and the second a gradient image as described in my previous post what is the result? I assumed this was a color replacement. A mapping of greyscale to color space. But in that light the multiplier does not make sense to me.
v.p{x,y} will look up the pixel at the point x,y in the second image 'v'
The x,y coordinate may be a floating point position so interpolation may be used to mixx colors of near by pixels.
So 0 means just the first 'zeroth' column of pixels will be used,
u*v.h mean the y coodinate is the color of the current pixel in the first image (in 0 to 1 range) multiplied by the height of thesecond image.
So this FX expression replaces the original with a lookup of its color in the second image.
that is replace pixel colors using a Color Lookup Table (the -clut operator is essentuallty does same thing (with minor improvements)
See IM Examples, Color LUT
http://www.imagemagick.org/Usage/color/#clut
Re: Create multi color transparent gradient with sparse-colo
Posted: 2010-10-12T23:58:45-07:00
by haarts
anthony wrote:
v.p{x,y} will look up the pixel at the point x,y in the second image 'v'
The x,y coordinate may be a floating point position so interpolation may be used to mixx colors of near by pixels.
So 0 means just the first 'zeroth' column of pixels will be used,
u*v.h mean the y coodinate is the color of the current pixel in the first image (in 0 to 1 range) multiplied by the height of thesecond image.
So this FX expression replaces the original with a lookup of its color in the second image.
that is replace pixel colors using a Color Lookup Table (the -clut operator is essentuallty does same thing (with minor improvements)
See IM Examples, Color LUT
http://www.imagemagick.org/Usage/color/#clut
Now I see! Thanks for clearing this up for me. And I replaced the -fx expression with the -clut expression. Many thanks for the tip.
Re: Create multi color transparent gradient with sparse-colo
Posted: 2010-10-13T00:01:42-07:00
by haarts
fmw42 wrote:
try adding -alpha set or -matte after -channel RGBA
Adding -alpha resulted in an error and -matte didn't do anything as far as I can see. I resolved the issue by -append and using different gradients. Thanks for the help though!
Re: Create multi color transparent gradient with sparse-colo
Posted: 2010-10-13T00:21:29-07:00
by anthony
that should have been "-alpha set"
also to specify transparency in a color you need rgba() nor rgb()
Code: Select all
convert -size 50x500 xc: -alpha set -channel RGBA \
-sparse-color Shepards '0,0 rgba(0,255,0,1)
0,250 rgba(255,255,255,0)
0,500 rgba(255,0,0,1)' test.png
WARNING: shepards currently does not properly handle alpha (sorry)
As such the above will shade the colors from the opaque colro toward transparent white.
Replace the rgba(255,255,255,0) with 'none' to see it shade toward black which makes the problem very visible!
I have added this problem onto my ToDo list.
It is also mishandling -channel A. for example this replaces all existing colors with black!
Code: Select all
convert logo: -alpha set -channel A -sparse-color Barycentric \
'0,0 opaque 0,%h transparent' \
show: