Select to view content in your preferred language

ArcGIS Pro, Extract Band arcpy function: Extract using band_name does not match any extract using band_id.

131
0
4 weeks ago
Labels (1)
NickCollis1
New Contributor

Unexpected behaviour is seen in several RGB rasters in ArcGIS Pro. In this example, a test dataset is used – sample data from the Ordnance Survey (OS) 1:25k Scale Colour Raster: https://www.ordnancesurvey.co.uk/products/25k-raster#get

 

The Get sample data button is selected and the Exeter download chosen. This gives a .zip containing a colormap raster, SX99.tif. License data is given by OS on the download page under the Sample Data License link. This is a colormap raster, but the example of interest is for r,g,b rasters that are produced using the “Export Map” functionality. So, a new raster is made from SX99.tif:

 

  1. This raster is brought into a .aprx file. The view is zoomed such that the display is wholly taken up by SX99.tif.
  2. An r,g,b raster is created by Share -> Export Map -> Geotiff Map, using the settings in the below image.

Export-Map-Settings.png

The three individual bands of the r,g,b raster are brought into the .aprx. The format expected is band 1 = red band, band 2 = green band and band 3 = blue band. To test this, within a .aprx, a single cell where r, g and b bands all have different values is found and Identify is run on this cell to get the r,g,b values. These are then checked against the individual band’s values for that cell. The order of the bands is confirmed to be as expected: red, green, blue.

The Extract Band arcpy function is used to create four different exports from the original raster, SX99.tif:

 

from arcpy import env
import arcpy
IN_OUT_RASTER_FOLDER = "C:/Users/mr-mallard/mr-mallards-wonderful-raster-folder/"
IN_RASTER_FILENAME = "SX99_Export.tif"

env.overwriteOutput = True # Allows the tool to over-write existing files.
in_raster = IN_OUT_RASTER_FOLDER + IN_RASTER_FILENAME

# Export band of band_id =2.
band_ids = [2]
out_raster = arcpy.ia.ExtractBand(raster=in_raster, band_ids=band_ids)
output_raster_name = IN_OUT_RASTER_FOLDER + "Exported_band_" + str(band_ids) + ".tif"
out_raster.save(output_raster_name)

# Export each individual band name.
# These are run individually as running within a for loop causes only a single raster to be saved, with names combined.
out_raster = arcpy.ia.ExtractBand(raster=in_raster, band_names=["red"])
output_raster_name = IN_OUT_RASTER_FOLDER + "Exported_band_red.tif"
out_raster.save(output_raster_name)
out_raster = arcpy.ia.ExtractBand(raster=in_raster, band_names=["green"])
output_raster_name = IN_OUT_RASTER_FOLDER + "Exported_band_green.tif"
out_raster.save(output_raster_name)
out_raster = arcpy.ia.ExtractBand(raster=in_raster, band_names=["blue"])
output_raster_name = IN_OUT_RASTER_FOLDER + "Exported_band_blue.tif"
out_raster.save(output_raster_name)

 

Firstly, the export with band_ids = [band_2] is compared to the band_2 raster in ArcGIS Pro using the Equal To tool (https://pro.arcgis.com/en/pro-app/latest/tool-reference/image-analyst/equal-to.htm). The output from this is all 1, confirming that band 2 is exported as expected.

 

Secondly, the export with band_names = [“green”]  is compared to the band_2 raster in ArcGIS Pro using the Equal To tool (https://pro.arcgis.com/en/pro-app/latest/tool-reference/image-analyst/equal-to.htm). The output from this shows the green_band export does not match the band_id = 2 export, which is not expected.

 

Lastly, as a check, the exports with band_names = [“red”] and = [“blue”] are also compared to the band_2 raster in ArcGIS Pro. These also do not match.

 

Why does the export using band_name = “green”, not match the export using band_id =  2?

Tags (3)
0 Kudos
0 Replies