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

[feature] Add RescaleIntensity & ZNormalization & ClampIntensity transforms #2241

Open
wants to merge 2 commits into
base: dev-1.x
Choose a base branch
from

Conversation

kellyiss
Copy link

Motivation

Support rescale intensity, znormalization and clamp intensity for medical data.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.


def transform(self, results: dict) -> dict:
img = results['img']
img = self.clamp(img)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
img = self.clamp(img)
img = np.clip(img, self.t_min, self.t_max)

Comment on lines 1411 to 1412
def clamp(self, img):
return np.clip(img, self.t_min, self.t_max)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can delete L1411-1412 since np.clip() could be directly used in def transform()?

self.channel_wise = channel_wise

def _normalize(self, img: np.ndarray, mean=None, std=None):
slices = np.ones_like(img, dtype=bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does slices = np.ones_like(img, dtype=bool) for?

Copy link
Author

Choose a reason for hiding this comment

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

I find that the "slices" is designed for the case that we only want to normalize the non-zero intensity of the image in MONAI. But I haven't added this function. In this version, the "slices" is not necessary. I will remove it. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I find that the "slices" is designed for the case that we only want to normalize the non-zero intensity of the image in MONAI. But I haven't added this function. In this version, the "slices" is not necessary. I will remove it. Thanks!

OK, got it! Thanks. Shall we add this normalize the non-zero intensity of the image function in the future? Do you think this function is important in medical image segmentation?

Copy link
Author

Choose a reason for hiding this comment

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

From my experiences so far, the difference of using it is slight most of the time but it's meaningful.
Adding it would be a better idea. Thanks!

mean (float, optional): the mean to subtract by
Defaults to None.
std (float, optional): the standard deviation to divide by
Defaults to None.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add docstring about channel_wise .

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Base: 83.55% // Head: 83.45% // Decreases project coverage by -0.09% ⚠️

Coverage data is based on head (f9c2b65) compared to base (a6a5a50).
Patch coverage: 73.40% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x    #2241      +/-   ##
===========================================
- Coverage    83.55%   83.45%   -0.10%     
===========================================
  Files          140      141       +1     
  Lines         7958     8062     +104     
  Branches      1191     1208      +17     
===========================================
+ Hits          6649     6728      +79     
- Misses        1119     1139      +20     
- Partials       190      195       +5     
Flag Coverage Δ
unittests 83.45% <73.40%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/datasets/transforms/transforms.py 92.59% <73.11%> (-4.32%) ⬇️
mmseg/datasets/transforms/__init__.py 100.00% <100.00%> (ø)
mmseg/utils/class_names.py 85.93% <0.00%> (-2.40%) ⬇️
mmseg/apis/inference.py 0.00% <0.00%> (ø)
mmseg/datasets/__init__.py 100.00% <0.00%> (ø)
mmseg/datasets/lip.py 100.00% <0.00%> (ø)
mmseg/models/backbones/timm_backbone.py 45.83% <0.00%> (+8.33%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@MengzhangLI
Copy link
Contributor

Hi, @kellyiss thanks for your nice PR.

Please fix the unit test problem. We would review it ASAP.

@MeowZheng MeowZheng added the 1.x Related issue of 1.x version label Nov 1, 2022
@MeowZheng MeowZheng deleted the branch open-mmlab:dev-1.x November 2, 2022 10:34
@MeowZheng MeowZheng closed this Nov 2, 2022
@MeowZheng MeowZheng reopened this Nov 2, 2022
@MeowZheng MeowZheng force-pushed the dev-1.x branch 3 times, most recently from 4c28e1e to 115552d Compare December 30, 2022 14:56
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
Needed to convert `timesteps` to `float32` a bit sooner.

Fixes open-mmlab#1537
@OpenMMLab-Assistant005
Copy link

Hi @kellyiss !We are grateful for your efforts in helping improve this open-source project during your personal time.
Welcome to join OpenMMLab Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/UjgXkPWNqA
If you have a WeChat account,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:)
Thank you again for your contribution❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Related issue of 1.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants