clEsperanto / pyclesperanto_prototype

GPU-accelerated bio-image analysis focusing on 3D+t microscopy image data
http://clesperanto.net
BSD 3-Clause "New" or "Revised" License
208 stars 44 forks source link

CLAHE #306

Open haesleinhuepf opened 1 year ago

haesleinhuepf commented 1 year ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

Ok nice thanks! Excited to see it work in pyclesperanto.

On June 16, 2024 7:25:18 PM GMT+02:00, Robert Haase @.***> wrote:

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

-- Reply to this email directly or view it on GitHub: https://github.com/clEsperanto/pyclesperanto_prototype/issues/306#issuecomment-2171778068 You are receiving this because you were mentioned.

Message ID: @.***> Hugo Raveton

StRigaud commented 1 month ago

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 :wink: . 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 :rocket: !

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