converting cmyk tif with background transparency to rgb tiff

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting cmyk tif with background transparency to rgb tiff

Post by snibgo »

I don't have Photoshop.

Code: Select all

convert Original.tif[0] -profile sRGB.icc o.tif
Visual comparison with Microsoft Photo Viewer shows no apparent difference between Original.tif and o.tif, whether I have converted with Q8 int (v6.9.0-0), Q8 HDRI (v6.9.0-0) or Q16 int (v6.9.0-0 or 6.9.1--6).

"identify -verbose o.tif" shows the file is sRGB but contains metadata:

Code: Select all

    photoshop:ColorMode: 4
    photoshop:ICCProfile: U.S. Web Coated (SWOP) v2
Perhaps this confuses (some versions of) Photoshop. Converting with "-strip" removes this metadata.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting cmyk tif with background transparency to rgb tiff

Post by fmw42 »

I think the OP's image meta data is messed up. It says USWebCoatedSwop.icc. However, if I remove it and other profiles using -strip and add the icc profile back, then it looks fine in all viewers including PS.

Code: Select all

convert Original.tif[0] -strip -profile /Users/fred/images/profiles/USWebCoatedSwop.icc -profile /Users/fred/images/profiles/sRGB.icc Original_rgb2.tif
But just removing the icc profile by itself, does not work as follows:

Code: Select all

convert Original.tif[0] +profile icc -profile /Users/fred/images/profiles/USWebCoatedSwop.icc -profile /Users/fred/images/profiles/sRGB.icc Original_rgb2.tif
So the issue must be in the xmp or tiff profile, I would guess.

EDIT: Thanks snibgo. We must have posted at about the same time. We came to the same results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting cmyk tif with background transparency to rgb tiff

Post by fmw42 »

snibgo wrote:"identify -verbose o.tif" shows the file is sRGB but contains metadata:

photoshop:ColorMode: 4
photoshop:ICCProfile: U.S. Web Coated (SWOP) v2
Yes, I see that now also and it is very strange. That kind of confirms that IM may not be writing the correct meta data in the resulting image.

I get

Code: Select all

 Properties:
    icc:copyright: sRGB built-in
    icc:description: sRGB built-in
    icc:manufacturer: (lcms internal)
    icc:model: sRGB built-in
 ...
    photoshop:ColorMode: 4
    photoshop:ICCProfile: U.S. Web Coated (SWOP) v2
...
    tiff:photometric: RGB
So there is some conflicting data between what is in the icc and tiff profiles and what is in the photoshop meta data.

This seems like a bug and I have posted to the Bugs forum with a link back to this topic.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting cmyk tif with background transparency to rgb tiff

Post by snibgo »

The problem seems to be Photoshop-specific metadata in the file, which IM is passing through from the input to the output.

I don't know to what extent Adobe support other software messing with Photoshop metadata.

We've seen this type of problem before, eg with imge sizes. Perhaps the best solution is for an IM operation "-stripPhotoshop" or similar that removes all Photoshop metadata.
snibgo's IM pages: im.snibgo.com
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by 246246 »

snibgo wrote: Perhaps the best solution is for an IM operation "-stripPhotoshop" or similar that removes all Photoshop metadata.
This can be done with +profile tiff:37724, but background transparency (that is shown only in Photoshop) is lost.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting cmyk tif with background transparency to rgb tiff

Post by snibgo »

246246 wrote:This can be done with +profile tiff:37724 ...
That doesn't work here.

Code: Select all

convert Original.tif[0] +profile tiff:37724 -profile sRGB.icc o.tif

identify -verbose  o.tif
... still shows:

Code: Select all

    photoshop:ColorMode: 4
    photoshop:ICCProfile: U.S. Web Coated (SWOP) v2
snibgo's IM pages: im.snibgo.com
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by 246246 »

... still shows:

Code: Select all

    photoshop:ColorMode: 4
    photoshop:ICCProfile: U.S. Web Coated (SWOP) v2
It seems that CMYK profile is in XMP profile.
So if you want to remove it, need "+profile xmp" also.
(Or if in icc profile, use +profile icc)

If your concern here is to remove ICC profile related part, I think remove xmp and icc is enough.

Code: Select all

d:\tmp>convert -quiet Original.tif[0] +profile icc +profile xmp tif:- | identify -verbose - | find /i "icc"
 
But adding sRGB.icc comes with Imagemagick windows binary distribution with your command,

Code: Select all

convert -quiet Original.tif[0] +profile xmp +profile icc -profile sRGB.icc o.tif
identify -verbose o.tif | find /i "icc"
    icc:copyright: Copyright 2007 International Color Consortium
    icc:description: sRGB v4 ICC preference perceptual intent beta
    icc:manufacturer: sRGB v4 ICC preference perceptual intent beta
    icc:model: sRGB v4 ICC preference perceptual intent beta
    Profile-icc: 60960 bytes
    icc:copyright: Copyright 2007 International Color Consortium
    icc:description: sRGB v4 ICC preference perceptual intent beta
    icc:manufacturer: sRGB v4 ICC preference perceptual intent beta
    icc:model: sRGB v4 ICC preference perceptual intent beta
    Profile-icc: 60960 bytes
