bin_centers = np.arange(image_min, image_max + 1)
// Add zeros at the end of the hist array to get the correct size
zero_hist = np.zeros(image_max - image_min - hist.shape[0] + 1)
hist = np.concatenate((hist, zero_hist))
else:
ValueError("Wrong value for the `source_range` argument")
return hist, bin_centers
After Change
def _bincount_histogram(image, source_range):
Efficient histogram calculation for a flat image of integers.
if source_range not in ["image", "dtype"]:
raise ValueError("Incorrect value for `source_range` argument: {}".format(source_range))
if source_range == "image":
image_min = np.min(image).astype(np.int64)
image_max = np.max(image).astype(np.int64)
elif source_range == "dtype":
image_min, image_max = dtype_limits(image, clip_negative=False)
image, offset = _offset_array(image, image_min, image_max)
hist = np.bincount(image.ravel(), minlength=image_max - image_min + 1)
bin_centers = np.arange(image_min, image_max + 1)
if source_range == "image":
idx = max(image_min, 0)
hist = hist[idx:]
return hist, bin_centers
def histogram(image, nbins=256, source_range="image", normalize=False):