Skip to content

inf value not supported #74

Open
Open

Description

@CallShaul

Hi,

I'd like to ask / recommend to add support for inf values.
Currently, inf values are hiding the information in the image, and cannot be seen using the normalize function,
The image would appear completely black, even after using the normalization button.

Image

Activity

  1. srwi commented on Jul 31, 2025

    @srwi
    Owner

    Mh, I'm not sure about this. In the case of non-normalized displaying it behaves as expected:

    import numpy as np
    height, width = 16, 16
    img = np.random.rand(height, width).astype(np.float32)
    img[:height//2, :width//2] = np.inf
    pass  # Break here
    
    Image

    The value range for float types is expected to be between 0.0 and 1.0, so in your case all pixels should be white (above the maximum value of 1.0).

    In the case of normalizing the image, I think the correct way would be to show all inf values as white, while all other values get squished towards 0 (black).

    You said even without normalization the image gets displayed as black? Could you share a reproducible code sample?

  2. CallShaul commented on Jul 31, 2025

    @CallShaul
    Author

    Here when it fails to normalize:

    (values are NOT in the range of 0-1, without the inf's - normalization works well outside of the 0-1 range, but not with the inf's)

    height, width = 16, 16
    img = np.random.rand(height, width).astype(np.float32)
    img *= 100
    img[:height//2, :width//2] = np.inf
    
  3. srwi commented on Jul 31, 2025

    @srwi
    Owner

    Okay, what would be your desired behavior when normalizing arrays with inf values?

    In my opinion the correct behavior would be to display inf values as white and everything else as black. That would be consistent with the idea of rescaling all values into the value range (0.0, 1.0).

  4. CallShaul commented on Jul 31, 2025

    @CallShaul
    Author

    I think the correct behavior should be not to miss the other values (visually) even when inf's are in the image.

    So when using the normalization function - if the inf's are white, all the other values should be colored according to their gray level to allow them to be seen.

    Maybe something like this:

    height, width = 16, 16
    img = np.random.rand(height, width).astype(np.float32)
    img *= 100
    img[:height//2, :width//2] = np.max(img)
    
    Image
  5. srwi commented on Jul 31, 2025

    @srwi
    Owner

    I think that would make sense but the user might miss that there are infinite values in there like this. An alternative would be to make infinite values appear transparent. Maybe the best way would be to make this an option so the user can decide which behavior is best for them.

    Thank you for your feedback!

  6. added
    enhancement
    on Jul 31, 2025
  7. CallShaul commented on Jul 31, 2025

    @CallShaul
    Author

    Yes, any extra visualization technique for those inf's is even better.
    Another edge-case to consider is a binary image with inf's. (if those inf's are either black or white - we might miss them)

    Thanks for your wiling to keep making the amazing PixelLens even better !

    All the best.

  8. srwi commented on Jul 31, 2025

    @srwi
    Owner

    Another edge-case to consider is a binary image with inf's. (if those inf's are either black or white - we might miss them)

    You're right. In that case maybe transparency would be the more suitable default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions