Skip to content

Commit

Permalink
Merge pull request #1741 from girder/bioformats-dicom-mag
Browse files Browse the repository at this point in the history
Read magnification values from DICOM when reading them via bioformats
  • Loading branch information
manthey authored Dec 9, 2024
2 parents 4fef43e + 4737d95 commit a5b46d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

- When using the multisource to composite multiple images with alpha channels, use nearest neighbor for upper tiles ([#1736](../../pull/1736))
- Read magnification values from DICOM when reading them via bioformats ([#1741](../../pull/1741))

### Changes

Expand Down
8 changes: 5 additions & 3 deletions sources/bioformats/large_image_source_bioformats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,15 @@ def _computeLevels(self):

def _computeMagnification(self):
self._magnification = {}
metadata = self._metadata['metadata']
metadata = self._metadata.get('seriesMetadata', {}).copy()
metadata.update(self._metadata['metadata'])
valuekeys = {
'x': [('Scaling|Distance|Value #1', 1e3)],
'y': [('Scaling|Distance|Value #2', 1e3)],
}
tuplekeys = [
('Physical pixel size', 1e-3),
('0028,0030 Pixel Spacing', 1),
]
magkeys = [
'Information|Instrument|Objective|NominalMagnification #1',
Expand All @@ -528,11 +530,11 @@ def _computeMagnification(self):
if 'mm_x' not in self._magnification and 'mm_y' not in self._magnification:
for key, units in tuplekeys:
if metadata.get(key):
found = re.match(r'^\D*(\d+(|\.\d+))\D+(\d+(|\.\d+))\D*$', metadata[key])
found = re.match(r'^[^0-9.]*(\d*\.?\d+)[^0-9.]+(\d*\.?\d+)\D*$', metadata[key])
if found:
try:
self._magnification['mm_x'], self._magnification['mm_y'] = (
float(found.groups()[0]) * units, float(found.groups()[2]) * units)
float(found.groups()[0]) * units, float(found.groups()[1]) * units)
except Exception:
pass
for key in magkeys:
Expand Down

0 comments on commit a5b46d1

Please sign in to comment.