Opened 8 years ago

Closed 8 years ago

#5583 closed defect (invalid)

NITF does not work when using ECW to load 16bit channels in JPEG2000 images.

Reported by: cleo Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords:


If a 16bit per channel JPEG 2000 image is found in an NITF file and the ECW driver (tried both v4.2 and v5.1) is used, it will put the data in the low byte instead of the high byte, so the image comes out black. However, the MrSID plugin (v9) works fine.

I don't have any files I can release right now, but I can try to get one if such a file can't be generated.

Change History (6)

comment:1 by Even Rouault, 8 years ago

I don't reproduce that issue with a unsigned 16 bit JPEG2000 (with 11 bit depth) compressed NITF, single channel, and with JP2ECW of the v5.0 SDK.

comment:2 by cleo, 8 years ago

Sorry, I should have specified that these were RGB images. For single channel, we recompute min/max, so it's not as bad. But I'll check what the ranges are for both drivers on single channel.

comment:3 by cleo, 8 years ago

I found the problem. With MrSID, it sets the min/max metadata and when you call GetStatistics(), it also returns the min/max. But with ECW, there is no metadata at all. I have no choice but to assume that all 16 bits are used and this is why the image appears black.

Another problem I'm seeing, even with MrSID, is that I'm not 100% sure how to interpret the data. Take these statistics for example:

Red: 17 - 760

Green: 0 - 493

Blue: 0 - 570

This is supposed to be an 11 bit JPEG 2000 image. This is what is reported by poDS->psImage->nBitsPerSample. But the range is a lot smaller. So if I use 11 bits, the image appears quite dark. Even if I use 10 bits, it's dark. This part I can add an option to select if they want to normalize the image. I believe the image I was given is a BGRN multipectral image. So the number of bits doesn't really bother me. Still, it'd be nice to have the number of bits used. Is there a generic way to obtain it?

Secondly, suppose I do want to normalize the channels, ECW doesn't give min/max. I don't really want to scan the whole file. I'd rather just use MrSID instead.

My two questions are:

  1. How do you get the number of bits per channel in a generic way?
  2. Is ECW supposed to give the min/max like MrSID does?

comment:4 by Even Rouault, 8 years ago

MrSID does a particular thing that other drivers don't do. If its GetStatistics() is called with bApproxOK = TRUE, it also forces their computation (which will be available on overviews), even if bForce is FALSE. This is a very particular behaviour (kind of hacky)

As far as bit depth is concerned, you can read the 'NBITS' metadata item in the 'IMAGE_STRUCTURE' metadata domain of the raster bands. It will indeed return 11 if the NITF metadata is set like that. To get the real range of values, you have to call GetStatistics() with bForce = TRUE.

comment:5 by cleo, 8 years ago

That's unfortunate that the range isn't available. But I can probably work with it. At least the number of bits can be obtained. This ticket can be closed.

comment:6 by Even Rouault, 8 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.