Skip to content
New issue

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

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

Already on GitHub? # to your account

merging to master #11

Merged
merged 3 commits into from
Jun 28, 2023
Merged
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
79 changes: 74 additions & 5 deletions docker/wsi-worker/extract_metadata.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,81 @@
import openslide
import sys
import json
import math

def getCurrentLetter(n):
string = ""
while n > 0:
n, remainder = divmod(n - 1, 26)
string = chr(65 + remainder) + string
return string

def calculateGrids(metadata):
verticalSize = 500
horizontalSize = 500
lineThickness = 13
vertical = verticalSize / float(metadata['openslide']['mpp_y']);
horizontal = horizontalSize / float(metadata['openslide']['mpp_y']);
overlay = []
overlayLabel = []
# Make sure we have the necessary information for the slide before we calculate
if ((metadata != None) and metadata['aperio'] and metadata['aperio']['OriginalHeight'] != None and metadata['aperio']['OriginalWidth'] != None):
width = int(metadata['aperio']['OriginalWidth'])
height = int(metadata['aperio']['OriginalHeight'])
gridLineLengthForHeight = (math.ceil(((height + horizontal) / horizontal)) - 1) * horizontal;
gridLineLengthForWidth = (math.ceil(((width + horizontal) / horizontal)) - 1) * horizontal;

# determine where to put the vertical gridlines
i = 0.0
while (i <= (width + vertical)):
overlay.append({
'px': i,
'py': 0,
'width': lineThickness,
'height': gridLineLengthForHeight,
'className': 'gridline'
})
i += vertical

# determine where to put the horizontal gridlines
j = 0.0
while (j <= (height + horizontal)):
overlay.append({
'px': 0,
'py': j,
'width': gridLineLengthForWidth,
'height': lineThickness,
'className': 'gridline'
})
j += horizontal

currentNumber = 0
yy = 0
while (yy < (height)): # loop through the rows
currentLetterCount = 1
currentLetter = getCurrentLetter(currentLetterCount)
i=0
while (i < (width)): # loop through the columns
overlayLabel.append(currentLetter + str(currentNumber))
overlay.append({
'id': 'labelOverlay-' + currentLetter + str(currentNumber),
'px': 0 + (i/vertical * vertical + lineThickness),
'py': 0 + (yy/horizontal * horizontal + lineThickness),
})
i+= vertical
currentLetterCount += 1
currentLetter = getCurrentLetter(currentLetterCount)
yy += vertical
currentNumber += 1
metadata['overlay'] = overlay
metadata['overlayLabel'] = overlayLabel


print("\n ".join(sys.argv))

svsfile = sys.argv[1]
metadata_out = sys.argv[2]
slide = openslide.OpenSlide(svsfile)


metadata = {}
for properties in slide.properties:
if '.' in properties:
Expand All @@ -20,9 +87,11 @@
metadata[mainKey][subkey] = slide.properties[properties]
else:
metadata[mainKey] = {subkey: slide.properties[properties]}

print('metadata_out', metadata_out)
calculateGrids(metadata)
with open(metadata_out, 'w') as metadata_file:
metadata_file.write(json.dumps(metadata))

slide.close()
slide.close();