Select to view content in your preferred language

# Change pixel value in raster file

11832
5
07-11-2017 09:20 AM
New Contributor II

How do I change pixel value in a raster dataset?

5 Replies
MVP Alum

If you have access to the Spatial Analyst extension, one way is to use the Conditional geoprocessing tools

You can also access the Conditional (Con) functions in Raster Calculator:

There are some other possibilities, but it depends on what you would like to do.  Can you provide more details on what you are trying to change?

Chris Donohue, GISP

New Contributor II

Thank you Chris for your reply. I have one MODIS aerosol optical depth data. The raster file have 0 to 254 rowid and 1 to 255 pixel value. The 0 has marked as no data and 255 marked as maximum value. But actually, 0 has value and 255 has no value. I have change the 255 as null and add 1 to all other value to get correct pixel values.

Can you help me to solve this problem?

MVP Alum

For the Null issue, consider using SetNull (Spatial Analyst):

Example from the Help:

Using an Expression:

To set any cell with a value greater than 5 to NoData and have the remaining cells retain their original values, the following parameters could be used on the tool dialog box:

• Input conditional raster : InRas1

Expression : "Value < 5"

Input false raster or constant value : InRas1

Output raster : setnull_1

The equivalent using an expression in Map Algebra is as follows:

``OutRas = SetNull(InRas1 < 5, InRas1)``

As to incrementing the other values up by one, I believe the Raster Calculator would be the way to go, using Map Algebra.

Example from the Help:

Operators can accept a mixture of rasters and numbers. For example, the following adds a constant value of 8 to all the cells in the input raster:

``outRas = Raster("inras1") + 8``

Chris Donohue, GISP

New Contributor II

ok, great. I need to change the pixel values through model builder as I have many AOD raster files so I have to run a loop. so how to change the pixel values in a loop in model building.

MVP Alum

The trick to processing all the rasters is to employ an Iterator in Modelbuilder. This will allow the looping through of each raster.

Here's the Modelbuilder Iterators:

Note, however, if you are conversant with Python, that would probably be more effective than using Modelbuilder (Modelbuilder can be a bit quirky).

Chris Donohue, GISP