Photoshop CS6 complains.

The embedded ICC profile cannot be use because the ICC profile is invalid. Ignoring the profile.

and seems to open it as CMYK.

Code: Select all

convert -quiet Original.tif[0] +profile xmp +profile icc -colorspace sRGB o.tif
generate photoshop-readable tif, and the background is transparent, but the color becomes orange.

[EDIT]
I understand why
convert -quiet Original.tif[0] +profile xmp +profile icc -profile sRGB.icc o.tif
failed.
convert -quiet Original.tif[0] +profile xmp -profile sRGB.icc o.tif
does not complained by Photoshop, but still color is orange (like -colorspace sRGB case above.)
Last edited by 246246 on 2015-08-30T08:20:45-07:00, edited 1 time in total.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by 246246 »

As far as I tried only way to keep background transparency and keep the color during RGB conversion is:

1) convert tiff to psd with Photoshop
or
convert tiff to psd with ImageMagick and open in Photoshop and lock transparent pixels and save it.
(About lock, related topic is here: viewtopic.php?f=1&t=27740&p=122734)

Then
2) convert psd to tiff with -colorspace sRGB or using profile. At that time, better to remove CMYK profile in XMP first to avoid conflict.

Code: Select all

convert Original.psd +profile xmp -colorspace sRGB o.tif
or

Code: Select all

convert Original.psd +profile xmp -profile sRGB.icc o.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting cmyk tif with background transparency to rgb tiff

Post by fmw42 »

These do not work for me.
wellyman1
Posts: 10
Joined: 2015-08-25T13:46:06-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by wellyman1 »

should I go back to approaching it this way? it did produce the desired result

convert Original.tif -alpha off /Users/tewellman/profiles/sRGB.icc -alpha on rgbout6.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting cmyk tif with background transparency to rgb tiff

Post by fmw42 »

That does not work for me. If I open that in PS, the colors are wrong. And in the other viewers, the transparency is gone.

I also tried

Code: Select all

convert Original.tif[0] \
\( -clone 0 -alpha extract \) \
\( -clone 0 -alpha off +profile "*" \
-profile /Users/fred/images/profiles/USWebCoatedSwop.icc \
-profile /Users/fred/images/profiles/sRGB.icc \) \
-delete 0 +swap -alpha off -compose copy_opacity -composite Original_rgb5.tif
But the alpha was gone. This seems to be a problem with your original image. All my viewers do not display the transparency, except for PS. I will report this on the bugs forum.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by 246246 »

fmw42 wrote:These do not work for me.
How not work? Whatis the result like?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting cmyk tif with background transparency to rgb tiff

Post by fmw42 »

246246 wrote:
fmw42 wrote:These do not work for me.
How not work? Whatis the result like?
This command:

Code: Select all

convert Original.tif[0] +profile "xmp" -profile /Users/fred/images/profiles/sRGB.icc Original_rgb2.tif
In other viewers besides PS, it has the right colors, but no transparency. In PS, it has transparency but has orange color where it should be brown.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by 246246 »

fmw42 wrote:
This command:

Code: Select all

convert Original.tif[0] +profile "xmp" -profile /Users/fred/images/profiles/sRGB.icc Original_rgb2.tif
In other viewers besides PS, it has the right colors, but no transparency. In PS, it has transparency but has orange color where it should be brown.
What I wrote (to get correct image) is convert from psd.
Last edited by 246246 on 2015-08-30T18:24:17-07:00, edited 2 times in total.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: converting cmyk tif with background transparency to rgb tiff

Post by 246246 »

wellyman1 wrote:should I go back to approaching it this way? it did produce the desired result

convert Original.tif -alpha off /Users/tewellman/profiles/sRGB.icc -alpha on rgbout6.tif
fmw42 wrote:That does not work for me. If I open that in PS, the colors are wrong. And in the other viewers, the transparency is gone
Transparency is not 'gone' with this conversion, Original.tif has transparency only detected in Photoshop (at least in Windows, imdisplay shows background as white.)
So it is not lost during this conversion.

Photoshop-only-transparency is lost when one remove 37724 tag from tiff.
fmw42 wrote:

Code: Select all

convert Original.tif[0] \
\( -clone 0 -alpha extract \) \
\( -clone 0 -alpha off +profile "*" \
-profile /Users/fred/images/profiles/USWebCoatedSwop.icc \
-profile /Users/fred/images/profiles/sRGB.icc \) \
-delete 0 +swap -alpha off -compose copy_opacity -composite Original_rgb5.tif
But the alpha was gone. This seems to be a problem with your original image. All my viewers do not display the transparency, except for PS. I will report this on the bugs forum.
This is the case. as you remove all profile in frame 2, photoshop-only-transparency is gone.
It is not stored in Original.tif[0] as alpha, so frame 1 does not contain transparency.

Currently, Imagemagick can handle some photoshop layer in tiff (37724 tag), that include layer image itself, and probably layer mask. But transparency information in 37724 is ignored at least in imdisplay.exe. As it is not standard tiff spec, it seems still reasonable, i.e. IMHO it might be wontfix. (But if this happened in psd, this should be fixed.)
Post Reply