π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix issue of image_histogram2d (#1295)
Wingkou Loeng6c9bc52dbbda
diff --git a/kornia/enhance/histogram.py b/kornia/enhance/histogram.pyindex 1db97f1d7..cfafe3904 100644--- a/kornia/enhance/histogram.py+++ b/kornia/enhance/histogram.py@@ -237,7 +237,7 @@ def image_histogram2d(hist = torch.sum(kernel_values, dim=(-2, -1)).permute(1, 2, 0)if return_pdf:- normalization = torch.sum(hist, dim=-1).unsqueeze(0) + eps+ normalization = torch.sum(hist, dim=-1, keepdim=True) + epspdf = hist / normalizationif image.dim() == 2:hist = hist.squeeze()diff --git a/test/enhance/test_histogram.py b/test/enhance/test_histogram.pyindex c5e1a4bc0..dd3f67de8 100644--- a/test/enhance/test_histogram.py+++ b/test/enhance/test_histogram.py@@ -54,9 +54,11 @@ class TestImageHistogram2d:assert_close(op(*inputs), op_script(*inputs))@pytest.mark.parametrize("kernel", ["triangular", "gaussian", "uniform", "epanechnikov"])- def test_uniform_hist(self, device, dtype, kernel):+ @pytest.mark.parametrize("size", [(1, 1), (3, 1, 1), (8, 3, 1, 1)])+ def test_uniform_hist(self, device, dtype, kernel, size):input = torch.linspace(0, 255, 10, device=device, dtype=dtype)input_x, _ = torch.meshgrid(input, input)+ input_x = input_x.repeat(*size)if kernel == "gaussian":bandwidth = 2 * 0.4 ** 2else:@@ -66,9 +68,11 @@ class TestImageHistogram2d:assert_close(ans, hist)@pytest.mark.parametrize("kernel", ["triangular", "gaussian", "uniform", "epanechnikov"])- def test_uniform_dist(self, device, dtype, kernel):+ @pytest.mark.parametrize("size", [(1, 1), (3, 1, 1), (8, 3, 1, 1)])+ def test_uniform_dist(self, device, dtype, kernel, size):input = torch.linspace(0, 255, 10, device=device, dtype=dtype)input_x, _ = torch.meshgrid(input, input)+ input_x = input_x.repeat(*size)if kernel == "gaussian":bandwidth = 2 * 0.4 ** 2else: