-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] Image Histogram Transformation #598
Comments
Thanks for the issue! I think we could provide a histogram transformation functionality in torchvision. Also, apart from Also, could you send a PR? |
Thank you @fmassa for your reply. The function above was written outside the context of PyTorch. That's why it's all NumPy. If you are going to integrate my code, I need some time (~ 1 month) to write it properly. As you said, I will use
My biggest worry is applying a histogram transform on floats. I need to see how other people do this (if you know any references, please send it my way). Otherwise, the way I would do it is to divide the input image/tensor to By putting more effort into it, we could provide template histograms eliminating the need for gamma correction, contrast adjustments, and mean and standard deviation shifting. Do you think I should send the pull request before addressing the big issues above or after (I'm still new to the GitHub community)? |
About points 1-2: If we pass the bins of the histogram as well, we don't need to worry if the image is floating point or not, so we would pass not only the counts but also what value each count accounts for. I think this would solve your comments, right? I don't have any experience with RAW or FITS images, but please feel free to send a PR with what we have discussed. Also, raising any issues you might see with it is definitely valuable! |
I like that! Then I'll start writing the function |
Hello @fmassa again. So I finished polishing and testing the code as we discussed. It is very inconvenient to switch back and forth between torch.tensor and numpy.ndarray, so I decided to do everything in numpy. |
As I have discussed in a feature request (link1), HistogramTransformation is very useful, especially when handling raw data in photography or astronomy. Please see the following gits (link2) for its functionality, examples, and proof of concept. link1: pytorch#598 link2: https://gist.github.com/Miladiouss/86bed5c53595116dfe18ee0a5c84f838
Hey 😃 I was browsing throught the vison issues and found that one, turns out I actually did some work on histogram specification some time ago. I wrote it as a cuda module as I was running the transform in an optimisation loop and needed it to be fast. The code is available over here if that can be useful : https://github.com/pierre-wilmot/NeuralTextureSynthesis/ |
@gheaeckkseqrz Thanks for the proposal! I think it could be a nice addition to have efficient GPU-accelerated transforms, but first we need to have a reference implementation and I have to find the time to review the PR in #796 |
@gheaeckkseqrz's proposal would also really help with style transfer and potentially GAN related tasks as well. Support for histogram matching on GPU with tensors can be extremely useful for style transfer. ProGamerGov/neural-style-pt#46 (comment) |
@Miladiouss So, I created this function that essentially matches the histogram of one image to another image, and it should hopefully help individuals with use cases like astronomy & neural style transfer. I wrote the code for a different PyTorch project (pytorch/captum), but Torchvision is free to use it as well! @fmassa
The inner functions can be eliminated easily for TorchScript / JIT compatibility, and it's fully autograd compatible. |
@ProGamerGov did this ever get implemented into any library? |
It is often useful (especially in the field of astronomy) to transform the histogram of images. I would like to suggest an image histogram transformation function (under torchvision.transforms) that transforms the histogram of an image to match that of a template image as closely as possible. For instance, consider the following function:
The function above is not optimal since it has to recalculate template image information. It is not discretized for float type images. It only performs for highly discretized images such as png (0-255 bins). It also performs poorly when the number of diverse pixels is too low which might be fixed by adding small noise.
The text was updated successfully, but these errors were encountered: