Page 1 of 2
bilinear point in percents
Posted: 2013-07-18T02:32:05-07:00
by Wolfy
Hello!
I am new to ImageMagick. I have this code
Code: Select all
convert t1-0.png -background white -flatten -alpha set -channel A -sparse-color Bilinear \"160,0 white %w,0 transparent\" t1-0.png
and i need to have percents but not pixels, something like this
Code: Select all
convert t1-0.png -background white -flatten -alpha set -channel A -sparse-color Bilinear \"50%,0 white %w,0 transparent\" t1-0.png
. But this gives unexpected results (not 50 percents). Please, help me
Re: bilinear point in percents
Posted: 2013-07-18T06:48:29-07:00
by snibgo
It would be good if all (x,y) coordinates could be given as percentages of (width,height). Sadly, they can't, and we have to do the necessary caculation in a script.
Re: bilinear point in percents
Posted: 2013-07-18T09:27:11-07:00
by GreenKoopa
Instead of 50%, try %[fx:0.50*w]. In some places this works, others not (support is expanding). When it does, it is far more flexible that simple percents.
Re: bilinear point in percents
Posted: 2013-07-18T09:49:30-07:00
by fmw42
GreenKoopa wrote:Instead of 50%, try %[fx:0.50*w]. In some places this works, others not (support is expanding). When it does, it is far more flexible that simple percents.
That should work for sparse-color as it does recognize % escapes. But if you want percent values, then use
%[fx:50*w/100],0 white
where 50 is from 50%. You cannot put % inside the fx expression. So strip the % from 50% and use 50.
Re: bilinear point in percents
Posted: 2013-07-18T09:59:08-07:00
by fmw42
Actually rather than
%[fx:50*w/100],0 white
it should really be
%[fx:50*(w-1)/100],0 white
otherwise at 100% you would get w, which is outside the image by one pixel, since the last pixel corresponding to width is width-1.
Re: bilinear point in percents
Posted: 2013-07-18T12:38:31-07:00
by GreenKoopa
Hopefully we helped with your initial problem Wolfy, so I'll continue on with this coordinate system question.
Some IM commands use 0,0 to mean the center of the top-left pixel (pixel coordinates), while others use 0,0 to mean the top-left edge of the image (top-left edge of the top-left pixel) (image coordinates). It is confusing (for me at least), but there are good reasons for it to be this way. Does -sparse-color uses pixel or image coordinates?
http://www.imagemagick.org/Usage/canvas ... _gradients
That documentation gives an example called gradient_math.png that states
Usage/canvas/#perfect_gradients wrote:If you were to look closely at this image you will find that the top and bottom most pixels are not white or black in color.
When I try this, my top most pixel is white. I don't know if something is awry or if this only serves to prove my confusion. Any ideas Fred and Anthony?
Re: bilinear point in percents
Posted: 2013-07-18T14:24:23-07:00
by fmw42
I suspect that -sparse-color like the distort methods are using Image Coordinates.
If image coordinates are being used, then the command above should be what I wrote originally.
%[fx:50*w/100],0 white
But that won't make a gradient that is expected to go from full black to full white. One needs to convert the Image Coordinates to their corresponding Pixel appropriate coordinates by the 0.5 offset
But then my second version is not actually what is needed. What is correct according the the reference would be to start at
0.0.5 somecolor
and end at
0,%[fx:w-.5] someothercolor
or perhaps easier to use in code so that you are always using +0.5
0,%[fx:(w-1)+.5] someothercolor
This is essentially finding the center of the square pixel in Image coordinates for the first and last pixels in the horizontal dimension.
If the image is wide enough one probably won't see any difference visually and mathematically you would need to be pretty picky.
However I will defer to Anthony for corrections or a better explanation.
Re: bilinear point in percents
Posted: 2013-07-18T14:40:16-07:00
by GreenKoopa
I reread the documentation and pinpointed why I was confused. The documentation implies that -sparse-color uses image coordinates. This seems proper to me, and intuitive since that makes all three of us correct on our first instinct. But the images within the documentation look like they were created using pixel coordinates. A quick experiment confirmed that this is the case.
Re: bilinear point in percents
Posted: 2013-07-18T15:37:38-07:00
by snibgo
The text descriptions on that page don't correlate with the images or what IM actually does (or even what it did in old versions).
Re: bilinear point in percents
Posted: 2013-07-18T17:11:15-07:00
by fmw42
Anthony will need to comment and clarify.
Re: bilinear point in percents
Posted: 2013-07-18T23:27:28-07:00
by Wolfy
This
works fine for me! Thank you all very much! Imagemagick is awesome tool!
Re: bilinear point in percents
Posted: 2013-07-21T23:53:27-07:00
by anthony
Sparse color and Distorts share the same code for converting input numbers coefficients (coords to color OR, coords to source coords, respectively). All coordinates are mathematical image coordinates. Percentages are not used.
HOWEVER.. both allow the use of % escapes in IMv6 (just as all option arguments will be able to use them in IMv7) as such you can use percentages, or even a 'normalized image coordinates' (a value of 0.0 to 1.0 across the image) simply by using some %[FX:...] expressions.
For an example see...
The Fractured Mirror distortion map
http://www.imagemagick.org/Usage/mappin ... ace_mirror
Which generated random points (positions from 0 to 1) of specific colors, using a Voronoi Mapping.
The operators that use pixel coordinates are: Text Placement, Image Offsets, Flood Fills (whcih needs a actual pixel), and Draw (which also makes some sense). As such mapping between these may need some 0.5 value differences.
Distort sets image 'offsets' correctly (as integer pixel coordinates) for composition when using +distort.
generally if the value is typically integer, it is pixel coords. If floating point it is image coordinates. The Exception is Draw, which allows floating point, but is more typically used using integers.
Actually many of the examples for sparse color does not make correct use of image coordinates in its arguments, so as to align its results with that of 'drawn circles' or the 'original image overlays'. It probably should, but the results have been good enough without this 'perfection'. Only the examples involving 'perfect gradients' actually use correct image coordinates.
Re: bilinear point in percents
Posted: 2013-07-22T00:30:44-07:00
by GreenKoopa
Is this correct output?
Code: Select all
convert -size 1x5 xc: -sparse-color Barycentric "0,0 white 0,5 black" txt:-
# ImageMagick pixel enumeration: 1,5,65535,srgb
0,0: (65535,65535,65535) #FFFFFFFFFFFF white
0,1: (52428,52428,52428) #CCCCCCCCCCCC grey80
0,2: (39321,39321,39321) #999999999999 grey60
0,3: (26214,26214,26214) #666666666666 grey40
0,4: (13107,13107,13107) #333333333333 grey20
convert -size 1x5 xc: -sparse-color Barycentric "0,0.5 white 0,4.5 black" txt:-
# ImageMagick pixel enumeration: 1,5,65535,srgb
0,0: (65535,65535,65535) #FFFFFFFFFFFF white
0,1: (57343,57343,57343) #DFFFDFFFDFFF srgb(87.4998%,87.4998%,87.4998%)
0,2: (40959,40959,40959) #9FFF9FFF9FFF srgb(62.4994%,62.4994%,62.4994%)
0,3: (24576,24576,24576) #600060006000 srgb(37.5006%,37.5006%,37.5006%)
0,4: ( 8192, 8192, 8192) #200020002000 srgb(12.5002%,12.5002%,12.5002%)
Re: bilinear point in percents
Posted: 2013-07-22T21:54:32-07:00
by anthony
No it is not right !!!
Also the result (using pixel coordinates)...
Code: Select all
convert -size 1x5 xc: -sparse-color Barycentric "0,0 white 0,4 black" txt:-
# ImageMagick pixel enumeration: 1,5,65535,srgb
0,0: (65535,65535,65535) #FFFFFFFFFFFF white
0,1: (49151,49151,49151) #BFFFBFFFBFFF srgb(74.9996%,74.9996%,74.9996%)
0,2: (32768,32768,32768) #800080008000 srgb(50.0008%,50.0008%,50.0008%)
0,3: (16384,16384,16384) #400040004000 srgb(25.0004%,25.0004%,25.0004%)
0,4: ( 0, 0, 0) #000000000000 black
shows that what result I should be getting using these image coordinates for pixel centers....
Code: Select all
convert -size 1x5 xc: -sparse-color Barycentric "0,0.5 white 0,4.5 black" txt:-
# ImageMagick pixel enumeration: 1,5,65535,srgb
0,0: (65535,65535,65535) #FFFFFFFFFFFF white
0,1: (57343,57343,57343) #DFFFDFFFDFFF srgb(87.4998%,87.4998%,87.4998%)
0,2: (40959,40959,40959) #9FFF9FFF9FFF srgb(62.4994%,62.4994%,62.4994%)
0,3: (24576,24576,24576) #600060006000 srgb(37.5006%,37.5006%,37.5006%)
0,4: ( 8192, 8192, 8192) #200020002000 srgb(12.5002%,12.5002%,12.5002%)
NOTE: white in this case is because of 'clipping', in HDRI the above value would be a 'ultra-white'.
Re: bilinear point in percents
Posted: 2013-07-22T22:06:27-07:00
by GreenKoopa
snibgo and I thought not. Sorry it took so long to demonstrate this clearly.