def scaling(image, method="stretching"):
"""
Change the image dynamic.
Parameters
----------
image: Image
the image to be transformed.
method: str, default 'stretching'
the normalization method: 'stretching', 'equalization' or 'adaptive'.
Returns
-------
normalize_image: Image
the normalized image.
"""
# Contrast stretching
if method == "stretching":
p2, p98 = np.percentile(image.data, (2, 98))
norm_data = exposure.rescale_intensity(image.data, in_range=(p2, p98))
# Equalization
elif method == "equalization":
norm_data = exposure.equalize_hist(image.data)
# Adaptive Equalization
elif method == "adaptive":
norm_data = exposure.equalize_adapthist(image.data, clip_limit=0.03)
# Unknown method
else:
raise ValueError("Unknown normalization '{0}'.".format(method))
normalize_image = pisap.Image(data=norm_data)
return normalize_image
评论列表
文章目录