-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add stain augment #2337
Add stain augment #2337
Conversation
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.
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: