medpy.metric.binary.obj_tpr#
- medpy.metric.binary.obj_tpr(result, reference, connectivity=1)[source]#
The true positive rate of distinct binary object detection.
The true positive rates gives a percentage measure of how many distinct binary objects in the first array also exists in the second array. A partial overlap (of minimum one voxel) is here considered sufficient.
In cases where two distinct binary object in the first array overlaps with a single distinct object in the second array, only one is considered to have been detected successfully.
- Parameters:
- resultarray_like
Input data containing objects. Can be any type but will be converted into binary: background where 0, object everywhere else.
- referencearray_like
Input data containing objects. Can be any type but will be converted into binary: background where 0, object everywhere else.
- connectivityint
The neighbourhood/connectivity considered when determining what accounts for a distinct binary object. This value is passed to
scipy.ndimage.generate_binary_structure
and should usually be \(> 1\). The decision on the connectivity is important, as it can influence the results strongly. If in doubt, leave it as it is.
- Returns:
- tprfloat
A percentage measure of how many distinct binary objects in
result
also exists inreference
. It has the range \([0, 1]\), where a \(1\) denotes an ideal score.
- Raises:
- RuntimeError
If the reference object is empty.
See also
Notes
This is not a real metric, as it is directed. Whatever array is considered as reference should be passed second. A perfect score of \(1\) tells that all distinct binary objects in the reference array also exist in the result array, but does not reveal anything about additional binary objects in the result array (use
obj_fpr
for this).Examples
>>> arr2 = numpy.asarray([[1,0,0],[1,0,1],[0,0,1]]) >>> arr1 = numpy.asarray([[0,0,1],[1,0,1],[0,0,1]]) >>> arr2 array([[1, 0, 0], [1, 0, 1], [0, 0, 1]]) >>> arr1 array([[0, 0, 1], [1, 0, 1], [0, 0, 1]]) >>> obj_tpr(arr1, arr2) 1.0 >>> obj_tpr(arr2, arr1) 1.0
Example of directedness:
>>> arr2 = numpy.asarray([1,0,1,0,1]) >>> arr1 = numpy.asarray([1,0,1,0,0]) >>> obj_tpr(arr1, arr2) 0.6666666666666666 >>> obj_tpr(arr2, arr1) 1.0
Examples of multiple overlap treatment:
>>> arr2 = numpy.asarray([1,0,1,0,1,1,1]) >>> arr1 = numpy.asarray([1,1,1,0,1,0,1]) >>> obj_tpr(arr1, arr2) 0.6666666666666666 >>> obj_tpr(arr2, arr1) 0.6666666666666666
>>> arr2 = numpy.asarray([1,0,1,1,1,0,1]) >>> arr1 = numpy.asarray([1,1,1,0,1,1,1]) >>> obj_tpr(arr1, arr2) 0.6666666666666666 >>> obj_tpr(arr2, arr1) 1.0
>>> arr2 = numpy.asarray([[1,0,1,0,0], [1,0,0,0,0], [1,0,1,1,1], [0,0,0,0,0], [1,0,1,0,0]]) >>> arr1 = numpy.asarray([[1,1,1,0,0], [0,0,0,0,0], [1,1,1,0,1], [0,0,0,0,0], [1,1,1,0,0]]) >>> obj_tpr(arr1, arr2) 0.8 >>> obj_tpr(arr2, arr1) 1.0