Skip to content

inverse adjust contrast#2217

Merged
rijobro merged 2 commits intoProject-MONAI:devfrom
rijobro:inverse_adjust_contrast
May 20, 2021
Merged

inverse adjust contrast#2217
rijobro merged 2 commits intoProject-MONAI:devfrom
rijobro:inverse_adjust_contrast

Conversation

@rijobro
Copy link
Copy Markdown
Contributor

@rijobro rijobro commented May 19, 2021

Starts to address #2213.

Description

Add inverse for AdjustContrastd and RandAdjustContrastd.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: Richard Brown <[email protected]>
@rijobro rijobro requested review from Nic-Ma and wyli and removed request for wyli May 20, 2021 09:33
Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

thanks! there might be an implicit int->float casting in the forward, not sure whether we should consider that in the inverse, perhaps could refactor that later

@rijobro rijobro enabled auto-merge (squash) May 20, 2021 15:37
@rijobro rijobro merged commit 4c6af53 into Project-MONAI:dev May 20, 2021
@rijobro rijobro deleted the inverse_adjust_contrast branch May 24, 2021 13:04
@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 24, 2021

Hi @rijobro ,

I have a concern about this PR:
If we use AdjustContrastd in the transform chain for image during inference, and want to invert pred based on the transform_info of image. How to avoid inverting this transform but invert other spatial transforms?

Thanks in advance.

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented May 24, 2021

The applied transforms are stored in a list, so we could simply manipulate the list as we need. Untested example might be like this:

def remove_transforms(transforms: list, to_be_removed: list):
    return [t for t in transforms if t["class"] not in to_be_removed]

transforms = remove_transforms(data["image_transforms"], ["AdjustContrastd"])

We could potentially formalise this using a withable or putting it in the Inverter logic:

ts = data["image_transforms"]
with InvertibleTransform.skipInverses(ts, ["AdjustContrastd"]):
    ts.inverse(data)

@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 24, 2021

Hi @rijobro ,

Thanks for your proposal, but is there any use case to avoid only 1 of same transforms?
For example:

Resized(keys="img", spatial_size=[128, 128, 128]),
RandSpatialCrop(keys="img", random_size=True),
Resized(keys="img", spatial_size=[64, 64, 64]),

And only skip the first Resized.
So in summary, I am not sure we should skip transforms by class name or instance unique ID.
@wyli @ericspod , what do you think? Or any other ideas?
We also need to think about how to enhance the Invertd transform for this feature request.

Thanks.

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented May 24, 2021

I think there could be lots of different reasons for wanting to do the inverse of some, but not all of the applied transforms, so there won't be any "one size fits all" solution.

I don't think we often use multiple instances of the same transform, but If the user wanted to skip the first Resized, then they could just do it via indexing: d["image_transforms] = d["image_transforms][1:]. Random transforms are appended even if do_transform was false (below threshold probability), meaning the length of invertible transforms will remain constant and indexing can be safely used.

@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 24, 2021

Hi @rijobro ,

Could you please help create a PR to enhance the Invertd transform for this issue?
Inverting is heavily used in our internal projects now, once users use AdjustContrastd transform, it will cause issue..

Thanks in advance.

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented May 24, 2021

Glad to hear that the inverse functionality is being used! Sure, I'll create a draft PR and we can discuss if the solution is acceptable there.

@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 25, 2021

Cool, sounds good!
Thanks.

@wyli
Copy link
Copy Markdown
Contributor

wyli commented May 25, 2021

perhaps could have a SpatialTransform interface? because in many cases we want to invert the spatial ones only.

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented May 26, 2021

Similar to my suggestion here: #2213 (comment).

I wonder if we're getting a little too complicated -- what about transforms that are a mix of spatial and intensity, what about invertible transforms that are neither spatial or intensity (we don't have any yet, but may in the future).

Would it be worth scheduling a meeting for our transforms? We may want to unify certain things to make them more future-proof.

@wyli
Copy link
Copy Markdown
Contributor

wyli commented May 26, 2021

sure @rijobro let's have a Teams chat soon...

@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 26, 2021

Hi @rijobro and @ericspod , sure, we certainly need to have an online discussion about how to make the inverting progress more flexible.

Thanks.

@wyli wyli mentioned this pull request May 26, 2021
6 tasks
wyli added a commit to wyli/MONAI that referenced this pull request May 26, 2021
wyli added a commit that referenced this pull request May 26, 2021
This reverts commit 4c6af53.

Signed-off-by: Wenqi Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants