Skip to content

Commit

Permalink
Merge pull request #46 from blowekamp/improve_build_histogram_var
Browse files Browse the repository at this point in the history
Clarify variable names in function which are used for scaling.
  • Loading branch information
blowekamp committed Mar 8, 2023
2 parents afc1f0d + 4207969 commit 9377690
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pytools/ng/build_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def histogram_stats(hist, bin_edges):
@click.argument("input_image", type=click.Path(exists=True, dir_okay=False, resolve_path=True))
@click.option(
"--mad",
"mad_scale",
type=float,
cls=MutuallyExclusiveOption,
mutually_exclusive=["sigma", "percentile-crop"],
Expand All @@ -196,6 +197,7 @@ def histogram_stats(hist, bin_edges):
)
@click.option(
"--sigma",
"sigma_scale",
type=float,
cls=MutuallyExclusiveOption,
mutually_exclusive=["mad", "percentile-crop"],
Expand All @@ -222,7 +224,7 @@ def histogram_stats(hist, bin_edges):
"elements of a double numeric value.",
)
@click.version_option(__version__)
def main(input_image, mad, sigma, percentile, clamp, output_json):
def main(input_image, mad_scale, sigma_scale, percentile, clamp, output_json):
"""
Reads the INPUT_IMAGE to compute an estimated minimum and maximum range to be used for visualization of the
data set. The image is required to have an integer pixel type.
Expand Down Expand Up @@ -254,14 +256,14 @@ def main(input_image, mad, sigma, percentile, clamp, output_json):
mids = 0.5 * (bins[1:] + bins[:-1])

logger.info("Computing statistics...")
if mad:
if mad_scale:
stats = histogram_robust_stats(h, bins)
logger.debug(f"stats: {stats}")
min_max = (stats["median"] - stats["mad"] * mad, stats["median"] + stats["mad"] * mad)
elif sigma:
min_max = (stats["median"] - stats["mad"] * mad_scale, stats["median"] + stats["mad"] * mad_scale)
elif sigma_scale:
stats = histogram_stats(h, bins)
logger.debug(f"stats: {stats}")
min_max = (stats["mean"] - stats["sigma"] * sigma, stats["mean"] + stats["sigma"] * sigma)
min_max = (stats["mean"] - stats["sigma"] * sigma_scale, stats["mean"] + stats["sigma"] * sigma_scale)
elif percentile:

lower_quantile = (0.5 * (100 - percentile)) / 100.0
Expand Down

0 comments on commit 9377690

Please sign in to comment.