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

Implement np.percentile to normalize images #332

Open
haesleinhuepf opened this issue Aug 20, 2024 · 2 comments
Open

Implement np.percentile to normalize images #332

haesleinhuepf opened this issue Aug 20, 2024 · 2 comments
Labels
request New feature or request

Comments

@haesleinhuepf
Copy link
Member

I recently hit a project where it would have been beneficial to do this on the GPU:

def normalize_image(image, lower_percentile, upper_percentile):
    """Make sure that image intensities lie between 0 and 1."""
    lower_bound = np.percentile(image, lower_percentile)
    upper_bound = np.percentile(image, upper_percentile)
    image_clipped = np.clip(image, lower_bound, upper_bound)
    normalized_image = (image_clipped - lower_bound) / (upper_bound - lower_bound)
    return normalized_image

For np.percentile, we could reuse our historam function. We might have to do a histogram with 10k or 100k bins and I'm not sure how efficient / doable this is.

np.clip is trivial to implement using minimum_image_and_scalar and maximum_image_and_scalar.

@StRigaud
Copy link
Member

Hey @haesleinhuepf,

These function seems indeed fit to be implemented, do you feel like doing them? I stay around for help if needed ofc 😃

@StRigaud StRigaud added the request New feature or request label Aug 21, 2024
@StRigaud
Copy link
Member

@haesleinhuepf I think we already have clip in Tier2 functions:

auto
clip_func(const Device::Pointer & device,
const Array::Pointer & src,
Array::Pointer dst,
float min_intensity,
float max_intensity) -> Array::Pointer
{
auto temp = tier1::maximum_image_and_scalar_func(device, src, nullptr, min_intensity);
return tier1::minimum_image_and_scalar_func(device, temp, dst, max_intensity);
}

and it is already available in the python bindings

@StRigaud StRigaud changed the title Implement np.clip and np.percentile to normalize images Implement np.percentile to normalize images Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants