HueProcessor doesn't behave as expected #802
Copy link
Copy link
Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of ImageSharp
- I have verified if the problem exist in both
DEBUGandRELEASEmode - I have searched open and closed issues to ensure it has not already been reported
Description
When using HueExtensions.Hue(), the resulting image does not look the way I would expect it to, based on my understanding of what hue is.
Given this example:
I would expect a hue shift of 180 degrees to produce something like this:
However, ImageSharp produces this:
Have I misunderstood what this method is supposed to do? Basically I'm expecting it to behave like the Hue/Saturation dialog in Photoshop does, when you change the hue and Colorize is unchecked.
Steps to Reproduce
- Download and save the first image from above as
example.png. - Run this code:
using (var img = Image.Load("example.png"))
{
img.Mutate(c => c.Hue(180));
using (var stream = File.Create("example-180.png"))
{
img.SaveAsPng(stream);
}
}System Configuration
- ImageSharp version:
1.0.0-beta0005 - Other ImageSharp packages and versions:
none - Environment (Operating system, version and so on):
Windows 10 Pro 1809 x64 v10.0.17763.194Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-43-generic x86_64)
- .NET Framework version:
.NET Core 2.1
Reactions are currently unavailable



Activity
Nacimota commentedon Jan 6, 2019
Okay I think I understand what's going on here. I had a dig around in the source and it pretty explicitly states that lum is preserved in the filter:
ImageSharp/src/ImageSharp/Processing/KnownFilterMatrices.cs
Line 329 in 441942b
I guess my question then becomes: should it, though? It doesn't seem intuitive to me, at least not as a default. Maybe we could get a filter that ignores luminosity? I don't have much experience with graphics programming so I'll have to do a lot of thought/research if I'm to create one myself.
JimBobSquarePants commentedon Jan 6, 2019
Hi @Nacimota
This is one of those situations where what Photoshop does I'd describe as wonky. Here's a fiddle demonstrating what CSS does. As you can see the output matches the behaviour there exactly which is what I would expect.
https://jsfiddle.net/37dyftxz/
I don't plan on adding a filter that replicates the unorthodox behaviour but if you wanted to the maths is demonstrated here.
http://graficaobscura.com/matrix/index.html
Hope that makes sense.
Cheers
James
Nacimota commentedon Jan 6, 2019
Hi, @JimBobSquarePants
Thanks for your quick reply. I think I'm just not understanding this stuff properly. One of my main issues with this hue function is that it seems to colourize grey parts of an image under certain conditions.
So for example when I take this image:

And run it through ImageSharp with a rotation of 90 degrees, I get this:

When I use the same image and 90 degree shift in your CSS example, the image stays grey as I would expect it to. Surely if you shift the hue of a pixel with no saturation, it should remain unchanged?
JimBobSquarePants commentedon Jan 6, 2019
Now that is interesting!
Here's the source for hue rotation in Chromium. Our matrice calculation looks the same (different indices but that's due to the 1D nature of their array). I'll do some experimentation.
https://cs.chromium.org/chromium/src/cc/paint/render_surface_filters.cc?l=72
Nacimota commentedon Jan 8, 2019
After discussing this in gitter, I've been encouraged to post a couple of extra examples for clarity. Both of these comparison pictures use a 90 degree shift as well. It seems like the further you are from 180 or 0 degrees, the more incorrect the result becomes:
The middle image on the bottom there is my attempt at implementing the "simple" (non-luminance-preserving) filter described on the graficaobscura page linked above.
Update test references. Fix #802
jsheely commentedon May 16, 2022
Did anyone figure out how to do it so it works like how Photoshop does hue processing. I'm not getting any yellow.
I'm not sure I understand how to use the Fix Colors Filters PR if that is a fix or not
jsheely commentedon May 17, 2022
@Nacimota Would you be able to post a function that handles the filter processing you were able to come up with?
JimBobSquarePants commentedon May 17, 2022
Hey @jsheely can you please stop spamming closed issues. If you have a problem report it properly like a professional