-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct colour space before cropping #1281
Conversation
def runConvertCmd(op: IMOperation): Future[Unit] = Future((new ConvertCmd).run(op)) | ||
def runIdentifyCmd(op: IMOperation): Future[List[String]] = Future { | ||
val cmd = new IdentifyCmd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you presuming that the identify command infers the colorspace from (a) some heuristic on the image data itself, or (b) uses image metadata?
When looking at this previously I was defeated by the ImageMagick source code being impenetrable to me. I think testing indicated that it is in fact (b). If this is the case then images with incorrect or missing metadata will still fail this test.
To confirm which situation is occurring you could intentionally strip all metadata from an image and then run the identify command to see whether it can correctly infer the colorspace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm which situation is occurring you could intentionally strip all metadata from an image and then run the identify command to see whether it can correctly infer the colorspace.
Yes, it (GM) can. After running -strip
, the jpeg-colorspace-name
is still present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theefer i'd try this with the same setup as in production (can't actually remember if we are using IM or GM, and the version may have an impact).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work fine on the cropper instance from some quick tests.
💎! Thanks, @theefer, great explanation! Just some thoughts as I can’t read code:
Are we stripping both I’m worried about robustness of our colour model inference via In general with that, I would like to see if among all our imagery there is even one image that is not correctly identified by the above but opens in Photoshop. If yes, I would like to find more robust way of identification. Only completely broken images have no colour model... The above detection could inform our db (it may be useful to list colour model in Show all metadata and be able to search for it): #765 |
This. I think I gave up last time I tried this because it's not possible to work out the colorspace without the metadata, (which kind of defeats the point). I seem to remember there are Java libraries that do run heuristics on the actual image data (possibly ImageJ) or indeed as @paperboyo says it's possibly more accurate in the most recent versions of ImageMagick. |
As far as we could see, @paperboyo what are your worries specifically? Could we run some tests to verify them?
No, I ran into an issue when stripping just ICC and I thought ICM was the canonical name, but if they're genuinely different we could try and strip both? |
@kenoir In both GM and IM, these properties are still present after |
If this PR fixes the problem in TEST then it's all fine but it's worth trying. I seem to remember being frustrated with the difference between my sandbox and a "real" instance. |
This is a comparison of latest IM & GM properties we are interested in, that survive
|
As fare as I know, when they differ, it pertains only to filename extensions. Part of the image spec is ICC, so I’m not sure why IM or GM even lets you differentiate between them (running any should strip ALL colour profile data). Okay, I’ve just checked: added an ICM profile to one image and ICC profile to another (the same profile, really, just different filenames :). Then run Annoyingly, if you do just That said, on an unrelated note, I can’t make latest GM to accept |
I have played around quite a lot with that command and it differs quite a lot dependant on OS too. |
Oh, no! That means that ICC profiles are treated by both apps as files instead of image characteristics. It’s convenient when adding and extracting, but definitely not in this instance... At least IM is listing @theefer re:identifying specific profiles |
Now stripping both icm and icc cc @paperboyo Added some tests for the colour model detection using a few sample images with and without embedded profiles. We should consider adding more tests around the |
// If matching, all is well, just pass through | ||
case (icc, model) if icc == model => base | ||
// If no colour model detected, we can't do anything anyway so just hope all is well | ||
case (_, None) => base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth logging out these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth logging out these cases?
I do think so. It's generally interesting to me what is the composition of the whole db in terms of colour models, colour profiles. Not that (all) the metadata isn't interesting ;)
👍 |
Correct colour space before cropping
Currently, the cropper fails in at least two cases:
The solution is to always read out both the embedded ICC profile colour space and the image data colour model and compare them before any conversion.
If they match, great, we can just apply our normal conversion to sRGB profile (from whatever profile is correctly embedded).
If they don't match, either because there is no embedded ICC profile, or because the embedded ICC profile is not matching the actual colour model, then we strip any embedded profile and replace it with a generic ICC profile that matches the actual colour model of the image data. Note that there is no guarantee that the profile will exactly match the image data, but it's a best effort estimate with standard ICC profiles. We can then resume the normal flow of converting the image to the desired output profile (sRGB), etc.
Initial tests with various images with mismatching or missing ICC profiles gave correct results.
This will also be used to correct the colour space of thumbnails we generate, in a future PR.
Thanks to @paperboyo for his big help with this!
TODO