[Bug] RandomEqualize() function seems wrong
See original GitHub issue🐛 Bug
When I use the kornia.augmentation.RandomEqualize() (or kornia.enhance.adjust.equalize()), I’m not seeing any change in the input. When I use a similar function in opencv, I see a different output. Am I missing something?
To Reproduce
Steps to reproduce the behavior:
>>> rng = torch.manual_seed(0)
>>> arr = 0.5*torch.rand(5,5) + 0.25
>>> print(arr)
tensor([[0.4981, 0.6341, 0.2942, 0.3160, 0.4037],
[0.5670, 0.4950, 0.6982, 0.4778, 0.5662],
[0.4244, 0.4509, 0.2612, 0.3344, 0.3969],
[0.5093, 0.5988, 0.6500, 0.3305, 0.3911],
[0.5908, 0.7076, 0.4485, 0.6871, 0.4597]])
>>> out = kornia.augmentation.RandomEqualize(p=1.)(arr)
>>> print(out)
tensor([[[[0.4981, 0.6341, 0.2942, 0.3160, 0.4037],
[0.5670, 0.4950, 0.6982, 0.4778, 0.5662],
[0.4244, 0.4509, 0.2612, 0.3344, 0.3969],
[0.5093, 0.5988, 0.6500, 0.3305, 0.3911],
[0.5908, 0.7076, 0.4485, 0.6871, 0.4597]]]])
Expected behavior
I am expecting the resulting matrix to be renormalized in the [0,1] range, since the function definition recommends my input to be in this range as described here: https://github.com/kornia/kornia/blob/master/kornia/augmentation/augmentation.py#L1119
Also, maybe this function should have a min and max equalization range?
>>> import cv2
>>> cv_arr = (arr.cpu().data.numpy())
>>> cv_arr = (cv_arr * 255.).astype(np.uint8)
>>> cv_out = cv2.equalizeHist(cv_arr)
>>> cv_out = (cv_out / 255.).astype(np.float32)
>>> print(torch.from_numpy(cv_out))
tensor([[0.5843, 0.8314, 0.0431, 0.0824, 0.2902],
[0.7098, 0.5412, 0.9569, 0.5020, 0.7098],
[0.3333, 0.4157, 0.0000, 0.1647, 0.2510],
[0.6235, 0.7922, 0.8745, 0.1255, 0.2078],
[0.7490, 1.0000, 0.4157, 0.9176, 0.4588]])
Environment
Collecting environment information… PyTorch version: 1.7.0 Is debug build: True CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A
OS: Mac OSX 10.15.7 (x86_64) GCC version: Could not collect Clang version: 12.0.0 (clang-1200.0.32.2) CMake version: Could not collect
Python version: 3.7 (64-bit runtime) Is CUDA available: False CUDA runtime version: No CUDA GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A
Versions of relevant libraries: [pip3] numpy==1.16.1 [pip3] torch==1.7.0 [pip3] torchvision==0.8.1 [conda] Could not collect
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
@edgarriba I’ll have more time next week, in a release push this week.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions, and happy coding day 😎