problems with fx operator

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
jhs
Posts: 5
Joined: 2015-03-16T11:08:58-07:00
Authentication code: 6789

problems with fx operator

Post by jhs »

i observe a change in behaviour from version 6.6.9-7 to 6.7.7-10 :

i am generating a panorama from a sky image with lookup tables, lutX.png and lutY.png
In the older version the result is in color on the newer i get a grayscale image.
The call in bash is as follows

Code: Select all

convert lutX.png lutY.png raw.jpg   -fx "u[2].p{ u*$wraw , v*$hraw }" pan.jpg
$wraw, $hraw are width and height of the raw image.

example images can be found here
http://gop.meteo.uni-koeln.de/~hatpro/j ... ge_magick/

the full code with variables and lookup tabels is:

Code: Select all

# width and height or original image
wraw=$(identify -format %w raw.jpg)
hraw=$(identify -format %h raw.jpg)

# simple estimate for center and radius
cx=$(($wraw/2))
cy=$(($hraw/2))
rad=$cx

# desired width and height of panorama
# panorama length = raw image width
wpan=$(( $wraw ))
# height is something
hpan=$(( $wpan * 100/628 )) 

; generate lookup table for x coordinate    
convert -size $wpan'x'$hpan xc: -channel G -fx "($cx-$rad*j/$hpan*sin(2*pi*i/$wpan))/$wraw" -separate lutX.png
; generate lookup table for y coordinate    
convert -size $wpan'x'$hpan xc: -channel R -fx "($cy+$rad*j/$hpan*cos(2*pi*i/$wpan))/$hraw" -separate lutY.png

# do the pano
convert lutX.png lutY.png raw.jpg   -fx "u[2].p{ u*$wraw , v*$hraw }" pan.jpg
am i doing wrong or is it convert ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: problems with fx operator

Post by snibgo »

It is taking the type (and other metadata) from the first image in the list. Insert "-type TrueColor" before the output filename.
snibgo's IM pages: im.snibgo.com
jhs
Posts: 5
Joined: 2015-03-16T11:08:58-07:00
Authentication code: 6789

Re: problems with fx operator

Post by jhs »

-type TrueColor does not help:

metadata of pan without -type TrueColor
$identify pan.jpg
pan.jpg JPEG 288x45 288x45+0+0 8-bit PseudoClass 256c 3.81KB 0.000u 0:00.000

generate pan with -type TrueColor :
$convert lutX.png lutY.png raw.jpg -fx "u[2].p{ u*$wraw , v*$hraw }" -type TrueColor pan_tc.jpg
metadata of this
$identify pan_tc.jpg
pan_tc.jpg JPEG 288x45 288x45+0+0 8-bit PseudoClass 256c 3.81KB 0.000u 0:00.010

so there is no change ... ant the image is still grayscale. :(


metadata of the lookup table i.e. the first image:
$identify lutX.png
lutX.png PNG 288x45 288x45+0+0 16-bit PseudoClass 65536c 24.4KB 0.000u 0:00.000

if I add -type TrueColor to the command generating lutX i get:
$convert -size $wpan'x'$hpan xc: -channel G -fx "($cx-$rad*j/$hpan*sin(2*pi*i/$wpan))/$wraw" -separate -type truecolor lutX_tc.png
$identify lutX_tc.png
lutX_tc.png PNG 288x45 288x45+0+0 16-bit DirectClass 28KB 0.000u 0:00.000

i.e. DirectClass instead of Pseudoclass which is not a 3*8bit but (if i understand correct) 3*5bit 'truecolor'

if i use this for the generation of pan.jpg without -type = truecolor I get:
$convert lutX_tc.png lutY.png raw.jpg -fx "u[2].p{ u*$wraw , v*$hraw }" pan_tc1.jpg
$identify pan_tc1.jpg
pan_tc1.jpg JPEG 288x45 288x45+0+0 8-bit DirectClass 4.46KB 0.000u 0:00.000

8-bit DirectClass means 3*8bit RGB truecolor ?
it is not the same type as lutX_tc.png !
but pan_tc1 it is now in color - great :D - problem solved.

But it remains somehow puzzling :? ...
jhs
Posts: 5
Joined: 2015-03-16T11:08:58-07:00
Authentication code: 6789

Re: problems with fx operator

Post by jhs »

...
could do it also with lookup tables in the red and green channels of lut_RG.png

Code: Select all

  convert -size $wpan'x'$hpan xc: -channel R -fx "($cx-$rad*j/$hpan*sin(2*pi*i/$wpan))/$wraw" \
                                  -channel G -fx "($cy+$rad*j/$hpan*cos(2*pi*i/$wpan))/$hraw" \
                               lut_RG.png
  # do the pano
  convert lut_RG.png raw.jpg   -fx "u[1].p{ u[0].r*$wraw , u[0].g*$hraw }" pan.jpg
this way the color problem does not occur (lut_RG.png is now a 16bit directclass).

Additonally this way might be slightly faster as only one lut has to be loaded.
(i am using lookup tables because they need to be changed only very rarely whereas the panorama is generated every 20seconds - see http://gop.meteo.uni-koeln.de/~hatpro/jue/tsi/current/)
... and think about using miff instead of png for the lut ...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: problems with fx operator

Post by snibgo »

IM did some weird things with greyscale around your versions. See http://www.imagemagick.org/script/color-management.php . It may be a good idea to upgrade to the current version.

The oldest version on my laptop is 6.8.0-0. On that version, with or without "-type TrueColor", I get a colour image.

On 6.9.0-0 (which is now quite old, but it is what I use), I need "-type TrueColor" to get colour.

"Pseudoclass" means palette; "Directclass" means non-palette. Both of those can be grayscale or colour.


Yes, loading only one file will probably be quicker, and miff will be quicker than png. However, miff file formats can change between versions. You might regenerate them when you upgrade, or at the start of each batch.
snibgo's IM pages: im.snibgo.com
Post Reply