Page 1 of 1

LAB TIF color artifacts after resizing

Posted: 2012-04-27T03:22:06-07:00
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.

Re: LAB TIF color artifacts after resizing

Posted: 2012-04-27T09:27:37-07:00
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

Re: LAB TIF color artifacts after resizing

Posted: 2012-04-27T23:56:33-07:00
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.

Re: LAB TIF color artifacts after resizing

Posted: 2012-04-29T03:30:56-07:00
by henrywho
convert lab250.tif -colorspace RGB -distort resize 200x200 -alpha off +repage -colorspace sRGB sRGB.png

Re: LAB TIF color artifacts after resizing

Posted: 2012-04-30T07:01:39-07:00
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.

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T00:21:14-07:00
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.

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T02:38:13-07:00
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.

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T09:49:17-07:00
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

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T10:07:28-07:00
by axelrose
The source is Photoshop, not PDF.
http://dl.dropbox.com/u/84530/IM/lab250.psd

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T10:58:38-07:00
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

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T16:17:45-07:00
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!

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T18:28:56-07:00
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.

Re: LAB TIF color artifacts after resizing

Posted: 2012-05-01T20:00:06-07:00
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