Skip to content
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

CLAHE #306

Open
haesleinhuepf opened this issue May 2, 2023 · 7 comments
Open

CLAHE #306

haesleinhuepf opened this issue May 2, 2023 · 7 comments

Comments

@haesleinhuepf
Copy link
Member

haesleinhuepf commented May 2, 2023

It would be great if we could get an OpenCL-Version of the CLAHE algorithm
https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE

Therefore, we might need to do a local histogram for every pixel. The entropy kernel does that too:
https://github.com/clEsperanto/clij-opencl-kernels/blob/master/kernels/entropy_3d_x.cl

This Metal kernel might be translatable to OpenCL (license: MIT):
https://github.com/MetalPetal/MetalPetal/blob/master/Frameworks/MetalPetal/Shaders/CLAHE.metal

See also:

@HugoRaveton
Copy link

Hi @haesleinhuepf , I have made a pyopencl kernel for 3D clahe: https://github.com/HugoRaveton/pyopencl_clahe, it only works for 8-bit 3D stacks for now.

@haesleinhuepf
Copy link
Member Author

Hi @HugoRaveton ,

oh fantastic! If you're interested, we can make it part of pyclesperanto! Either you send a pull-request like this one or you add an open source license to your code (BSD, MIT, Apache or similar) formally allowing otgers to copy and reuse your code. As you wish! After some testing and modifications, we would also incorporate your code into the next incarnation of pyclesperanto, which requires writing some C++ code here. That's not necessarily a task you. I'm just saying @StRigaud and me are highly interested in getting smart algorithms such as CLAHE into our code base. Thus, big thanks for reaching out! Let us know how to proceed.

@StRigaud
Copy link
Member

Hi @HugoRaveton, that looks really great!

You can test your pure OpenCL kernel with the new pyclesperanto using the cle.native_execute() function. You can have a look at the very basic test code here. And I will soon make some demos notebook for people to test their OpenCL kernel.

Like @haesleinhuepf said, we can integrate it to the library or, if you prefere, we can guide and help you to do it 😄 .

it only works for 8-bit 3D stacks for now

The prototype repo is no more in development, just maintenance for legacy. The new pyclesperanto now is fully 3D (2D is just 3D with depth == 1). From a quick look at your code, It should run fine for 3D and 2D, with little to no change. The 8-bit is a bit more constraining but I think it will be complex to make it otherwise. So It's awesome already!

@HugoRaveton
Copy link

Hi @StRigaud and @haesleinhuepf, I have added an MIT open license to the repo so you are free to integrate it into pyclesperanto. I will try to get it to work with any bit depth soon. I would also be interested in contributing directly to the library, let me know if I can help!
Cheers

@haesleinhuepf
Copy link
Member Author

I will try to get it to work with any bit depth soon.

No need for that, we will do this when integrating it in pyclesperanto. It's a no-brainer within our infrastructure. We'll show you.

Big thanks!

Best,
Robert

@HugoRaveton
Copy link

HugoRaveton commented Jun 17, 2024 via email

@StRigaud
Copy link
Member

StRigaud commented Jul 24, 2024

Hi @HugoRaveton

FYI i made a fork of your repo and i updated your kernel using clesperanto opencl keywords. I let you have a look, if you wanna do more kernel 😉 . Very minimal work here, simply replacing how we read/write in the images and update the input parameters not needed (width, height, depth. etc.).

This enable the kernel to be directly called in pyclesperanto which I demonstrate this notebook.

Seems to work like a charm 🚀 !

I still need to see how to manage the bit depth but otherwise, it can be integrated easily in clesperanto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants