Is it possible to create 8-bit grayscale JPEG-2000?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
djc88
Posts: 9
Joined: 2016-12-21T07:51:47-07:00
Authentication code: 1151

Is it possible to create 8-bit grayscale JPEG-2000?

Post by djc88 »

I am attempting to use Magick.NET to create JPEG-2000 images in C#. (My library came from the ZIP file Magick.NET-7.0.3.500-Q8-x86.) I'm starting from a data array of bytes, creating a C# Bitmap object (called "bmp"), creating a MagickImage from that Bitmap, and writing to a file:

Code: Select all

using (MagickImage m = new MagickImage(bmp))
{
    m.Format = MagickFormat.Jp2;
    m.Settings.SetDefine(MagickFormat.Jp2, "quality", "80");
    m.Write(jpeg2000FullPath);
}
This code successfully creates valid JPEG-2000 files that I can open in FastStone Image Viewer. However, FastStone reports that these are 24-bit RGB files. I want to create 8-bit Grayscale JPEG-2000 files. Is there a command I can call that will change this setting?

I've searched the forum; here are some relevant topics I've found:

This user seems to have had success creating grayscale JPEG-2000 files. Attempting to call equivalent commands in Magick .NET doesn't work for me.
This user seems to have created grayscale JPEG-2000 files. (No details provided.)
This user wanted to create 16-bit grayscale files. (Unresolved.)
Last edited by djc88 on 2016-12-21T12:59:09-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is it possible to create 8-bit grayscale JPEG-2000?

Post by snibgo »

I don't know how to do it in C#, but it works in v6.9.5-3 with no problem:

Code: Select all

convert rose: -colorspace gray r.jp2
Exiftool repors that r.jp2 is JPEG 2000 with one channel.
snibgo's IM pages: im.snibgo.com
djc88
Posts: 9
Joined: 2016-12-21T07:51:47-07:00
Authentication code: 1151

Re: Is it possible to create 8-bit grayscale JPEG-2000?

Post by djc88 »

I think you're right; I've verified it for myself with ImageMagick's command-line "convert" command.

I've tried setting the colorspace to Gray in two ways in my C# code (by uncommenting one of the commented lines at a time):

Code: Select all

using (MagickImage m = new MagickImage(bmp))
{
    m.Format = MagickFormat.Jp2;
    //m.Settings.SetDefine(MagickFormat.Jp2, "colorspace", "gray");
    //m.Settings.ColorSpace = ColorSpace.Gray;
    m.Settings.SetDefine(MagickFormat.Jp2, "quality", "80");
    m.Write(jpeg2000FullPath);
}
I've confirmed with exiftool that the Number Of Components remains 3 in both cases, whereas that value correctly changed to 1 when executed in the command-line.

It appears Magick.NET is not respecting the ColorSpace change. I'll post this question over to the Magick.NET section of the board.

--------

EDIT: FYI, I've posted on the Magick.NET forum, the Magick.NET website, and created an Issue.
Post Reply