1

Using GDAL 2.4.0 with OpenJPEG 2000 v2.3.0.

gdalinfo reports all four bands of NAIP imagery as "Unknown" colorinterp. Sample image here: https://prd-tnm.s3.amazonaws.com/StagedProducts/NAIP/id_2015/46115/m_4611501_sw_11_1_20150702_20151207.jp2

This messes up apps like mapserver, which are then unable to serve out color images.

I attempted to add colorinterp information via an .aux.xml sidecar file. Gdalinfo reports that the sidecar file is detected and read, but the colorinterp is still unknown. Sidecar file contents below (what is shown is the entire file).

Googling around, I see reference to the openjpeg2000 driver using the sidecar file for georeferencing, but no mention of using it for colorinterp metadata. Can I fix the colorinterp using a sidecar file?

I know I can fix colorinterp by doing gdal_translate, but I have an awful lot of these files (~4TB), and any gdal_translation produces files 3x - 4x bigger. I want to avoid having the files get that big. I suspect the commercial encoders USDA is using are better than OpenJPEG2000, so I'd love to just leave the files alone and interpret the existing bands correctly. How would I do that?

<PAMDataset>
  <PAMRasterBand band="1">
    <ColorInterp>Red</ColorInterp>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG2000</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="2">
    <ColorInterp>Green</ColorInterp>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG2000</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="3">
    <ColorInterp>Blue</ColorInterp>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG2000</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="4">
    <ColorInterp>Grey</ColorInterp>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG2000</MDI>
    </Metadata>
  </PAMRasterBand>
</PAMDataset>
  • I guess that the real problem is not with colorinterpretation but with the 4 band source data. Select the bands which you want to use for the RGB presentation with for example PROCESSING "BANDS=1,2,3". – user30184 Mar 24 at 12:16
  • genius! can you make that an answer so I can accept it? – Bryce Nordgren Mar 25 at 20:49
0

MapServer can handle images with any number of bands but there are some limits in what can be rendered on screen. Images which have only 1 band or 1 data band and either an alpha band or a mask band are rendered by default as greyscale. Coloured presentation is possible through FORMATOPTION PALETTE https://mapserver.org/mapfile/outputformat.html.

Images which have 3 data bands and perhaps an extra alpha/mask band are rendered as RGB color image. Images which have 4 or more data bands get rendered as greyscale. For rendering multiband images as RGB user must select which bands to use with the PROCESSING "BANDS=[R],[G],[B]"directive https://mapserver.org/input/raster.html. Other processing directives, like PROCESSING "SCALE=" may be useful for improving the result.

For using 3 first bands of your image for rendering add this line into your LAYER:

PROCESSING "BANDS=1,2,3"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.