Copy alpha channel

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Copy alpha channel

Post by miket »

I'm attempting to copy a grayscale file into the alpha channel of a Radiance RGBE file using perl magic. The Radiance file has values which exceed the quantum depth (Q16 HDR) and the grayscale file has values either 0 or quantum depth (Q16)

In command line the following was successful:

Code: Select all

convert -define compose:clamp=off \
 IMAGE_A.hdr IMAGE_B.ppm \
 -alpha Off -compose copy-opacity -composite \
 IMAGE_OUT.hdr
 


The compose:clamp=off instruction appeared to be necessary for this to work correctly.

I have not been able to identify the equivalent clamp=off command in perl magic, and the following code does not work (i.e. produces a fully transparent alpha channel, in the same way as omitting the clamp=off instruction in the command line example).

Code: Select all

    $image_b->Set(Alpha=>"Off");
    $image_a->Set(Alpha=>'Set');
    $image_a->Composite(file=>$image_b, compose=>"CopyOpacity");


Running $image_x->Identify(); on $image_a (before composite) gives

Code: Select all

Image: /media/sf_Linux_Share/Process/2/2_3_Test.hdr
  Format: HDR (Radiance RGBE image format)
  Class: DirectClass
  Geometry: 4460x2976+0+0
  Units: Undefined
  Type: TrueColorAlpha
  Endianess: Undefined
  Colorspace: RGB
  Depth: 16-bit
  Channel depth:
    Red: 16-bit
    Green: 16-bit
    Blue: 16-bit
    Alpha: 1-bit
  Channel statistics:
    Pixels: 13272960
    Red:
      min: 0 (0)
      max: 6.4552e+06 (98.5)
      mean: 160894 (2.45509)
      standard deviation: 280578 (4.28135)
      kurtosis: 220.499
      skewness: 12.0161
      entropy: 0.394997
    Green:
      min: 0 (0)
      max: 6.3569e+06 (97)
      mean: 164157 (2.50488)
      standard deviation: 253904 (3.87432)
      kurtosis: 188.494
      skewness: 10.295
      entropy: 0.40226
    Blue:
      min: 0 (0)
      max: 6.38966e+06 (97.5)
      mean: 167421 (2.55468)
      standard deviation: 211620 (3.22911)
      kurtosis: 236.99
      skewness: 11.2159
      entropy: 0.271946
    Alpha:
      min: 65535 (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: -nan (-nan)
      kurtosis: -5.00137e+69
      skewness: 1.03552e+50
      entropy: 0.392506
  Image statistics:
    Overall:
      min: 0 (0)
      max: 6.4552e+06 (98.5)
      mean: 139502 (2.12866)
      standard deviation: 216780 (3.30785)
      kurtosis: 304.257
      skewness: 13.5816
      entropy: 0.365427
  Rendering intent: Undefined
  Gamma: 1
  Alpha color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 4460x2976+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: RLE
  Orientation: Undefined
  Properties:
    date:create: 2016-10-06T16:07:51+01:00
    date:modify: 2016-10-06T16:07:51+01:00
    signature: f660e94e6f56fcc5a4e4b2ed7b591e27509ee420a848713ae3f76664ed9cd12b
  Tainted: True
  Filesize: 42.62MB
  Number pixels: 13.27M
  Pixels per second: 642KB
  User time: 21.180u
  Elapsed time: 0:21.660
  Version: ImageMagick 7.0.2-4 Q16 x86_64 2016-09-15 http://www.imagemagick.org
.... and the $image_b file

Code: Select all

Image: /tmp/magick-16155MFWS9Z8ZGoU5
  Format: PPM (Portable pixmap format (color))
  Mime type: image/x-portable-pixmap
  Class: DirectClass
  Geometry: 4460x2976+0+0
  Base geometry: 5248x3502
  Units: Undefined
  Type: Bilevel
  Base type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 16/1-bit
  Channel depth:
    Gray: 1-bit
  Channel statistics:
    Pixels: 13272960
    Gray:
      min: 0 (0)
      max: 65535 (1)
      mean: 65439.3 (0.99854)
      standard deviation: 2502.42 (0.0381845)
      kurtosis: 679.845
      skewness: -26.1122
      entropy: 0.0158595
  Colors: 2
  Histogram:
     19381: (    0,    0,    0) #000000000000 black
  13253579: (65535,65535,65535) #FFFFFFFFFFFF white
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Alpha color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2016-10-06T16:06:43+01:00
    date:modify: 2016-10-06T16:06:43+01:00
    signature: fdab5316fe8c640cccbb47967da3defa2e75559ce5b52a08fb2f70f56acb9728
  Artifacts:
    modulate:colorspace: HSB
  Tainted: False
  Filesize: 0B
  Number pixels: 13.27M
  Pixels per second: 272KB
  User time: 15.060u
  Elapsed time: 0:49.849
  Version: ImageMagick 7.0.2-4 Q16 x86_64 2016-09-15 http://www.imagemagick.org
...... with the post Composite result file being

Code: Select all

Image: /media/sf_Linux_Share/Process/2/2_3_Test.hdr
  Format: HDR (Radiance RGBE image format)
  Class: DirectClass
  Geometry: 4460x2976+0+0
  Units: Undefined
  Type: TrueColorAlpha
  Endianess: Undefined
  Colorspace: RGB
  Depth: 16-bit
  Channel depth:
    Red: 16-bit
    Green: 16-bit
    Blue: 16-bit
    Alpha: 1-bit
  Channel statistics:
    Pixels: 13272960
    Red:
      min: 0 (0)
      max: 6.4552e+06 (98.5)
      mean: 160894 (2.45509)
      standard deviation: 280578 (4.28135)
      kurtosis: 220.499
      skewness: 12.0161
      entropy: 0.394997
    Green:
      min: 0 (0)
      max: 6.3569e+06 (97)
      mean: 164157 (2.50488)
      standard deviation: 253904 (3.87432)
      kurtosis: 188.494
      skewness: 10.295
      entropy: 0.40226
    Blue:
      min: 0 (0)
      max: 6.38966e+06 (97.5)
      mean: 167421 (2.55468)
      standard deviation: 211620 (3.22911)
      kurtosis: 236.99
      skewness: 11.2159
      entropy: 0.271946
    Alpha:
      min: 65535 (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: -nan (-nan)
      kurtosis: -5.00137e+69
      skewness: 1.03552e+50
      entropy: 0.392506
  Image statistics:
    Overall:
      min: 0 (0)
      max: 6.4552e+06 (98.5)
      mean: 139502 (2.12866)
      standard deviation: 216780 (3.30785)
      kurtosis: 304.257
      skewness: 13.5816
      entropy: 0.365427
  Rendering intent: Undefined
  Gamma: 1
  Alpha color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 4460x2976+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: RLE
  Orientation: Undefined
  Properties:
    date:create: 2016-10-06T16:07:51+01:00
    date:modify: 2016-10-06T16:07:51+01:00
    signature: f660e94e6f56fcc5a4e4b2ed7b591e27509ee420a848713ae3f76664ed9cd12b
  Tainted: True
  Filesize: 42.62MB
  Number pixels: 13.27M
  Pixels per second: 2.208MB
  User time: 6.020u
  Elapsed time: 0:07.009
  Version: ImageMagick 7.0.2-4 Q16 x86_64 2016-09-15 http://www.imagemagick.org

Am I missing something, or is there an alternative way to do this?

Mike
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Copy alpha channel

Post by snibgo »

Perhaps clamp=on or off could be added by the developers to the Perl Composite method.

Meanwhile, you might use the Perl equivalents of "-separate" and "-combine", which don't clamp.
snibgo's IM pages: im.snibgo.com
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Copy alpha channel

Post by miket »

So, getting the embarrassing bit out of the way first - the perl command for Composite is not Composite(file=>$image_b.....), but is Composite(image=>$image_b ......). The alpha channel now copies as expected. :oops: (the incorrect usage failed silently, so I really need to get to grips with error trapping !!!)

However, the Composite command IS still clamping my input HDR files.

Snibgo suggested requesting the clamp on/off feature could be added to the perl implementation. What is the best way to go about requesting this feature?

Mike
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Copy alpha channel

Post by snibgo »

I don't use Perl, and I'm not an IM developer, and don't know what changes would be needed.

I suggest you post to the developers forum, asking for the Perl equivalent of the command-line interface "-define compose:clamp=on or off".

You might link back to this post.
snibgo's IM pages: im.snibgo.com
Post Reply