Skip to content

Commit

Permalink
Merge pull request #989 from DigitalSlideArchive/ppc-frame-style
Browse files Browse the repository at this point in the history
Support handling frame and style parameters
  • Loading branch information
manthey authored May 2, 2023
2 parents 6b4b60a + df86a92 commit ea852b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
23 changes: 17 additions & 6 deletions histomicstk/cli/PositivePixelCount/PositivePixelCount.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@


def tile_positive_pixel_count(imagePath, tilePosition, it_kwargs, ppc_params,
color_map, useAlpha, region_polygons):
color_map, useAlpha, region_polygons, style):
tile_start_time = time.time()
ts = large_image.getTileSource(imagePath)
ts = large_image.getTileSource(imagePath, style=style)
tile = ts.getSingleTile(tile_position=tilePosition, **it_kwargs)
mask = utils.polygons_to_binary_mask(
region_polygons, tile['x'], tile['y'], tile['width'], tile['height'])
result, ppcmask = ppc.count_image(tile['tile'], ppc_params, mask)
img = tile['tile']
if len(img.shape) == 2:
img = img.reshape((img.shape[0], img.shape[1], 1))
if len(img.shape) == 3 and img.shape[-1] == 1:
img = np.repeat(img, 3, axis=2)
result, ppcmask = ppc.count_image(img, ppc_params, mask)
tile.release()
ppcimg = color_map[ppcmask]
if not useAlpha:
Expand All @@ -27,7 +32,9 @@ def tile_positive_pixel_count(imagePath, tilePosition, it_kwargs, ppc_params,

def main(opts):
pprint.pprint(vars(opts))
ts = large_image.getTileSource(opts.inputImageFile)
if not opts.style or opts.style.startswith('{#control'):
opts.style = None
ts = large_image.getTileSource(opts.inputImageFile, style=opts.style)
sink = large_image.new() if getattr(opts, 'outputLabelImage', None) else None
tiparams = utils.get_region_dict(opts.region, None, ts)
region_polygons = utils.get_region_polygons(opts.region)
Expand All @@ -50,6 +57,10 @@ def main(opts):
tiparams['region']['width'], tiparams['region']['height'])
tiparams['format'] = large_image.constants.TILE_FORMAT_NUMPY
tiparams['tile_size'] = dict(width=tileSize, height=tileSize)
try:
tiparams['frame'] = int(opts.frame)
except Exception:
pass
tileCount = next(ts.tileIterator(**tiparams))['iterator_range']['position']
start_time = time.time()
if tileCount > 4 and getattr(opts, 'scheduler', None) != 'none':
Expand All @@ -64,7 +75,7 @@ def main(opts):
futureList.append(client.submit(
tile_positive_pixel_count,
opts.inputImageFile, tile_position, tiparams, ppc_params,
color_map, useAlpha, region_polygons))
color_map, useAlpha, region_polygons, opts.style))
for idx, future in enumerate(futureList):
result, ppcimg, x, y, mask, tile_start_time = future.result()
results.append(result)
Expand All @@ -79,7 +90,7 @@ def main(opts):
tile_position = tile['tile_position']['position']
result, ppcimg, x, y, mask, tile_start_time = tile_positive_pixel_count(
opts.inputImageFile, tile_position, tiparams, ppc_params,
color_map, useAlpha, region_polygons)
color_map, useAlpha, region_polygons, opts.style)
results.append(result)
if sink:
sink.addTile(ppcimg, x, y, mask=mask)
Expand Down
20 changes: 19 additions & 1 deletion histomicstk/cli/PositivePixelCount/PositivePixelCount.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<name>region</name>
<label>Analysis ROI</label>
<longflag>region</longflag>
<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>
<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>
<default>-1,-1,-1,-1</default>
</region>
<float>
Expand Down Expand Up @@ -157,6 +157,24 @@
<description>Average intensity of positive pixels excluding strong positive pixels</description>
</float>
</parameters>
<parameters advanced="true">
<label>Frame and Style</label>
<description>Frame parameters</description>
<string>
<name>frame</name>
<longflag>frame</longflag>
<label>Frame Index</label>
<description>Frame index in a multi-frame image</description>
<default>{#control:#current_image_frame#}</default>
</string>
<string>
<name>style</name>
<longflag>style</longflag>
<label>Style Options</label>
<description>Image style options for compositing a multi-frame image</description>
<default>{#control:#current_image_style#}</default>
</string>
</parameters>
<parameters advanced="true">
<label>Dask</label>
<description>Dask parameters</description>
Expand Down

0 comments on commit ea852b3

Please sign in to comment.