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

Closed

Unable to create 8-bit grayscale JPEG-2000 images

description

As I discuss in this post and these ImageMagick forum posts (the "Users" forum; as well as the "Magick.NET" forum), I am unable to successfully create 8-bit grayscale JPEG-2000 images in Magick.NET.

I am able to successfully create 8-bit grayscale images via the command line in ImageMagick, so I believe the problem is not a deeper issue with ImageMagick. Rather, Magick.NET does not respect commands to change the Color.

With certain commands (see my discussion linked above in the Magick.NET forum), the JPEG-2000 metadata changes, but the file size does not change appreciably, suggesting that the actual imagery data being written is not changing. With other commands, neither the metadata nor the file size change.
Closed Feb 3 at 8:47 AM by dlemstra

comments

djc88 wrote Dec 22, 2016 at 4:59 PM

As requested here, I've uploaded a test 8-bit grayscale bitmap that reproduces the issue. It's not the same file that I've been using, but it still illustrates the discrepancy. Here is a Google Drive link.

When I use Magick.NET (version 7.0.3.500-Q8-x86), without setting to Grayscale, the jp2 file size is 698 KB. When I set m.ColorSpace to ColorSpace.Gray, the jp2 file size actually increases to 702 KB.

When I use the ImageMagick command-line "convert" tool on Linux Mint (version 6.7.7-10), without setting to Grayscale, the jp2 file size is 698 KB (the same as from Magick.NET). When I pass the "-colorspace gray" argument, the file size decreases to 665 KB.

Not as dramatic of a decrease in file size as I saw with my other file, but it still illustrates a discrepancy in the behavior of the command line vs. Magick.NET.

Could it be related to the version numbers of the two libraries? Has anything changed in the JPEG-2000 encoder between ImageMagick 6.7.7-10 and Magick.NET 7.0.3.500?

dlemstra wrote Dec 26, 2016 at 3:37 PM

I think this has to do that we switched from JasPer to OpenJPEG. I saw that I could reduce the size of the file if I specified the compression rate:
image.Write(jpeg2000FullPath, new Jp2WriteDefines()
{
  // Not sure what is a good value
  Rate = new float[] { 5 }
});

djc88 wrote Jan 3 at 3:11 PM

That code that you provided doesn't work on my machine. I get an error message: "The type or namespace name 'Jp2WriteDefines' could not be found (are you missing a using directive or an assembly reference?)"

Again, my Magick.NET version is 7.0.3.500-Q8-x86.

I also attempted to insert the following code (hoping that it would be equivalent) immediately before the Write command. This gives no errors, but the output jp2 file appears to be unchanged.
m.Settings.SetDefine(MagickFormat.Jp2, "Rate", "5.0");

dlemstra wrote Jan 3 at 4:46 PM

You will need to upgrade Magick.NET to get that new feature. I added the Jp2WriteDefines because of this issue that you created. If you want to stay with the old version you should use rate instead of Rate in the define. The defines are case sensitive.

dlemstra wrote Jan 9 at 1:48 PM

Can I close this issue @djc88?