Add 'gdal raster neighbors' to compute focal statistics#13088
Add 'gdal raster neighbors' to compute focal statistics#13088rouault merged 2 commits intoOSGeo:masterfrom
Conversation
7c24fd8 to
5455d2e
Compare
5455d2e to
0b63f85
Compare
dbaston
left a comment
There was a problem hiding this comment.
I think this is a great addition and makes the VRTKernelFilteredSource so much more useful!
| src_ds.WriteRaster(0, 0, 3, 3, array.array("B", [1, 2, 3, 4, 5, 6, 7, 8, 9])) | ||
|
|
||
| neighbors["input"] = src_ds | ||
| neighbors["kernel"] = "one_3x3" |
There was a problem hiding this comment.
What do you think about specifying the neighborhood size and weighting separately?
neighbors["size"] = 3 # (or [3, 3]) ?
neighbors["weighting"] = "equal" # (or "sharpen", "gaussian_blur") etc.
There was a problem hiding this comment.
I was considering that, but I don't think (or at least I don't know how) all kernels can be set to an arbitrary size. For example, u and v likely only make sense for 3x3. edge and sharpen likely too. gaussian_blur there's likely a formula somewhere, but that's pretty much the only one we can size arbitrarily. I let that for further improvements
There was a problem hiding this comment.
I don't know how many can be arbitrary but "equal" (here, "one") certainly can. GRASS has formulas for "gaussian" and "exponential", https://grass.osgeo.org/grass-stable/manuals/r.neighbors.html#:~:text=For%20the%20gaussian%20weighting%20function,*x+y*y))
These wouldn't need to be implemented now, since we can error out for an unsupported combination of kernel and size, but I think the API should support an arbitrary size even if it's only implemented for an equal-weight kernel.
We could also support non-square kernels by padding with zeros to allow e.g. --weighting equal --size 3 5
There was a problem hiding this comment.
I've adding a commit adding --size (single value), and combining 'size' and 'kernel' values (with only 'equal' being supported for any size value)
0b63f85 to
ff330e7
Compare
9a70ff6 to
7f94de7
Compare
7f94de7 to
cec1e75
Compare
cec1e75 to
a3843fe
Compare
Fixes #12768