2
2
#
3
3
# deepzoom_tile - Convert whole-slide images to Deep Zoom format
4
4
#
5
- # Copyright (c) 2010-2013 Carnegie Mellon University
5
+ # Copyright (c) 2010-2014 Carnegie Mellon University
6
6
#
7
7
# This library is free software; you can redistribute it and/or modify it
8
8
# under the terms of version 2.1 of the GNU Lesser General Public License
37
37
class TileWorker (Process ):
38
38
"""A child process that generates and writes tiles."""
39
39
40
- def __init__ (self , queue , slidepath , tile_size , overlap , quality ):
40
+ def __init__ (self , queue , slidepath , tile_size , overlap , limit_bounds ,
41
+ quality ):
41
42
Process .__init__ (self , name = 'TileWorker' )
42
43
self .daemon = True
43
44
self ._queue = queue
44
45
self ._slidepath = slidepath
45
46
self ._tile_size = tile_size
46
47
self ._overlap = overlap
48
+ self ._limit_bounds = limit_bounds
47
49
self ._quality = quality
48
50
self ._slide = None
49
51
@@ -69,7 +71,8 @@ def _get_dz(self, associated=None):
69
71
image = ImageSlide (self ._slide .associated_images [associated ])
70
72
else :
71
73
image = self ._slide
72
- return DeepZoomGenerator (image , self ._tile_size , self ._overlap )
74
+ return DeepZoomGenerator (image , self ._tile_size , self ._overlap ,
75
+ limit_bounds = self ._limit_bounds )
73
76
74
77
75
78
class DeepZoomImageTiler (object ):
@@ -124,7 +127,7 @@ class DeepZoomStaticTiler(object):
124
127
"""Handles generation of tiles and metadata for all images in a slide."""
125
128
126
129
def __init__ (self , slidepath , basename , format , tile_size , overlap ,
127
- quality , workers , with_viewer ):
130
+ limit_bounds , quality , workers , with_viewer ):
128
131
if with_viewer :
129
132
# Check extra dependency before doing a bunch of work
130
133
import jinja2
@@ -133,12 +136,14 @@ def __init__(self, slidepath, basename, format, tile_size, overlap,
133
136
self ._format = format
134
137
self ._tile_size = tile_size
135
138
self ._overlap = overlap
139
+ self ._limit_bounds = limit_bounds
136
140
self ._queue = JoinableQueue (2 * workers )
137
141
self ._workers = workers
138
142
self ._with_viewer = with_viewer
139
143
self ._dzi_data = {}
140
144
for _i in range (workers ):
141
- TileWorker (self ._queue , slidepath , tile_size , overlap , quality ).start ()
145
+ TileWorker (self ._queue , slidepath , tile_size , overlap ,
146
+ limit_bounds , quality ).start ()
142
147
143
148
def run (self ):
144
149
self ._run_image ()
@@ -160,7 +165,8 @@ def _run_image(self, associated=None):
160
165
else :
161
166
image = ImageSlide (self ._slide .associated_images [associated ])
162
167
basename = os .path .join (self ._basename , self ._slugify (associated ))
163
- dz = DeepZoomGenerator (image , self ._tile_size , self ._overlap )
168
+ dz = DeepZoomGenerator (image , self ._tile_size , self ._overlap ,
169
+ limit_bounds = self ._limit_bounds )
164
170
tiler = DeepZoomImageTiler (dz , basename , self ._format , associated ,
165
171
self ._queue )
166
172
tiler .run ()
@@ -219,6 +225,9 @@ def _shutdown(self):
219
225
220
226
if __name__ == '__main__' :
221
227
parser = OptionParser (usage = 'Usage: %prog [options] <slide>' )
228
+ parser .add_option ('-B' , '--ignore-bounds' , dest = 'limit_bounds' ,
229
+ default = True , action = 'store_false' ,
230
+ help = 'display entire scan area' )
222
231
parser .add_option ('-e' , '--overlap' , metavar = 'PIXELS' , dest = 'overlap' ,
223
232
type = 'int' , default = 1 ,
224
233
help = 'overlap of adjacent tiles [1]' )
@@ -249,5 +258,5 @@ def _shutdown(self):
249
258
opts .basename = os .path .splitext (os .path .basename (slidepath ))[0 ]
250
259
251
260
DeepZoomStaticTiler (slidepath , opts .basename , opts .format ,
252
- opts .tile_size , opts .overlap , opts .quality , opts .workers ,
253
- opts .with_viewer ).run ()
261
+ opts .tile_size , opts .overlap , opts .limit_bounds , opts .quality ,
262
+ opts .workers , opts . with_viewer ).run ()
0 commit comments