Skip to content

Conversation

@mostafajahanifar
Copy link
Collaborator

@mostafajahanifar mostafajahanifar commented Oct 28, 2021

Introducing stainaugment tool for generating stain-augmented images from an input image. This class can be used stand-alone or in albumentations augmentation pipelines.

The process works as bellow:

  1. H and E parts of the input images are first extracted, using a predefined stain_matrix or a stain_matrix that has been calculated based on 'Vahadane' or 'Macenko' methods.
  2. Input image's stain concentrations are calculated based on the provided/extracted stain_matrix.
  3. Stain concentrations are adjusted randomly based on two input sigma1 and sigma2 parameters:
    • Scaled by alpha = np.random.uniform(1 - self.sigma1, 1 + self.sigma1)
    • Biased by beta = np.random.uniform(-self.sigma2, self.sigma2)
  4. New image is formed based on the adjusted concentrations.

Providing the pre-extracted stain_matrix on class initialization have two benefits:

  • stainaugment can be used for small patches on-the-fly during the model training (because the bulk of stain matrix extraction or dictionary learning is eliminated)

  • By setting the parameters, this function allow the user to augment the stain around a target stain matrix i.e., normalize the stain to a target image and then augment it.

  • Class definition and structure

  • Check the functionality

  • Add support for albumentations

  • Complete the docstring and writing examples

  • Complete the test and coverage

  • Add an example to "Stain Normalization" notebook

@shaneahmed shaneahmed added the enhancement New feature or request label Oct 31, 2021
@codecov
Copy link

codecov bot commented Nov 3, 2021

Codecov Report

Merging #181 (83295a9) into develop (b045ba4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 83295a9 differs from pull request most recent head 26dcf3f. Consider uploading reports for the commit 26dcf3f to get more accurate results
Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #181   +/-   ##
========================================
  Coverage    99.79%   99.80%           
========================================
  Files           40       41    +1     
  Lines         2979     3057   +78     
  Branches       499      507    +8     
========================================
+ Hits          2973     3051   +78     
  Misses           1        1           
  Partials         5        5           
Impacted Files Coverage Δ
tiatoolbox/tools/__init__.py 100.00% <100.00%> (ø)
tiatoolbox/tools/stainaugment.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b045ba4...26dcf3f. Read the comment docs.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@shaneahmed shaneahmed requested a review from Srijay-lab November 5, 2021 11:59
Copy link
Contributor

@simongraham simongraham left a comment

Choose a reason for hiding this comment

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

Nice work. Few small things to change but generally it’s nice. Happy to merge when those things are addressed

@mostafajahanifar
Copy link
Collaborator Author

mostafajahanifar commented Nov 8, 2021

Many thanks to @simongraham and @Srijay-lab for reviewing this PR. I have incorporated your comments in ff0e65c. Please let us know if you are happy with the changes (and test the code on your system if possible) so @shaneahmed can merge this PR.

Copy link
Member

@shaneahmed shaneahmed left a comment

Choose a reason for hiding this comment

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

Thanks @mostafajahanifar
Please address my comments and add stain augmentation feature to usage.rst

Copy link
Member

@shaneahmed shaneahmed left a comment

Choose a reason for hiding this comment

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

@shaneahmed shaneahmed merged commit 87d0ecb into develop Nov 9, 2021
@shaneahmed shaneahmed deleted the feature-stainaugment branch November 9, 2021 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants