This project has moved and is read-only. For the latest updates, please go here.

Composite Multiply Gray Scaled Images

Jun 1, 2015 at 9:39 AM
I'm trying to mimic auto white balance part from Fred's ImageMagick script with the latest version, but the result seems to be different from expected.
The mask created by composite operation is a RGB image instead of a gray scaled image.
What is causing the difference from command line behavior?
using (MagickImage mask = image.Clone())
    mask.ColorSpace = ColorSpace.HSB;

     using (MagickImage newMask = mask.Separate(Channels.Green).First())
         using (MagickImage maskBlue = mask.Separate(Channels.Blue).First())
             // Becomes a RGB image.
             newMask.Composite(maskBlue, CompositeOperator.Multiply);
Jun 2, 2015 at 9:29 AM
The result image created by 6.8.x build is a gray scaled image, which is the same as convert command.
The 7.0.x builds created a tinted image.
Is there a new setting that I missed or is this a bug in 7.0.x builds?
Jun 2, 2015 at 6:32 PM
This could be a bug in ImageMagick 7 but might also be an intentional change. I will take a look at it this weekend.
Jun 3, 2015 at 3:17 AM
Thank you for your help.
Jun 8, 2015 at 9:10 AM
Edited Jun 8, 2015 at 9:12 AM
I was able to find the issue and this will be fixed in the next release. I also added a new unit test to make sure this stays fixed.
Sep 18, 2015 at 8:57 AM

I tried out the latest version, but still has the same issues in various places.
If I do
convert.exe 1.jpg -colorspace HSB -channel B -separate +channel -solarize 50% 2.jpg
clone.ColorSpace = ColorSpace.HSB;
using (var layer = clone.Separate(Channels.Blue).First())
    layer.Solarize(Quantum.Max / 2);
The convert.exe result will be gray scaled, but Magick.NET is not.

The initial post composites two channel images also still not showing the correct result.
Can you look into the issues again?
Thank you.

P.S. Another recommendation is change Solarize method's parameter "factor" from double to Percentage to match ImageMagick's documentation. I had to play around to match the values.
Sep 18, 2015 at 12:29 PM
I will look into both issues this weekend. I already added an extra overload to Solarize to accept a Percentage. This will be available in the next release of Magick.NET.
Sep 19, 2015 at 11:01 PM
Both problems have been resolved. It turns out that my unit test was incorrect and did not detect the change that broke the code again.... After the test was fixed it failed. But after my change to ImageMagick it passed the test again. Sorry for the inconvenience. The fix will be included in the next release of Magick.NET that I will try to publish tomorrow.
Sep 21, 2015 at 9:30 AM
Tested the latest release and got the correct results!

I seem to find another bug in AutoLevel, which produce different result from ImageMagick's command line -auto-level.
I could use image's min and max and Level method to get the same result as command line -auto-level, so it seems the problem is in AutoLevel method.
Sep 21, 2015 at 9:53 AM
Can you post an example of the command line and the code that you are using in Magick.NET?
Sep 21, 2015 at 11:33 AM
I tried the following:
convert 1.jpg -auto-level output.jpg
using (var image = new ImageMagick.MagickImage("1.jpg"))
using (var image = new ImageMagick.MagickImage("1.jpg"))
    double min = 100 * image.Statistics().Composite().Minimum / Quantum.Max;
    double max = 100 * image.Statistics().Composite().Maximum / Quantum.Max;
    image.Level(new Percentage(min), new Percentage(max));
I get the same results from 1 & 3.
Sep 21, 2015 at 12:00 PM
Another thing I tried today that I quite can't get around.
I tried compositing images with ColorDodge, but can't get the right results.
I'm wondering if it's the alpha channel that messes it up.
convert 1.jpg ( +clone -fill #d29901 -colorize 100% -alpha set -channel A -evaluate set 40% +channel ) -compose ColorDodge -composite test.jpg
using (var image = new ImageMagick.MagickImage("1.jpg"))
using (var clone = image.Clone())
    clone.Colorize(new MagickColor("#d29901"), new Percentage(100));
    clone.Evaluate(Channels.Alpha, EvaluateOperator.Set, Quantum.Max * 0.4);
    image.Composite(clone, CompositeOperator.ColorDodge);
Any insights?

Sep 21, 2015 at 10:27 PM
I can confirm that your problem with ColorDoge is a bug in ImageMagick 7. I just pushed a patch to our GIT repository to fix this. I will get back to you on the AutoLevel method later. I know what is going on but I am not sure yet how to handle this.
Sep 22, 2015 at 4:34 AM
Thanks for the quick response.

I assume the next build of Magick.NET will come with the ColorDodge fix?
Since I can use the work around for AutoLevel, I can replace it for now.
By the way, is InverseLevel (+level) function missing? I only find InverseLevelColors.

Thanks again.
Sep 22, 2015 at 11:48 AM
The next version will include that fix. The InverseLevel function is missing because it is kind of hidden in the C API. I will make sure to add this before the next release.
Sep 22, 2015 at 11:49 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.