Closed mitch-1211 closed 2 days ago
So under metrics/image.py we see that in the definition of the SizedDiskRegion
class, name
is set to a constant string value: name: str = "Disk Region"
Under core/image.py in the compute
function, we see how the dictionary is populated:
for metric in metrics:
metric.inject_image(self)
value = metric.context_calculate()
self.metrics.append(metric)
metric_data[metric.name] = value
So as metric.name
is not a unique key (name: str = "Disk Region"
), we see the value get overwritten as each metric of the same type is calculated, resulting in a single value returned in the dictionary that corresponds to the last metric evaluated.
This would not be an issue if different types of metrics were calculated, e.g. combining a SizedDiskLocator
with a GlobalDiskLocator
There is a workaround, but it just requires more lines of code:
def get_bb_location(estimate_point):
bb_location = img.compute(
metrics=[
SizedDiskLocator.from_center_physical(
expected_position_mm=estimate_point,
search_window_mm=(7,7),
radius_mm=3,
radius_tolerance_mm=2
)
]
)
return bb_location
# +ve Y = lower in image
# +ve X = right side of image
bb_estimates = [
Point(0,0), # centre [0]
Point(0,57.5), # bottom inner [1]
Point(0,-57.5), # top inner [2]
Point(57.5,0), # right inner [3]
Point(-57.5,0), # left inner [4]
Point(0,107.5), # bottom outer [5]
Point(0,-107.5),# top outer [6]
Point(107.5,0), # right outer [7]
Point(-107.5,0) # left outer [8]
]
bb_locations = []
for estimate in bb_estimates:
bb_locations.append(get_bb_location(estimate)[0])
Yup, known issue that's still outstanding. https://forum.pylinac.com/t/retrieving-multiple-metrics-information/419. I will work on it early next week. Thanks!
Thanks @jrkerns didn't realise you could override the metric name, that will get me out of trouble for now
Describe the bug using image metrics with
SizedDiskLocator
to find BBs in an image. Only the last metric to be evaluated is returned in the dictionary. The dictionary should contain the results of all metrics evaluated.To Reproduce Steps to reproduce the behavior: Run the following code:
bb_locations
is a dictionary containing a single entryExpected behavior
bb_locations
is a dictionary containing the points of BBs that were close top1
andp2