From 7adcd960bb4d53f8f24cf78f3477eb4a72dcebb6 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 10 Sep 2024 08:18:33 -0400 Subject: [PATCH] Extend correlating annotation element bounding boxes This ensures that if the bounding box is correlated from data files, folders, or item metadata, the annotation id and name is also correlated with the augmented data for the annotation element. --- CHANGELOG.md | 2 +- .../utils/__init__.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5272fd464..6fa6718c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Bug Fixes - Fix scaling small images in the multi source with bicubic smoothing ([#1627](../../pull/1627)) -- Fix correlating annotation bounding boxes on adjacent items for plottable data ([#1628](../../pull/1628)) +- Fix correlating annotation bounding boxes on adjacent items for plottable data ([#1628](../../pull/1628), ([#1632](../../pull/1632)) ## 1.29.7 diff --git a/girder_annotation/girder_large_image_annotation/utils/__init__.py b/girder_annotation/girder_large_image_annotation/utils/__init__.py index f95b503aa..2edb91168 100644 --- a/girder_annotation/girder_large_image_annotation/utils/__init__.py +++ b/girder_annotation/girder_large_image_annotation/utils/__init__.py @@ -780,8 +780,7 @@ def _keysToColumns(self, columns, parts, doctype, getData, selector, length): if len(cols) == 4: # If we load all of these from annotation elements, use all # three keys: - # for akey in {'annotation.id', 'annotation.name', 'annotationelement.id'}: - for akey in {'annotationelement.id'}: + for akey in {'annotation.id', 'annotation.name', 'annotationelement.id'}: if self._datacolumns and akey in self._datacolumns: self._requiredColumns.add(akey) self._ensureColumn( @@ -1014,6 +1013,10 @@ def _collectColumns(self, columns, recordlist, doctype, first=True, iid='', aid= lambda record, data, row: record['label']['value']) self._commonColumn(columns, 'annotationelement.type', doctype, getData, lambda record, data, row: record['type']) + self._commonColumn(columns, 'annotation.id', doctype, getData, + lambda record, data, row: str(record['_aid'])) + self._commonColumn(columns, 'annotation.name', doctype, getData, + lambda record, data, row: str(record['_aname'])) self._commonColumn(columns, 'bbox.x0', doctype, getData, lambda record, data, row: record['_bbox']['lowx']) self._commonColumn(columns, 'bbox.y0', doctype, getData, @@ -1054,6 +1057,8 @@ def _getColumnsFromAnnotations(self, columns): if ((not self._sources or 'annotationelement' in self._sources) and Annotationelement().countElements(annot) <= self.maxAnnotationElements): for element in Annotationelement().yieldElements(annot, bbox=True): + element['_aid'] = annot['_id'] + element['_aname'] = annot['annotation']['name'] count += self._collectColumns( columns, [element], 'annotationelement', iid=iid, aid=str(annot['_id'])) if not iidx: @@ -1141,15 +1146,18 @@ def computeSelectorAxis(record, data, row): return 0 rows = {} cols = sorted({col for col in self._compute['columns'] if col in self._datacolumns}) - for kidx, key in enumerate(cols): + lencols = len(cols) + needcols = cols + sorted(set(self._requiredColumns) - set(cols) - self.computeColumns) + for kidx, key in enumerate(needcols): for row, value in self._datacolumns[key].items(): if not kidx: rows[row] = [value] elif row in rows and len(rows[row]) == kidx: rows[row].append(value) - rows = {k: row for k, row in rows.items() if len(row) == len(cols)} + rows = {k: row for k, row in rows.items() if len(row) == len(needcols)} if not len(rows): return 0 + rows = {k: row[:lencols] for k, row in rows.items()} if not self._computeFunction(rows): return 0 for key in self.computeColumns: