Skip to content

Commit ea852b3

Browse files
authored
Merge pull request #989 from DigitalSlideArchive/ppc-frame-style
Support handling frame and style parameters
2 parents 6b4b60a + df86a92 commit ea852b3

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

histomicstk/cli/PositivePixelCount/PositivePixelCount.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111

1212

1313
def tile_positive_pixel_count(imagePath, tilePosition, it_kwargs, ppc_params,
14-
color_map, useAlpha, region_polygons):
14+
color_map, useAlpha, region_polygons, style):
1515
tile_start_time = time.time()
16-
ts = large_image.getTileSource(imagePath)
16+
ts = large_image.getTileSource(imagePath, style=style)
1717
tile = ts.getSingleTile(tile_position=tilePosition, **it_kwargs)
1818
mask = utils.polygons_to_binary_mask(
1919
region_polygons, tile['x'], tile['y'], tile['width'], tile['height'])
20-
result, ppcmask = ppc.count_image(tile['tile'], ppc_params, mask)
20+
img = tile['tile']
21+
if len(img.shape) == 2:
22+
img = img.reshape((img.shape[0], img.shape[1], 1))
23+
if len(img.shape) == 3 and img.shape[-1] == 1:
24+
img = np.repeat(img, 3, axis=2)
25+
result, ppcmask = ppc.count_image(img, ppc_params, mask)
2126
tile.release()
2227
ppcimg = color_map[ppcmask]
2328
if not useAlpha:
@@ -27,7 +32,9 @@ def tile_positive_pixel_count(imagePath, tilePosition, it_kwargs, ppc_params,
2732

2833
def main(opts):
2934
pprint.pprint(vars(opts))
30-
ts = large_image.getTileSource(opts.inputImageFile)
35+
if not opts.style or opts.style.startswith('{#control'):
36+
opts.style = None
37+
ts = large_image.getTileSource(opts.inputImageFile, style=opts.style)
3138
sink = large_image.new() if getattr(opts, 'outputLabelImage', None) else None
3239
tiparams = utils.get_region_dict(opts.region, None, ts)
3340
region_polygons = utils.get_region_polygons(opts.region)
@@ -50,6 +57,10 @@ def main(opts):
5057
tiparams['region']['width'], tiparams['region']['height'])
5158
tiparams['format'] = large_image.constants.TILE_FORMAT_NUMPY
5259
tiparams['tile_size'] = dict(width=tileSize, height=tileSize)
60+
try:
61+
tiparams['frame'] = int(opts.frame)
62+
except Exception:
63+
pass
5364
tileCount = next(ts.tileIterator(**tiparams))['iterator_range']['position']
5465
start_time = time.time()
5566
if tileCount > 4 and getattr(opts, 'scheduler', None) != 'none':
@@ -64,7 +75,7 @@ def main(opts):
6475
futureList.append(client.submit(
6576
tile_positive_pixel_count,
6677
opts.inputImageFile, tile_position, tiparams, ppc_params,
67-
color_map, useAlpha, region_polygons))
78+
color_map, useAlpha, region_polygons, opts.style))
6879
for idx, future in enumerate(futureList):
6980
result, ppcimg, x, y, mask, tile_start_time = future.result()
7081
results.append(result)
@@ -79,7 +90,7 @@ def main(opts):
7990
tile_position = tile['tile_position']['position']
8091
result, ppcimg, x, y, mask, tile_start_time = tile_positive_pixel_count(
8192
opts.inputImageFile, tile_position, tiparams, ppc_params,
82-
color_map, useAlpha, region_polygons)
93+
color_map, useAlpha, region_polygons, opts.style)
8394
results.append(result)
8495
if sink:
8596
sink.addTile(ppcimg, x, y, mask=mask)

histomicstk/cli/PositivePixelCount/PositivePixelCount.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<name>region</name>
2323
<label>Analysis ROI</label>
2424
<longflag>region</longflag>
25-
<description>Region of interest where analysis is performed. This is either -1,-1,-1,-1 for thw hole image, or a four-element vector in the format "left, top, width, height", or a list of four or more x,y vertices to specify a polygon.</description>
25+
<description>Region of interest where analysis is performed. This is either -1,-1,-1,-1 for the whole image, or a four-element vector in the format "left, top, width, height", or a list of four or more x,y vertices to specify a polygon.</description>
2626
<default>-1,-1,-1,-1</default>
2727
</region>
2828
<float>
@@ -157,6 +157,24 @@
157157
<description>Average intensity of positive pixels excluding strong positive pixels</description>
158158
</float>
159159
</parameters>
160+
<parameters advanced="true">
161+
<label>Frame and Style</label>
162+
<description>Frame parameters</description>
163+
<string>
164+
<name>frame</name>
165+
<longflag>frame</longflag>
166+
<label>Frame Index</label>
167+
<description>Frame index in a multi-frame image</description>
168+
<default>{#control:#current_image_frame#}</default>
169+
</string>
170+
<string>
171+
<name>style</name>
172+
<longflag>style</longflag>
173+
<label>Style Options</label>
174+
<description>Image style options for compositing a multi-frame image</description>
175+
<default>{#control:#current_image_style#}</default>
176+
</string>
177+
</parameters>
160178
<parameters advanced="true">
161179
<label>Dask</label>
162180
<description>Dask parameters</description>

0 commit comments

Comments
 (0)