-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
500 Fix deepedit orientation issue [skip mgpu] (#501)
Fixes #500 . ### Description This PR is used to fix the orientation issue of the spleen deepedit annotation bundle. This PR refers to Project-MONAI/MONAILabel#1537 ### Status **Ready** ### Please ensure all the checkboxes: <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Codeformat tests passed locally by running `./runtests.sh --codeformat`. - [ ] In-line docstrings updated. - [ ] Update `version` and `changelog` in `metadata.json` if changing an existing bundle. - [ ] Please ensure the naming rules in config files meet our requirements (please refer to: `CONTRIBUTING.md`). - [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy` are correct in `metadata.json`. - [ ] Descriptions should be consistent with the content, such as `eval_metrics` of the provided weights and TorchScript modules. - [ ] Files larger than 25MB are excluded and replaced by providing download links in `large_file.yml`. - [ ] Avoid using path that contains personal information within config files (such as use `/home/your_name/` for `"bundle_root"`). --------- Signed-off-by: Yiheng Wang <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1058d4b
commit d7ae2b4
Showing
7 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Dict | ||
|
||
import numpy as np | ||
from einops import rearrange | ||
from monai.transforms.transform import Transform | ||
|
||
|
||
class OrientationGuidanceMultipleLabelDeepEditd(Transform): | ||
def __init__(self, ref_image="image", label_names=None): | ||
""" | ||
Convert the guidance to the RAS orientation | ||
""" | ||
self.ref_image = ref_image | ||
self.label_names = label_names | ||
|
||
def transform_points(self, point, affine): | ||
"""transform point to the coordinates of the transformed image | ||
point: numpy array [bs, N, 3] | ||
""" | ||
bs, n = point.shape[:2] | ||
point = np.concatenate((point, np.ones((bs, n, 1))), axis=-1) | ||
point = rearrange(point, "b n d -> d (b n)") | ||
point = affine @ point | ||
point = rearrange(point, "d (b n)-> b n d", b=bs)[:, :, :3] | ||
return point | ||
|
||
def __call__(self, data): | ||
d: Dict = dict(data) | ||
for key_label in self.label_names.keys(): | ||
points = d.get(key_label, []) | ||
if len(points) < 1: | ||
continue | ||
reoriented_points = self.transform_points( | ||
np.array(points)[None], | ||
np.linalg.inv(d[self.ref_image].meta["affine"].numpy()) @ d[self.ref_image].meta["original_affine"], | ||
) | ||
d[key_label] = reoriented_points[0] | ||
return d |