[QUESTION] Image histogram example
Open
@stiepan is already working on this.
Since Jan 6, 2023.
question
- Dominant language
- C++
- Stars
- 5.8k
- Forks
- 678
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 27
Description
Hi, thank you very much for you work, DALI is really a great library. DALI accelerated my model training by almost 19 times compared to another augmentation library and it's really impressive. Although I'm still missing a few things. For example, i want to use custom augmentation and i need to calculate image histogram in the following way (I need it for Otsu thresholding):
import cv2
import numpy as np
IMAGE_PATH = "image.jpeg"
if __name__ == "__main__":
image = cv2.imread(IMAGE_PATH)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
...
# Find normalized_histogram, and its cumulative distribution function
hist = cv2.calcHist([image], [0], None, [256], [0, 256])
hist_norm = hist.ravel() / hist.sum()
Q = hist_norm.cumsum()
Could you please guide me? I've tried something like this:
def dali_calc_hist(decoded_images: DALITensorList, image_sizes: DALITensorList):
gray = fn.color_space_conversion(
decoded_images,
image_type=dali_types.RGB,
output_type=dali_types.GRAY,
)
hist = [0] * 256
cumsum = [0] * 256
n = image_size[0] * image_size[1]
_sum = fn.constant(idata=[0], dtype=dali_types.FLOAT)
for gray_lvl in range(256):
hist[gray_lvl] = fn.reductions.sum(
fn.cast(gray == gray_lvl, dtype=dali_types.UINT8)
) / n
_sum = _sum + hist[gray_lvl]
cumsum[gray_lvl] = _sum
return hist, cumsum
but i really feel that i'm doing something wrong, because actually in hist and cumsum i have nested DataNodes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.