Skip to content

Commit

Permalink
Change deprecated scipy.ndimage namespaces in optional imports (Proje…
Browse files Browse the repository at this point in the history
…ct-MONAI#7847)

Fixes Project-MONAI#7677 .

### Description

A few sentences describing the changes proposed in this pull request.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.

---------

Signed-off-by: alkamid <adam.klimont@cydar.co.uk>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
  • Loading branch information
alkamid and KumoLiu authored Jun 25, 2024
1 parent 08d5728 commit e801540
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion monai/apps/deepedit/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

logger = logging.getLogger(__name__)

distance_transform_cdt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_cdt")
distance_transform_cdt, _ = optional_import("scipy.ndimage", name="distance_transform_cdt")


class DiscardAddGuidanced(MapTransform):
Expand Down
2 changes: 1 addition & 1 deletion monai/apps/deepgrow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from monai.utils.enums import PostFix

measure, _ = optional_import("skimage.measure", "0.14.2", min_version)
distance_transform_cdt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_cdt")
distance_transform_cdt, _ = optional_import("scipy.ndimage", name="distance_transform_cdt")

DEFAULT_POST_FIX = PostFix.meta()

Expand Down
2 changes: 1 addition & 1 deletion monai/apps/nuclick/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

measure, _ = optional_import("skimage.measure")
morphology, _ = optional_import("skimage.morphology")
distance_transform_cdt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_cdt")
distance_transform_cdt, _ = optional_import("scipy.ndimage", name="distance_transform_cdt")


class NuclickKeys(StrEnum):
Expand Down
2 changes: 1 addition & 1 deletion monai/apps/pathology/transforms/post/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from monai.utils.misc import ensure_tuple_rep
from monai.utils.type_conversion import convert_to_dst_type, convert_to_tensor

label, _ = optional_import("scipy.ndimage.measurements", name="label")
label, _ = optional_import("scipy.ndimage", name="label")
disk, _ = optional_import("skimage.morphology", name="disk")
opening, _ = optional_import("skimage.morphology", name="opening")
watershed, _ = optional_import("skimage.segmentation", name="watershed")
Expand Down
4 changes: 2 additions & 2 deletions monai/apps/pathology/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def compute_multi_instance_mask(mask: np.ndarray, threshold: float) -> Any:
"""

neg = 255 - mask * 255
distance = ndimage.morphology.distance_transform_edt(neg)
distance = ndimage.distance_transform_edt(neg)
binary = distance < threshold

filled_image = ndimage.morphology.binary_fill_holes(binary)
filled_image = ndimage.binary_fill_holes(binary)
multi_instance_mask = measure.label(filled_image, connectivity=2)

return multi_instance_mask
Expand Down
6 changes: 3 additions & 3 deletions monai/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
optional_import,
)

binary_erosion, _ = optional_import("scipy.ndimage.morphology", name="binary_erosion")
distance_transform_edt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_edt")
distance_transform_cdt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_cdt")
binary_erosion, _ = optional_import("scipy.ndimage", name="binary_erosion")
distance_transform_edt, _ = optional_import("scipy.ndimage", name="distance_transform_edt")
distance_transform_cdt, _ = optional_import("scipy.ndimage", name="distance_transform_cdt")

__all__ = [
"ignore_background",
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/signal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from monai.utils.enums import TransformBackends
from monai.utils.type_conversion import convert_data_type, convert_to_tensor

shift, has_shift = optional_import("scipy.ndimage.interpolation", name="shift")
shift, has_shift = optional_import("scipy.ndimage", name="shift")
iirnotch, has_iirnotch = optional_import("scipy.signal", name="iirnotch")
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning) # project-monai/monai#5204
Expand Down

0 comments on commit e801540

Please sign in to comment.