1

Further to my question on SO I'm trying to check the validity of bitmaps. Mainly for transparent or black pixels.

I'm new to ArcMap, and I now know that Python scripts can be run from Arc.

Any hoops, the following script loops over the bitmap pixel by pixel using Pillow.

# get image (theFile) & threshold (th)
f = theFile
img = Image.open(theFile)

w = img.size[0]
h = img.size[1]

pix = img.load()


blackCount = 0
for y in range(h):
  for x in range(w):
    p = pix[x,y]
    r,g,b, a = p

    print ("r, g, b: %s, %s, %s" % (r, g, b))

    if (r <= th) & (g <= th) & (b <= th):
      blackCount +=1

However, I realised that Pillow can't handle large bitmap files (I'm looking at images in excess of 2GB)

What's the best way to achieve this through ArcMap?

Bearing in mind I need to look over hundreds of directories containing each tiff. The results just need to be in the form of a text file - damage to each bitmap(s) (number of pixels effected) and the name of the file(s) in question.

4
  • Have you looked into ArcPy?
    – PolyGeo
    Commented Mar 23, 2016 at 11:04
  • 1
    What exactly are you trying to achieve?
    – Aaron
    Commented Mar 23, 2016 at 11:52
  • Find black & transparent pixels in large tiff files Commented Mar 23, 2016 at 11:59
  • 2
    Have you looked into converting the raster into numpy arrays?
    – crmackey
    Commented Mar 23, 2016 at 14:24

1 Answer 1

2

I would go as @crmackev suggest. Get the rasters into numpy arrays. Here you have some basic code to do that: How to get your raster in Numpy and get cell's value.

  # Dem_Raster to array
  # This will get the raster info into a Numpy array (m cols by n rows)
  array_dem = arcpy.RasterToNumPyArray(source_dem, nodata_to_value=-99999)
  #This will get you the number of rows and columns in your array
  (max_rows, max_cols) = array_dem.shape

  # Loop thru all the cells in array
  for m in max_rows:
      for n in max_cols:
          cell_value = array_dem.item(m,n)
          # do your process here...
          if cell_value = black   # this is not python, its pseudocode
             black_count += 1
       print black_count.

Hope this helps.

1
  • I'd warn that this will have the same issue as Pillow - running out of memory when the array read is too large. So you'll really want to write a loop and read windows of your raster into the array using the lower_left_corner, nrows and ncols arguments as well.
    – om_henners
    Commented Mar 23, 2016 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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