Skip to content

Commit e781c4f

Browse files
anna-grimanna-grim
andauthored
feat: supports zipped tiffs (#142)
Co-authored-by: anna-grim <[email protected]>
1 parent 382e933 commit e781c4f

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

demo/demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def evaluate():
2828
2929
"""
3030
# Initializations
31-
pred_labels = TiffReader(pred_labels_path)
31+
pred_labels = TiffReader(pred_labels_path, swap_axes=False)
3232
skeleton_metric = SkeletonMetric(
3333
groundtruth_pointer,
3434
pred_labels,

demo/results-overview.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ Average Results...
1313
Total Results...
1414
# Splits: 31
1515
# Merges: 0
16+
Average Results...
17+
# Splits: 7.9680
18+
# Merges: 0.0000
19+
Split Rate: 114.6940
20+
Merge Rate: 0.0000
21+
% Split Edges: 1.1996
22+
% Omit Edges: 4.5086
23+
% Merged Edges: 0.0000
24+
Edge Accuracy: 95.4914
25+
ERL: 180.8849
26+
Normalized ERL: 0.3949
27+
28+
Total Results...
29+
# Splits: 31
30+
# Merges: 0

demo/results.csv

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
,# Splits,# Merges,Split Rate,Merge Rate,% Split Edges,% Omit Edges,% Merged Edges,Edge Accuracy,ERL,Normalized ERL,GT Run Length
2-
SNT_Data-002,0,,84.0837616185713,,0.0,0.0,0.0,100.0,84.08,1.0,84.08
2+
SNT_Data-002,0,,84.08376161857129,,0.0,0.0,0.0,100.0,84.08,1.0,84.08
33
SNT_Data-035,0,,163.37074041968347,,0.0,0.0,0.0,100.0,163.37,1.0,163.37
4-
SNT_Data-037,1,,211.98055903143307,,0.98,1.96,0.0,98.04,184.57,0.8585,214.98
5-
SNT_Data-038,1,,251.78664303157586,,0.83,1.65,0.0,98.35,144.38,0.5667,254.79
6-
SNT_Data-041,4,,55.46881994891756,,2.83,7.55,0.0,92.45,52.62,0.2286,230.17
4+
SNT_Data-037,1,,211.9805590314331,,0.98,1.96,0.0,98.04,184.57,0.8585,214.98
5+
SNT_Data-038,1,,251.78664303157595,,0.83,1.65,0.0,98.35,144.38,0.5667,254.79
6+
SNT_Data-041,4,,55.46881994891758,,2.83,7.55,0.0,92.45,52.62,0.2286,230.17
77
SNT_Data-043,2,,46.354813254114404,,1.92,9.62,0.0,90.38,35.32,0.3334,105.96
88
SNT_Data-051,0,,106.56843799568803,,0.0,0.0,0.0,100.0,106.57,1.0,106.57
9-
SNT_Data-052,6,,99.17738848187408,,1.37,6.48,0.0,93.52,265.1,0.4184,633.57
10-
SNT_Data-053,15,,98.71530688808681,,1.31,4.46,0.0,95.54,207.79,0.1343,1547.45
11-
SNT_Data-062,2,,105.18979564964228,,0.9,8.11,0.0,91.89,116.9,0.5144,227.24
12-
SNT_Data-074,0,,80.17991450259144,,0.0,0.0,0.0,100.0,80.18,1.0,80.18
9+
SNT_Data-052,6,,99.17738848187402,,1.37,6.48,0.0,93.52,265.1,0.4184,633.57
10+
SNT_Data-053,15,,98.7153068880868,,1.31,4.46,0.0,95.54,207.79,0.1343,1547.45
11+
SNT_Data-062,2,,105.1897956496423,,0.9,8.11,0.0,91.89,116.9,0.5144,227.24
12+
SNT_Data-074,0,,80.17991450259146,,0.0,0.0,0.0,100.0,80.18,1.0,80.18

src/segmentation_skeleton_metrics/utils/img_util.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
from abc import ABC, abstractmethod
1313
from tifffile import imread
1414

15+
import io
1516
import numpy as np
1617
import tensorstore as ts
18+
import zipfile
1719

1820

1921
class ImageReader(ABC):
@@ -168,18 +170,22 @@ class TiffReader(ImageReader):
168170
Class that reads an image with the Tifffile library.
169171
"""
170172

171-
def __init__(self, img_path, swap_axes=True):
173+
def __init__(self, img_path, inner_tiff_filename=None, swap_axes=True):
172174
"""
173175
Instantiates a TiffReader image reader.
174176
175177
Parameters
176178
----------
177179
img_path : str
178-
Path to a TIFF image.
180+
Path to a TIFF image or ZIP archive containing a TIFF image.
181+
inner_tiff_filename : str or None, optional
182+
If img_path is a ZIP file, specifies the TIFF filename inside the
183+
ZIP. Default is None.
179184
swap_axes : bool, optional
180185
Indication of whether to swap axes 0 and 2. Default is True.
181186
"""
182187
# Instance attributes
188+
self.inner_tiff_filename = inner_tiff_filename
183189
self.swap_axes = swap_axes
184190

185191
# Call parent class
@@ -189,7 +195,15 @@ def _load_image(self):
189195
"""
190196
Loads image using the Tifffile library.
191197
"""
192-
self.img = imread(self.img_path)
198+
# Read image
199+
if self.img_path.lower().endswith(".zip"):
200+
with zipfile.ZipFile(self.img_path, "r") as z:
201+
with z.open(self.inner_tiff_filename) as f:
202+
self.img = imread(io.BytesIO(f.read()))
203+
else:
204+
self.img = imread(self.img_path)
205+
206+
# Swap axes (if applicable)
193207
if self.swap_axes:
194208
self.img = np.swapaxes(self.img, 0, 2)
195209

src/segmentation_skeleton_metrics/utils/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def read_txt_from_gcs(bucket_name, path):
267267
"""
268268
client = storage.Client()
269269
bucket = client.bucket(bucket_name)
270-
blob = bucket.blob(filename)
270+
blob = bucket.blob(path)
271271
return blob.download_as_text()
272272

273273

0 commit comments

Comments
 (0)