Opened 12 years ago
Closed 12 years ago
#4343 closed defect (fixed)
GDAL incorrectly sets irepband information when saving nitf->nitf
Reported by: | jeepingben | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 1.9.0 |
Component: | default | Version: | svn-trunk |
Severity: | normal | Keywords: | |
Cc: |
Description
I found this while using GDAL to convert from uncompressed NITF to JPEG2000 compressed NITF, but it happens when converting uncompressed nitf to uncompressed nitf as well.
The setting of IREP and IREPBAND seems to be based on a series of special cases and for any case that doesn't match the special case IREP is set to MONO and IREPBAND is set to M for all bands.
The attached file has IREP MULTI and GRBX band-order. If I change the bandorder to RGBX, it works as expected. This was tested using gdal-translate from a recent SVN build.
From the project I am working on, I tried explicitly setting the color interpretation for the bands before writing and it did not help.
Attachments (2)
Change History (8)
by , 12 years ago
Attachment: | multi-grbx.r0 added |
---|
comment:1 by , 12 years ago
I somehow manage to get a result close to what you want by using SetColorInterpretation() after creating the file. The only thing you cannot do is write X as a value. However I can imagine that the driver could be easily expanded to write custom value, for example with a new creation option "IREPBAND=val1,val2,...,valN" or implement SetMetadataItem() at the band level so that SetMetadataItem("IREPBAND", "X") works.
from osgeo import gdal ds = gdal.GetDriverByName('NITF').Create('grbx.ntf', 1, 1, 4) ds.GetRasterBand(1).SetColorInterpretation(gdal.GCI_GreenBand) ds.GetRasterBand(2).SetColorInterpretation(gdal.GCI_BlueBand) ds.GetRasterBand(3).SetColorInterpretation(gdal.GCI_RedBand) ds.GetRasterBand(4).SetColorInterpretation(gdal.GCI_Undefined) # write M actually ds = None
comment:2 by , 12 years ago
Thanks for the reply,
I was able to set the color interpretation on the output file, but only when writing uncompressed NITF, if I write a JPEG2000 nitf, I still get 'M' for all IREPBANDs.
Adding a creation option would be very helpful especially for ISUBCAT, currently I see no way to preserve it.
Supporting other values (X, IR, etc) for IREPBAND is not so important.
comment:3 by , 12 years ago
I've successfully managed to adapt the above script to produce a JPEG2000 NITF with B,G,R order... (only tested with trunk)
from osgeo import gdal ds = gdal.GetDriverByName('NITF').Create('grbx.ntf', 128, 128, 4, options = ['IC=C8']) ds.GetRasterBand(1).SetColorInterpretation(gdal.GCI_GreenBand) ds.GetRasterBand(2).SetColorInterpretation(gdal.GCI_BlueBand) ds.GetRasterBand(3).SetColorInterpretation(gdal.GCI_RedBand) ds.GetRasterBand(4).SetColorInterpretation(gdal.GCI_Undefined) ds.GetRasterBand(1).Fill(0) ds.GetRasterBand(2).Fill(0) ds.GetRasterBand(3).Fill(0) ds.GetRasterBand(4).Fill(255) ds = None
comment:4 by , 12 years ago
I think I figured out why this is working for your script, but not for my program. I'm using createCopy. This means that nitfdataset.cpp:599 is never reached, so bJP2Writing is false. The code at nitfdataset.cpp:136 isn't called and my changes to color interpretation are not saved. I would expect createCopy to get the color interpretation from the source image, or possibly to let me set it.
by , 12 years ago
Attachment: | irepband_and_isubcat.patch added |
---|
comment:5 by , 12 years ago
I've attached a patch which allows passing in IREPBAND and ISUBCAT as creation options. It expects a comma separated list of values in band order.
Example: IREPBAND=B ,G ,R ISUBCAT=560 ,480 ,660
comment:6 by , 12 years ago
Milestone: | → 1.9.0 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
4 band uncompressed nitf, non-rgb band order