Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue correlating bounding boxes across multiple annotations #1647

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Update zarr dependencies ([#1646](../../pull/1646))

### Bug Fixes

- Fixed an issue correlating bounding boxes across multiple annotations ([#1647](../../pull/1647))

## 1.29.10

### Improvements
Expand Down
38 changes: 30 additions & 8 deletions girder_annotation/girder_large_image_annotation/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,9 @@ def _keysToColumns(self, columns, parts, doctype, getData, selector, length):
if self._datacolumns and akey in self._datacolumns:
self._requiredColumns.add(akey)
self._ensureColumn(
columns, akey, self.commonColumns[akey], doctype,
getData, self.datafileAnnotationElementSelector(akey, cols),
columns, akey, self.commonColumns[akey],
'.'.join(doctype.split('.')[:2]), getData,
self.datafileAnnotationElementSelector(akey, cols),
length)

def _ensureColumn(self, columns, keyname, title, doctype, getData, selector, length):
Expand Down Expand Up @@ -966,13 +967,15 @@ def _commonColumn(self, columns, keyname, doctype, getData, selector):
title = self.commonColumns[keyname]
self._ensureColumn(columns, keyname, title, doctype, getData, selector, None)

def _collectRecordRows(
def _collectRecordRows( # noqa
self, record, data, selector, length, colkey, col, recidx, rows,
iid, aid, eid):
iid, aid, eid, doctype, columns):
"""
Collect statistics and possible data from one data set. See
_collectRecords for parameter details.
"""
getAid = (aid == '' and (doctype.startswith(('folder', 'datafile.'))))
getEid = (eid == '' and (doctype.startswith(('folder', 'datafile.'))))
count = 0
for rowidx in range(rows):
if self.cancel:
Expand Down Expand Up @@ -1000,6 +1003,22 @@ def _collectRecordRows(
if len(col['distinct']) <= self.maxDistinct:
col['distinct'].add(value)
if self._datacolumns and colkey in self._datacolumns:

if getAid:
try:
aid = columns['annotation.id']['where'][doctype][1](record, data, rowidx)
if aid is None:
aid = ''
except Exception:
pass
if getEid:
try:
eid = columns['annotationelement.id']['where'][doctype][1](
record, data, rowidx)
if eid is None:
eid = ''
except Exception:
pass
self._datacolumns[colkey][(
iid, aid, eid,
rowidx if length is not None else -1)] = value
Expand Down Expand Up @@ -1046,7 +1065,7 @@ def _collectRecords(self, columns, recordlist, doctype, iid='', aid=''):
continue
subcount = self._collectRecordRows(
record, data, selector, length, colkey, col, recidx,
rows, iid, aid, eid)
rows, iid, aid, eid, doctype, columns)
if self._datacolumns:
if colkey in self._requiredColumns:
count = min(count, subcount) if count is not None else subcount
Expand Down Expand Up @@ -1406,6 +1425,8 @@ def data(self, columns, requiredColumns=None): # noqa
logger.info(f'Gathering {len(colsout)} x {len(rows)} data')
data, rows = self._collectData(rows, colsout)
self._datacolumns = None
if hasattr(self, '_bboxLookup'):
logger.info(f'Bounding boxes: {sum(len(x) for x in self._bboxLookup.values())}')
for cidx, col in enumerate(colsout):
colkey = col['key']
numrows = len(data)
Expand All @@ -1417,12 +1438,13 @@ def data(self, columns, requiredColumns=None): # noqa
subdata = data
for cidx, col in enumerate(colsout):
colkey = col['key']
numrows = len(data)
numrows = len(subdata)
if colkey in self._requiredColumns and colkey not in specifiedReqColumns:
subdata = [row for row in subdata if row[cidx] is not None]
if len(subdata) < numrows:
logger.info(f'Reduced row count from {numrows} to {len(subdata)} '
f'because of None values in implied column {colkey}')
if len(subdata) and len(subdata) < len(data):
logger.info(f'Reduced row count from {len(data)} to {len(subdata)} '
f'because of None values in implied columns')
data = subdata
if self.cancel:
return
Expand Down