Page 1 of 1

Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T17:56:19-07:00
by BrandonMathis
I am at trying to recolor a black and white photoshop tiff and ran into this problem.

I am attempting to recolor the white in this image
https://github.com/BrandonMathis/magik_ ... f?raw=true

to #8649ba

Code: Select all

convert black_square.tif -fill "#8649ba" -opaque "#FFFFFF" out.tif
The above command results in this image which has magenta in it, not #8649ba which is closest to magenta:
https://github.com/BrandonMathis/magik_ ... f?raw=true

The command throws this error

Code: Select all

convert: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/856.
I have more details posted in this github repo where 6 different color conversion requests result in their primary color counterpart.
https://github.com/BrandonMathis/magik_tiff_recolor_bug

Here is an identify on the resulting image with magenta color

Code: Select all

Image: magenta_out.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 600x600+0+0
  Resolution: 72x72
  Print size: 8.33333x8.33333
  Units: PixelsPerInch
  Type: Palette
  Base type: TrueColor
  Endianess: LSB
  Colorspace: sRGB
  Depth: 1-bit
  Channel depth:
    red: 1-bit
    green: 1-bit
    blue: 1-bit
  Channel statistics:
    Pixels: 360000
    Red:
      min: 0 (0)
      max: 1 (1)
      mean: 0.4996 (0.4996)
      standard deviation: 0.5 (0.5)
      kurtosis: -2
      skewness: 0.0016
      entropy: 1
    Green:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
      entropy: nan
    Blue:
      min: 0 (0)
      max: 1 (1)
      mean: 0.4996 (0.4996)
      standard deviation: 0.5 (0.5)
      kurtosis: -2
      skewness: 0.0016
      entropy: 1
  Image statistics:
    Overall:
      min: 0 (0)
      max: 1 (1)
      mean: 0.333067 (0.333067)
      standard deviation: 0.408248 (0.408248)
      kurtosis: -0.332263
      skewness: 1.08997
      entropy: nan
  Colors: 2
  Histogram:
    180144: (  0,  0,  0) #000000 black
    179856: (255,  0,255) #FF00FF magenta
  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)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 600x600+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: LZW
  Orientation: TopLeft
  Properties:
    date:create: 2015-08-06T20:49:23-04:00
    date:modify: 2015-08-06T20:49:23-04:00
    dc:format: image/tiff
    photoshop:ColorMode: 0
    signature: 1ca9e17fb3133c57790143cef1f83c9252fd86e5c5c55cfbed4745044fec338d
    tiff:alpha: unspecified
    tiff:endian: lsb
    tiff:photometric: RGB
    tiff:rows-per-strip: 36
    xmp:CreateDate: 2015-07-28T11:51:42-04:00
    xmp:CreatorTool: Adobe Photoshop CC 2015 (Macintosh)
    xmp:MetadataDate: 2015-07-28T17:07:21-04:00
    xmp:ModifyDate: 2015-07-28T17:07:21-04:00
    xmpMM:DocumentID: xmp.did:7f6ce280-2928-424a-975f-77f443ca9473
    xmpMM:InstanceID: xmp.iid:93fa8981-d8e4-4468-b009-c3b696d91dd1
    xmpMM:OriginalDocumentID: xmp.did:7f6ce280-2928-424a-975f-77f443ca9473
  Profiles:
    Profile-8bim: 4140 bytes
    Profile-xmp: 14305 bytes
  Artifacts:
    filename: magenta_out.tif
    verbose: true
  Tainted: False
  Filesize: 24.4KB
  Number pixels: 360K
  Pixels per second: 360GB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-07-26 http://www.imagemagick.org

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T18:16:21-07:00
by fmw42
Try this. It works for me on IM 6.9.1.10 Q16 Mac OSX. It is probably because the input is bilevel and needs to be converted upwards to palette. But I would think that IM should be doing that automatically. So perhaps a bug.

Code: Select all

convert black_square.tif -fill "#8649ba" -opaque "#FFFFFF" -type palette out.tif

Please in the future always provide your IM version and platform when asking questions on this forum.

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T18:25:16-07:00
by snibgo
When an input has a low bit-depth, this is often carried through to the output. One cure for this is "+depth" before the output.

Code: Select all

convert black_square.tif -fill "#8649ba" -opaque "#FFFFFF" +depth a.tiff

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T18:49:20-07:00
by fmw42
snibgo wrote:When an input has a low bit-depth, this is often carried through to the output. One cure for this is "+depth" before the output.

Code: Select all

convert black_square.tif -fill "#8649ba" -opaque "#FFFFFF" +depth a.tiff

Thanks Snibgo. I think that is a good method as well, perhaps better or more obvious than using -type. But it seems to me that IM should be doing one or the other automatically. Would you agree?

Fred

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T19:15:03-07:00
by BrandonMathis
Would you happen to know what the comparative command in RMagick would be to call +depth?

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T19:16:06-07:00
by fmw42
Sorry I do not know RMagick. But you could also just use the equivalent of -depth 4 or 8 or -type palette.

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T19:24:26-07:00
by snibgo
fmw42 wrote:But it seems to me that IM should be doing one or the other automatically. Would you agree?
It surprised me when I first came across it. If the input is 8 bit/channel/pixel, then so is the output, whatever processing has been applied. I raised this in the forum, and someone (Dirk?) said to use "+depth".

"+depth" can waste filespace. In Q32, it gives 32 bit/ch/pixel files. It does so for the sample image in this thread, but IM makes it a palette file so the only extra space is for the palette. (The palette has two entries, each being 32 bit/ch/pixel.)

Alternative behaviours include:

1. Outputs automatically do a "+depth". But this is IM making decisions for us. Perhaps a user is processing 8-bit JPEGs, with calculations in 16-bit but is happy with 8-bit PNG outputs.

2. When writing, IM reads every pixel and counts the number of significant digits. This might give the output more or less bits/ch/pixel than the input, but precision from processing would never be lost. Again, this is IM making decisions for us, and would take processing time.

Ideally, I would like option 2, but switchable at a global level: environment variable IMAGE_MAGICK_AUTO_OUT_DEPTH or something.

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T19:32:52-07:00
by fmw42
Yes, I suppose one should not rely upon IM to make too many decisions for the user. But I would think that going from a bilevel image and adding color (or more graylevels) would be something that IM should recognize, if possible, and upscale the depth or type appropriately.

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-06T20:34:36-07:00
by snibgo
Perhaps IM could issue a warning when an image has more colours than the bit-depth can cope with. This would be fairly simple, and computationally cheap, for bit-depths up to 8.

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-10T07:31:53-07:00
by BrandonMathis
Took a little time to dig it out of the RMagick documentation but I found this

Code: Select all

manipulate! do |img|
  img.colorspace = Magick::SRGBColorspace
  mg.set_channel_depth Magick::AllChannels, 8
  # Begin Recoloring
That fixed my problem :) Black and white tiffs can now be recolored with the whole spectrum of RGB colors.

I do, however, feel that this is a bug in imagmagick as it is pretty unexpected behavior for tiffs. Or maybe this is a bug in libtiff.

Re: Odd behavior when recoloring a black and white Photoshop create tiff

Posted: 2015-08-10T07:52:08-07:00
by snibgo
Thanks for publishing the fix.

Unless told to do otherwise, IM outputs at the same bit-depth as the first input. Perhaps an option could be added to IM to automatically increase bit-depth but, currently, it doesn't.