[gdal-dev] Masked histogram calculation

Starms, William waskd6 at missouri.edu
Sat Aug 2 15:38:17 PDT 2025


Hi everyone, I’ve been using GetHistogram but I need to support rasters with alpha channels and those run through nearblack. I don’t see masked histogramming mentioned in the docs. I do see the masked read functions, but it looks like numpy’s masked array histogram function is one of many ma functions that don't work correctly(?) (https://github.com/numpy/numpy/issues/10019)

Does anyone have any creative ideas to share?

For masked data, the simplest seems to be iteratively histogramming manually masked blocks.

It looks like nearblack can handle >4 bands, but I need multibyte dtypes. I was thinking of rasterizing a VRT that uses the new equations system to compute  A | (A >> 8) or maybe a two step equivalent of bool(A) -> sum(A) and running that through nearblack to make an alpha channel for the above method.


Appreciate everyone’s thoughts.

Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250802/c841c8fb/attachment.htm>


More information about the gdal-dev mailing list