LAB TIF color artifacts after resizing

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?".
Post Reply
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

LAB TIF color artifacts after resizing

Post by axelrose »

Hello all,

I'm converting a LAB TIFF to RGB JPEG. This looks fine without resizing but shows lots of color artifacts when resizing.

Input: http://dl.dropbox.com/u/84530/IM/lab250.tif

Code: Select all

convert lab250.tif lab250.jpg
gives
Image

Code: Select all

convert lab250.tif -resize 200x200 lab250.jpg
gives
Image

Can anybody crosscheck to see if this is a bug?

Many regards, Axel.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: LAB TIF color artifacts after resizing

Post by fmw42 »

I can confirm that.

I believe the problem is that JPG does not support colorspace LAB. So you have to convert to RGB or sRGB

The closest I can come is:

convert lab250.tif -colorspace sRGB -resize 200x200 lab250.jpg
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: LAB TIF color artifacts after resizing

Post by axelrose »

The colorspace parameter hasn't much influence here. The JPEG automatically gets converted into RGB.

Leave out the -resize option and the result is fine.

Regards, Axel.
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: LAB TIF color artifacts after resizing

Post by henrywho »

convert lab250.tif -colorspace RGB -distort resize 200x200 -alpha off +repage -colorspace sRGB sRGB.png
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: LAB TIF color artifacts after resizing

Post by axelrose »

Thanks a lot henrywho! Your command line is a helpful workaround.

Do you have another magic spell for converting LAB PSD files?

If I use this input http://dl.dropbox.com/u/84530/IM/lab250.psd and this command line

Code: Select all

convert lab250.psd -colorspace RGB -distort resize 200x200 -alpha off +repage -colorspace sRGB lab200-psd.jpg
the colors are wrong, see Image

Cheers, Axel.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: LAB TIF color artifacts after resizing

Post by anthony »

More than likely you will need to use profiles to correctly map this LAB colorspace to RGB or sRGB, then either remove teh profile or make sure -colorpsace also matches how IM should think of the color.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: LAB TIF color artifacts after resizing

Post by axelrose »

Hi Anthony,

thanks for taking the time to check my question.

I do not see though how you mean the application of profiles in the IM sense.

If I do

Code: Select all

convert lab250.tif -profile sRGB.icc lab250-tif.jpg
the colors are ok.
If I run

Code: Select all

convert lab250.psd -profile sRGB.icc lab250-psd.jpg
the colors are much different.

LAB is a device independent colorspace and has no profiles.

It's sufficient for me to know that it is simply not possible at the moment to convert LAB PSD colors
but LAB TIFF with contorted "-distort resize" option.

Regards, Axel.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: LAB TIF color artifacts after resizing

Post by fmw42 »

I could not get your pdf file to work either. I suspect that it has something to do with imbedding a LAB image into a PDF. The PDF is masking the LAB information in some way. But that is just a guess. I don't really know that much about PDF or LAB.

You could try using some tool to extract the image from the PDF and then convert it. There must be some tools that will extract images from PDFs. Search on Google. Or see the non-im pdf tools at http://www.imagemagick.org/Usage/formats/#ps
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: LAB TIF color artifacts after resizing

Post by axelrose »

The source is Photoshop, not PDF.
http://dl.dropbox.com/u/84530/IM/lab250.psd
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: LAB TIF color artifacts after resizing

Post by fmw42 »

axelrose wrote:The source is Photoshop, not PDF.
http://dl.dropbox.com/u/84530/IM/lab250.psd
OOPS! Sorry I misread it. The best I can do for you are the following two methods, which produce the same results.


convert lab250.psd -channel rgb -separate +channel -resize 50% lab250_%d.png
convert lab250_0.png -colorspace LAB \
lab250_0.png -compose copyRed -composite \
lab250_1.png -compose copyGreen -composite \
lab250_2.png -compose copyBlue -composite \
-combine -colorspace sRGB lab250a.png


convert lab250.psd -channel rgb -separate +channel lab250_%d.png
convert \( lab250_0.png -resize 50% \) -colorspace LAB \
\( lab250_0.png -colorspace RGB -resize 50% -colorspace sRGB \) -compose copyRed -composite \
\( lab250_1.png -colorspace RGB -resize 50% -colorspace sRGB \) -compose copyGreen -composite \
\( lab250_2.png -colorspace RGB -resize 50% -colorspace sRGB \) -compose copyBlue -composite \
-combine -colorspace sRGB lab250b.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: LAB TIF color artifacts after resizing

Post by anthony »

axelrose wrote: I do not see though how you mean the application of profiles in the IM sense.

If I do

Code: Select all

convert lab250.tif -profile sRGB.icc lab250-tif.jpg
the colors are ok.
If I run

Code: Select all

convert lab250.psd -profile sRGB.icc lab250-psd.jpg
the colors are much different.

LAB is a device independent colorspace and has no profiles.

It's sufficient for me to know that it is simply not possible at the moment to convert LAB PSD colors
but LAB TIFF with contorted "-distort resize" option.

Regards, Axel.
LAB is a specific colorspace, yes. But TIFF is a image file format. A container. As the first command works fine I would thus assume that the TIFF has a LAB color profile attached to the containing image. The question is does the PSD file?

Try (something like) this -- I don't use color profiles much so I am not certain of the exact filenames.

Code: Select all

  convert lab250.psd +profile -profile LAB.icc -profile sRGB lab250-psd.jpg
This first removes any existing profile (precaution), attaches a LAB profile, then converts to sRGB profile.
(really -profile need to have separate remove, set, convert modes -- like -colorspace does - perhaps in IMv7)

Fred -- you are getting very very 'low' level, when there should not be a need.

Code: Select all

 +profile '*' -set colorspace LAB -colorspace sRGB
should do the equivalent of what you are doing. But I have a feeling profiles are the cause of the problem. Not all applications display images according to the images profile!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: LAB TIF color artifacts after resizing

Post by fmw42 »

when I run this:

convert lab250.psd +profile "*" -set colorspace LAB -colorspace sRGB lab250.png

I get a rather bluish looking image.

Also I do not know of any LAB profiles? I am not sure there are any.

I tried many variations of what you suggested first, but to no avail in psd. They work in tiff. So I think there is something either hidden in the psd file, such as the photoshop colorspace=9 --- what is that? -- or IM is not reading such psd lab files correctly.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: LAB TIF color artifacts after resizing

Post by anthony »

I really don't know any more.

Their is a xmp profile in the image, but that is not a color profile.
By default IM thinks of the image as LAB colorspace - so that is good.

I know round trip sRGB->LAB->sRGB colorspace check is working, but that may not mean the actual conversion is working. We probably should check it against a LAB profile conversion.
EG

Code: Select all

  convert rose: -profile sRGB -profile LAB -set colorspace LAB -colorspace sRGB show:
But I don't have the icc profile file installed on my machine! Shows how little I use them!




This however this is showing some problem, as it came out wrong!

Code: Select all

  convert rose: -colorspace RGB -colorspace LAB -colorspace sRGB show:
But this comes out correct

Code: Select all

  convert rose: -colorspace XYZ -colorspace LAB -colorspace sRGB show:
that probably indicates a RGB->LAB conversion failure, so is probably unrelated to this problem.

It should not matter how many -colorspace operations we do, the result should be what ever the final colorspace operation converts too.

Adding this as a colorspace test (currently failing) in source.
Hmm the colorspace trip test is also failing for sRGB->RGB->XYZ->sRGB
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply