This repository was archived by the owner on Jul 10, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add stain augment #2337
Merged
Merged
Add stain augment #2337
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's Guide by SourceryThis PR introduces a new stain augmentation feature for histopathology images. The changes involve adding functions and classes for extracting and normalizing H&E stains using various methods (Vahadane, Macenko, presets), integrating a new HEStain transform into the augmentation pipeline, and expanding the test suite to validate the new functionality. Updated class diagram for H&E Stain AugmentationclassDiagram
class StainNormalizer {
+stain_matrix_target
+fit(img: np.ndarray)
}
class VahadaneNormalizer {
+fit(img: np.ndarray)
}
class MacenkoNormalizer {
-angular_percentile: float
+fit(img: np.ndarray, angular_percentile: float = 99)
}
StainNormalizer <|-- VahadaneNormalizer
StainNormalizer <|-- MacenkoNormalizer
class SimpleNMF {
-n_iter: int
-initial_colors: np.array
+fit_transform(optical_density: np.ndarray) : tuple[np.ndarray, np.ndarray]
}
class HEStain {
-method: Literal["preset", "random_preset", "vahadane", "macenko"]
-preset: Literal["ruifrok", "macenko", "standard", "high_contrast", "h_heavy", "e_heavy", "dark", "light"]
-intensity_scale_range: tuple[float, float]
-intensity_shift_range: tuple[float, float]
-augment_background: bool
-stain_normalizer
-preset_names: list
+get_stain_matrix(img: np.ndarray) : np.ndarray
+apply(img: np.ndarray, stain_matrix: np.ndarray, scale_factors: np.ndarray, shift_values: np.ndarray) : np.ndarray
+get_params_dependent_on_data(params: dict, data: dict) : dict
+get_transform_init_args() : dict
}
class InitSchema {
-method
-preset
-intensity_scale_range: tuple[float, float]
-intensity_shift_range: tuple[float, float]
-augment_background: bool
+validate_matrix_selection() : Self
}
HEStain "1" *-- "1" InitSchema : uses
%% Depending on the method, HEStain composes a stain extractor
HEStain o-- VahadaneNormalizer : "stain_extractor (if method=='vahadane')"
HEStain o-- MacenkoNormalizer : "stain_extractor (if method=='macenko')"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ternaus - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a usage example to the documentation for the new transform.
- The SimpleNMF class could benefit from more detailed comments explaining the iterative update steps.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Add an H&E stain augmentation to simulate different staining conditions in histopathology images. The augmentation supports predefined stain matrices, Vahadane and Macenko stain extraction methods, and custom matrices. Control the intensity variations with
intensity_scale_range
andintensity_shift_range
, and choose whether to augment background regions withaugment_background
.New Features:
Tests: