I need to reduce the processing extent of my raster by some sort of automatic procedure in python. Currently the borders of the dataset I've been using has anomalies (due to the classification of the landsat scanning lines).

ScanLines Classified

I would like to reduce the extent of the raster processing so that when I retrieve the information above by a SetNull function the borders are not processed. Something like Area

Now this can easily be done with an extract by mask function (i.e. figure2) although that would require manual selection of the masking region. Is there a menthod I can utilize to calculate the extent region (ignoring nodata values) minus the border width in the x and y direction of each row/column and then utilize the arcpy.env.extent in Python?

  • Could you just get the extent of the whole raster and then subtract a standard distance from each side? Or is that too simplistic? – Radar Sep 19 '12 at 16:11
  • That would work assuming that the extent is derived from those areas with values rather than the entire area (i.e. nodata values) – BJEBN Sep 19 '12 at 16:48
  • 1
    I'm having a bit of trouble understanding what constitutes a "border". Do you want to automatically detect the scanning anomalies and then crop them? If so, are you looking for a method that would allow you to detect these anomalies? – Radar Sep 19 '12 at 16:52
  • The border is the area of the raster containing values - perhaps the second image above is slightly confusing as I see now that they are outlying values(must of had an extra layer active when i took a screen grab). The solid area above is the raster border - the red square is the desired raster extent while the current raster extent is the entire image(including the white *nodata values) – BJEBN Sep 19 '12 at 18:10

This workflow deals first with the junk floating around the edges and then solves the problem.

  1. Create a binary indicator of the "border" area, which I take to include all surrounding NoData cells. It is convenient to use any value to indicate the border and NoData for the rest, as in SetNull(Not(IsNull('X')), 1):


  2. Regiongroup the result and select the border component. (This can usually be automated by selecting the component with the largest value of [Count].) The image will look almost the same; only a few stray pixels in the center are excluded here--but they must be excluded for the next step to work.

    (An alternative approach is to use morphological operations first to shrink the border and then re-expand it: this erases the isolated bits in the middle.)

  3. Compute the Euclidean distance grid to the border component.


  4. Mask out all small distances in the original image, as in SetNull(([Distance to Border component] < 30), X):


(The final image shows the original border in green overlaid, for reference, on the result.)


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.