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

55 Initialize UI Elements correctly for multichannel TIFF images #72

Merged
merged 6 commits into from
Aug 9, 2024

Conversation

ShalinGhe
Copy link
Collaborator

Description

This pull request solves issue #55 and introduces enhancements to handle multi-channel TIFF images in Cellpose. The main improvements include initializing UI components such as color buttons, sliders, and on/off buttons based on the number of layers in the loaded TIFF image. This way, the user will have a well-configured interface for analyzing multi-layer TIFF images. Additionally, the UI now correctly hides these components when a non-TIFF image is loaded or the number of layers in an image is smaller than 3.

Changes Made

1. io.py

  • Function _load_image:
    • Added support for checking multi-layer TIFF images
    • Implemented logic to detect the number of layers in the loaded multichannel TIFF image
    • Called parent.generate_multi_channel_ui(num_layers, is_tiff) to set up UI components for the multi-channel image

2. gui.py

  • Function generate_multi_channel_ui(self, num_layers, is_tiff):
    • Clears existing UI elements from the layout
    • Initializes and sets up sliders, color buttons, and on/off buttons based on the number of layers in the TIFF image
    • Shows or hides UI components based on whether a multi-channel TIFF image is loaded and has more than 3 layers
    • Restored the original red, green, and blue names when no multichannel TIFF image is loaded
  • Function rgb_to_hex(self, rgb_tuple):
    • Converts RGB tuples to hexadecimal color strings for UI components

Initial Color Values:

  • Red: (255, 0, 0)
  • Green: (0, 255, 0)
  • Blue: (0, 0, 255)
  • Yellow: (255, 255, 0)
  • Magenta: (255, 0, 255)
  • Cyan: (0, 255, 255)
  • Orange: (255, 165, 0)
  • The color stack is dynamically initialized by the color_initialization method and is correctly applied within generate_multi_channel_ui. This method ensures that the colors are assigned to the colors_stack in a cyclic manner based on the number of layers in the loaded TIFF image

Functionality

  • UI Initialization:

    • For multi-layer TIFF images, N on/off buttons, N color dialog buttons, N sliders, and N marker names are visible (N is the number of layers)
    • The on/off buttons, color buttons, and marker names only appear when a multi-layer TIFF image is loaded. They should be hidden for non-TIFF images and TIFF images with N < 4
    • The colors are dynamically assigned from a predefined stack based on the number of layers in the image
  • Visibility:

    • When a multi-layer TIFF image is loaded, all corresponding UI elements are displayed
    • When no multi-layer TIFF image is loaded, these UI elements are hidden
  • Additional:

    • When no multi-layer TIFF is loaded, the marker names are set to "Grey/Red", "Green", and "Blue" as before

Implementation Details

  • Handling TIFF Images:
    • Utilized the PIL library to support TIFF image loading and processing
    • Differentiate between TIFF and non-TIFF files and adjust UI components accordingly

Testing

  • Manual Testing:
    • Verified that loading a multi-layer TIFF image correctly displays the color buttons, sliders, and on/off buttons.
Screenshot 2024-08-09 at 10 51 13 Screenshot 2024-08-09 at 10 50 51
  • Confirmed that these UI components are hidden and marker change their name when a non-TIFF image is loaded
Screenshot 2024-08-09 at 10 49 44
  • Edge Cases:
    • Tested with different numbers of layers to ensure UI components adjust correctly
Screenshot 2024-08-09 at 11 57 21 Screenshot 2024-08-09 at 10 56 46
  • Tested if color buttons cycle through color stack in TIFF images with N > len(colors)
    Screenshot 2024-08-09 at 10 55 09

@ShalinGhe ShalinGhe self-assigned this Aug 9, 2024
@ShalinGhe ShalinGhe linked an issue Aug 9, 2024 that may be closed by this pull request
8 tasks
Copy link

@robertkrasniqi robertkrasniqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review: Multi-Channel TIFF Image Support in Cellpose

Summary

This pull request addresses issue #55 by enhancing the Cellpose UI to better handle multi-channel TIFF images. The modifications include dynamic UI initialization based on the number of layers in the loaded TIFF image and ensuring that UI components are hidden when non-TIFF images or TIFF images with fewer than three layers are loaded. These improvements result in a more user-friendly interface, particularly when dealing with complex, multi-layer TIFF files.

Changes Implemented

  • Function rgb_to_hex(self, rgb_tuple):
    • Color Conversion: This function was refactored and extracted from its previous location because the program would not run without it (in commit e7a0614). By pulling it out, the program now runs without issues. This function converts RGB tuples into hexadecimal strings, which are then used to set color values for the UI components.

Functionality Testing

  • UI Initialization:

    • When a multi-layer TIFF image is loaded, N on/off buttons, N color buttons, N sliders, and N marker names appear in the UI, where N is the number of layers in the TIFF image. The components are hidden when a non-TIFF image or a TIFF with fewer than three layers is loaded.
  • Edge Case Testing:

    • Tested with images containing various numbers of layers to confirm that the UI components correctly adjust to the number of layers. Additionally, verified that the color buttons cycle through the predefined color stack when N > len(colors).
  • Manual Testing:

    • The changes were manually tested by loading multi-layer TIFF images to confirm that the UI components such as color buttons, sliders, and on/off buttons are displayed correctly. Furthermore, confirmed that the components are hidden and marker names change appropriately when non-TIFF images are loaded.

Overall, the pull request has successfully introduced the required functionality to handle multi-channel TIFF images, and the program now runs smoothly with the refactored rgb_to_hex method.

Good Job, looks very good!

Copy link
Collaborator

@Davidundso Davidundso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the changes:

  • Cellpose works correctly when no tiff is loaded
  • menu initializes with the correct number of sliders, buttons
  • buttons have the right initial color
  • The code is well commented and understandable

@robertkrasniqi robertkrasniqi merged commit 5c653e9 into main Aug 9, 2024
1 of 2 checks passed
@robertkrasniqi robertkrasniqi deleted the 55_multichannel_initialization branch August 9, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multi-channel initialization
4 participants