possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

under imagemagick 7.0.7.23 when i do :

NewMagickWand(..)
MagickReadImage(.. "myImage.heic" ..)
MagickSetImageFormat(.. "jpg" ..)
MagickGetImageProfiles(.. '*' ..)
=> then it's return an icc profile

under the last one (7.0.8.44) then then same command return NO icc profile :(
so it's a possible regression

however their is another problem under 7.0.7.23, when converting the icc to an sRGB icc i get something absolutely wrong:

NewMagickWand(..)
MagickReadImage(.. "myImage.heic" ..)
MagickSetImageFormat(.. "jpg" ..)
MagickGetImageProfiles(.. '*' ..)
=> then it's return an icc profile
MagickProfileImage(..."icc", sRGB ...)
=> then it's return an image with totally wrong colors :(
like https://stackoverflow.com/questions/559 ... 8_55983690

the original heic file is here: https://filebin.ca/4fy7yPEUfwga/picture.zip
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by snibgo »

Your input is picture_1788442403862513610_-77991839800696479_-50_-50.heic.

According to "identify -verbose" and exiftool, that file has the color model YCbCr, not RGB. IM says there is no ICC color profile. exiftool says there is an embedded RGB profile. I have no idea how an RGB profile should affect a YCbCr image.

Code: Select all

convert picture_1788442403862513610_-77991839800696479_-50_-50.heic out.png
... with v6.9.9-50, the result looks good. PNG can't store YCbCr, so IM converts it to sRGB, with no embedded profile.
snibgo's IM pages: im.snibgo.com
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@snibgo yes convert picture_1788442403862513610_-77991839800696479_-50_-50.heic out.png look good on 7.0.8.44 the but ICC color profile get lost :(

Main problem is that 7.0.8.44 found no ICC color profile when there is one but 7.0.7.23 found one ICC color profile this why I say maybe it's a regression

After with 7.0.7.23 I cannot convert to sRGB If i want to remove the icc profile
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by snibgo »

exiftool says the embedded profile is "Display P3". If you think your file is encoded with P3 colorspace, you can convert the pixel model from YCbCr to sRGB, then assign the P3 profile, then convert to a sRGB profile, like this:

Code: Select all

convert -verbose  picture_1788442403862513610_-77991839800696479_-50_-50.heic -colorspace sRGB -profile P3D65.icc -profile sRGB.icc x1.png
(You must convert to sRGB first, because the profile calculations only work correctly when the channels are RGB.)

This result also looks good, but the saturation is higher than converting without profiles, because P3 has a larger gamut than sRGB.
snibgo's IM pages: im.snibgo.com
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@snibgo : "If you think your file is encoded with P3 colorspace"
I don't know actually, I receive the file from internet and work on it on the fly (it's a web server) :(
So I can only trust what IM say me, but here look like im is wrong (in 7.0.8.44) :(

also, do you know how to convert to sRGB first using the API ? I guess I need to find the equivalent of -colorspace sRGB right ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by snibgo »

exiftool says the embedded profile is "Display P3". IM can't see the profile, possibly because the profile is for RGB channels but the file has YCbCr channels. An RGB profile can't be applied to YCbCr pixels. (Well, it can but the result is bad, as you have seen.)
loki5100 wrote:also, do you know how to convert to sRGB first using the API ?
Sorry, I don't know.
loki5100 wrote:I guess I need to find the equivalent of -colorspace sRGB right ?
Yes.
snibgo's IM pages: im.snibgo.com
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@snibgo: i Found it's MagickSetColorspace(). I did it but it's not help :(

under 7.0.7.23 :

NewMagickWand(..)
MagickReadImage(.. "myImage.heic" ..)
MagickSetImageFormat(.. "jpg" ..)
MagickGetImageProfiles(.. '*' ..) => found one icc profile
MagickSetColorspace(sRGBColorspace)
MagickProfileImage(..."icc", sRGB ...)

colors are still totally wrong :(
did i miss something ?
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@snibgo

Ok I found it's was MagickTransformImageColorspace

so under 7.0.7.23 doing

NewMagickWand(..)
MagickReadImage(.. "myImage.heic" ..)
MagickSetImageFormat(.. "jpg" ..)
MagickGetImageProfiles(.. '*' ..) => found one icc profile
MagickTransformImageColorspace(sRGBColorspace)
MagickProfileImage(..."icc", sRGB ...)

work great

however this not work on the last one 7.0.8.44 as MagickGetImageProfiles(.. '*' ..) => found NO icc profile :(
under 7.0.8.44 it's not possible to convert the heic file to JPG conserving the original P3 icc profile .. on 7.0.7.23 it's work ok
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@snibgo

little question, when I want to convert any image with any kind of icc profiles to a sRGB icc profile do I always need to first convert the image to sRGBColorspace color space and then later apply the icc sRGB color profile ?

MagickTransformImageColorspace(sRGBColorspace)
MagickProfileImage(..."icc", sRGB ...)

right ?

and what the difference between color space and icc profile ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by fmw42 »

No. You either use the equivalent of -colorspace sRGB or you use an sRGB profile. Not both. If the input image has a profile, then you only need to provide the sRGB profile. If the image does not have a profile, then you need to check to see if some other colorspace (not RGB or sRGB). For example if it is CMYK, and no cmyk profile, then you need to provide a CMYK profile first, then the sRGB profile.
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@fmw42

So how to do (programmatically) with my picture (https://filebin.ca/4fy7yPEUfwga/picture.zip)
When I receive it in my server, when I do MagickGetImageColorspace I can see it's not sRGB (YCbCr here) but I see also that there is 1 ICC profile.
how to know if it's an sRGB icc profile or not? because as I understand you if it's an YCbCr icc profile then I can directly do MagickProfileImage(...sRGB..) else I must do MagickTransformImageColorspace

so say me if i m right :
* image with sRGB color space + sRGB icc profile (or no icc profile) =>MagickProfileImage(...sRGB..)
* image with other color space (like YCbCr) + any icc profile (like YCbCr / sRGB icc profile) =>MagickTransformImageColorspace(...sRGB..)

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

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by snibgo »

I don't agree with Fred. The general advice is "use -profile or -colorspace but not both". That is usually good advice. But here the problem is that the colour model isn't correct for the profile, so we need to correct the colour model first.
loki5100 wrote:little question, when I want to convert any image with any kind of icc profiles to a sRGB icc profile do I always need to first convert the image to sRGBColorspace color space and then later apply the icc sRGB color profile ?
Short answer: yes.

Long answer:

A colour model defines the number of colour channels and what each channel represents. Examples: (red green blue), (hue saturation lightness), (cyan magenta yellow).

A colour space uses a particular colour model, but additionally defines parameters (eg primaries and transfer curves) that make pixels colorimetrically precise, so devices know exactly what colour they should show at each pixel. Example colour spaces: sRGB, CIELab, AdobeRGB.

With those definitions, IM's "-colorspace" defines a colour space, because each one can be converted to or from the colorimetrically-defined CIELab or XYZ. IM has a finite number of builtin colorspaces, about 30. "magick -list colorspace" lists these.

"-profile" is another way to define a color space. In particular, ICC profiles are used to define colour spaces that use the (red green blue) or (cyan magenta yellow black) colour models. An infinite number can be defined. An ICC profile can be created for any colour model such as (Y Cb Cr), but I've never seen that. I've only ever seen profiles for (red green blue) and (cyan magenta yellow black).

As a general rule, when an image has an embedded profile and we want to convert to a different colour space, we should use the "-profile" operation.

IM doesn't check that the profile for an operation is consistent with the colour model of the image. That's the problem you had: an image encoded with a (Y Cb Cr) colour model but a profile that needed a (red green blue) model.

Does that answer the question?
snibgo's IM pages: im.snibgo.com
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

@snibgo thanks a lot for this documentative answer! I still not understand one thing, how iphone devices (so quite a lot of users) can send image with YCbCr color space and sRGB color profile and as you say this is non-sense because an RGB profile can't be applied to YCbCr color space? but this work well, when i convert the image to jpg keeping the original YCbCr color space and the original icc color profile (as you say an sRGB color profile but don't know how to check it) it's work well on all browser and app, color are good! why it's possible? if i remove the icc color profile then colors look like washed so the icc color profile is used by the browser to render the image?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by snibgo »

loki5100 wrote:... when i convert the image to jpg keeping the original YCbCr color space and the original icc color profile (as you say an sRGB color profile but don't know how to check it) it's work well on all browser and app, color are good! why it's possible?
JPEGs are often encoded as YCbCr. Browsers and editors automatically and silently convert this to the (red green blue) model because that is what computer screens need. A browser etc can then take account of an embedded RGB profile, which defines what colours should be made, and convert the image to the correct profile for the screen.

ImageMagick will also automatically and silently convert an RGB image to YCbCr when the output format is JPG. And when the input is JPG YCbCr, IM will convert to (red green blue), and take account of an embedded RGB profile.

But IM won't do this automatically for HEIC files. For HEIC, we need to tell it to convert to sRGB.
snibgo's IM pages: im.snibgo.com
loki5100
Posts: 35
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Re: possible regression: unable to get the icc profile of an heic image under 7.0.8.44

Post by loki5100 »

thanks a lot @snibgo !

So as a conclusion, we can say :

1/ there is a regression in IM 6.0.8.44 as it's not possible anymore to find the ICC profile, so impossible anymore to convert the .heic file to jpg keeping the icc profile configuration (it's will be removed, but image stay in YCbCr color Space). Color in the resulting jpg image look like washed

2/IM is not able to convert an YCbCr image with an ICC color profile that is not YCbCr to a sRGB color profile via MagickProfileImage(..sRGBICCProfile...). colors get completely wrong at the end! the only way is to first apply MagickTransformImageColorspace(..sRGBColorspace..) and them MagickProfileImage(..sRGBICCProfile...).

3/ as their is no way in IM to know if an ICC color profile is YCbCr or sRGB then we must always do MagickTransformImageColorspace(..sRGBColorspace..) followed by MagickProfileImage(..sRGBICCProfile...). anyway MagickProfileImage(..sRGBICCProfile...) will always transform the color space to sRGB but if we don't do first by ourself MagickTransformImageColorspace(..sRGBColorspace..) it's will do it very wrongly.

right?
Post Reply