We can use a better metric than num_foreground for reducing the allocation size of UF. That metric is num_transitions: the number of times the previous voxel doesn't match the current voxel when the current voxel is foreground.
This metric is better for several reasons.
1) It can be easily computed in a SIMD fashion and is approximately as quick to compute.
2) It is strictly greater than or equal to the number of provisional labels. Provisional labels are assigned in essentially the same way except that they may use other neighboring voxels to a avoid creating a new label. Therefore, transitions is a safe metric.
3) transitions are strictly less than or equal to the number of foreground voxels. This is simply stated as the transition criterion is anded with the foreground condition.
This allows us to handle every situation the foreground criterion did and also dense datasets too! Connectomics datasets have many label transitions but nearly every voxel is foreground. Therefore, this criterion might make the "sparse" mode obsolete for now as only pathological data (e.g. range(voxels)) or a checkerboard pattern with no background voxels would force a full size allocation.
We can use a better metric than num_foreground for reducing the allocation size of UF. That metric is num_transitions: the number of times the previous voxel doesn't match the current voxel when the current voxel is foreground.
This metric is better for several reasons.
1) It can be easily computed in a SIMD fashion and is approximately as quick to compute. 2) It is strictly greater than or equal to the number of provisional labels. Provisional labels are assigned in essentially the same way except that they may use other neighboring voxels to a avoid creating a new label. Therefore, transitions is a safe metric. 3) transitions are strictly less than or equal to the number of foreground voxels. This is simply stated as the transition criterion is anded with the foreground condition.
This allows us to handle every situation the foreground criterion did and also dense datasets too! Connectomics datasets have many label transitions but nearly every voxel is foreground. Therefore, this criterion might make the "sparse" mode obsolete for now as only pathological data (e.g. range(voxels)) or a checkerboard pattern with no background voxels would force a full size allocation.