Select to view content in your preferred language

Replace values in RGB rasters

2177
2
07-01-2013 03:06 AM
bogdanpalade1
Deactivated User
Hello,

My goal is to replace the values of one raster (of all the 3 RGB bands) with the values of another raster (also 3 bands) where the values of the initial raster meet some requirements, for example only where Band_1 (Red) = 205, Band_2 (Green) = 255 and Band_3 (Blue) = 194. The code bellow does not work saying something like the raster 205 is not supported...I also dont know how to loop through the RGB arrays...

Initially I tried to do this in raster calculator but did not figure it out how to do it...
Here I put the code where I want to replace the values of the Image17 with the values of Image16:

import arcpy, os
arcpy.CheckOutExtension("Spatial")

arcpy.env.workspace = r"Z:\BP\TST"
Image16 = r"Z:\BP\TST\16.tif"
Image17 = r"Z:\BP\TST\17.tif"

Image16_red = arcpy.sa.Raster(Image16+"\\Band_1")
Image16_green = arcpy.sa.Raster(Image16+"\\Band_2")
Image16_blue = arcpy.sa.Raster(Image16+"\\Band_3")


Image17_red = arcpy.sa.Raster(Image17+"\\Band_1")
Image17_green = arcpy.sa.Raster(Image17+"\\Band_2")
Image17_blue = arcpy.sa.Raster(Image17+"\\Band_3")

if Image17_red == "205":
    if Image17_green == "255":
        if Image17_blue == "194":
            output_obj = (Image17_red = Image16_red) & (Image17_green = Image16_green) & (Image17_blue = Image16_blue)
            output_obj.save(r"Z:\BP\TST\output.tif")


Could you please give me a hint on how to solve this?

Thank you very much
Tags (2)
0 Kudos
2 Replies
markdenil
Frequent Contributor
If you use Copy Raster or raster To Other Formats to save your three band composite image as a GRID Stack,
you will then have access to the three component GRIDs (one for each band).

If you run the Reclassify on the GRID (band) you want to change,
and then use Composite Bands to reassemble the composite from the GRIDs,
you should accomplish what you want to do.

In short:
1. disassemble
2. adjust
3. reassemble
0 Kudos
bogdanpalade1
Deactivated User
Thank you very much for your reply. Meanwhile it took like 5 minutes to solve it with erdas model maker :). No need to separate and layer stack after...
0 Kudos