This provides an implementation of a gray-weighted distance transform nearly identical in functionality to MATLAB's graydist(I,mask,'quasi-euclidean'). The difference is that the mask is given by an array with the same encoding as the output of our identifyflats function: the algorithm finds paths over components where (flats[pixel] & 1) !=0 and starting from locations where (flats[pixel] & 4) != 0. Every other pixel is skipped, and you don't need to modify the costs raster to prevent them from being visited. The priority queue from #46 is reused here.
As discussed in https://github.com/TopoToolbox/libtopotoolbox/pull/37#issuecomment-2107751658, we can return backlinks to the lower neighbor along the geodesic path. If you don't need the backlinks (e.g because you don't want to allocate the memory for them upfront), it is safe to pass a null pointer as prev. The pointer is always checked before it is accessed.
The tests are fairly basic property-based tests that check that the right costs are assigned to non-flat pixels and presills and that use the backlinks to check that the relative distance between sequential pixels along a path is as expected. I have also manually compared the output of this against that computed in MATLAB, and they are identical.
The different name (gwdt versus graydist) is meant to remind us that they are not equivalent in functionality, and I was already using the gwdt_ namespacing scheme for the gwdt_computecosts function.
Closes #10
This provides an implementation of a gray-weighted distance transform nearly identical in functionality to MATLAB's
graydist(I,mask,'quasi-euclidean')
. The difference is that the mask is given by an array with the same encoding as the output of ouridentifyflats
function: the algorithm finds paths over components where(flats[pixel] & 1) !=0
and starting from locations where(flats[pixel] & 4) != 0
. Every other pixel is skipped, and you don't need to modify the costs raster to prevent them from being visited. The priority queue from #46 is reused here.As discussed in https://github.com/TopoToolbox/libtopotoolbox/pull/37#issuecomment-2107751658, we can return backlinks to the lower neighbor along the geodesic path. If you don't need the backlinks (e.g because you don't want to allocate the memory for them upfront), it is safe to pass a null pointer as
prev
. The pointer is always checked before it is accessed.The tests are fairly basic property-based tests that check that the right costs are assigned to non-flat pixels and presills and that use the backlinks to check that the relative distance between sequential pixels along a path is as expected. I have also manually compared the output of this against that computed in MATLAB, and they are identical.
The different name (
gwdt
versusgraydist
) is meant to remind us that they are not equivalent in functionality, and I was already using thegwdt_
namespacing scheme for thegwdt_computecosts
function.