Adding a median filter for 2/3D images#5307
Conversation
It is adapted to MONAI style. Co-authored-by: Ebrahim Ebrahim [email protected]
|
One test fails, I don't know why. |
|
@wyli and @ebrahimebrahim can you provide some feedback? Or take over the PR? |
|
sure, I'll try to finalize this one.. |
|
I think it looks good; thanks for working on this! Some useful features, which could potentially be put off to future work:
|
ERROR: test_value_15 (__main__.TestMedianSmoothd)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/parameterized/parameterized.py", line 533, in standalone_func
return func(*(a + p.args), **p.kwargs)
File "/home/dzenan/MONAI/tests/test_median_smoothd.py", line 72, in test_value
result = MedianSmoothd(**argments)(image)
File "/home/dzenan/MONAI/monai/transforms/intensity/dictionary.py", line 1020, in __call__
d[key] = self.converter(d[key])
File "/home/dzenan/MONAI/monai/transforms/intensity/array.py", line 1165, in __call__
out_t: torch.Tensor = median_filter_instance(img_t.unsqueeze(0)).squeeze(0)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/dzenan/MONAI/monai/networks/layers/simplelayers.py", line 519, in forward
x = median_filter(x, self.window, self.kernel)
File "/home/dzenan/MONAI/monai/networks/layers/simplelayers.py", line 475, in median_filter
features: torch.Tensor = F.conv3d(in_tensor.reshape(c, 1, *sshape), kernel, padding="same", stride=1)
RuntimeError: Expected 4-dimensional input for 4-dimensional weight[3, 1, 1, 3], but got 5-dimensional input of size [1, 1, 1, 3, 3] instead
----------------------------------------------------------------------
Ran 20 tests in 0.828s
|
I am stuck again. Judging by debugger's inspection, we are passing both 4D tensor and 4D kernel for 2D test case to |
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
|
What we really want is pad with 'replicate' mode. Otherwise zeroes creep in all around the edges. With the small test images that is super-obvious, but it might be hard to debug with realistic-sized images later on, especially for other people. @wyli If you can take a crack at this modification, that would be great. Otherwise I could give it a shot later, perhaps in a new PR. |
Signed-off-by: Wenqi Li <[email protected]>
sure, I'll stop here with constant padding 0 for a basic implementation... |
Signed-off-by: Wenqi Li <[email protected]>
|
added an example here Project-MONAI/DocImages#16 |
|
/build |
Signed-off-by: Wenqi Li <[email protected]>
|
/build |
wyli
left a comment
There was a problem hiding this comment.
looks good to me, padding mode and separable approximations are left for future PRs.
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant of median filtering. Signed-off-by: Dženan Zukić <[email protected]> Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]>
Ref Project-MONAI#5264. Follow-up to Project-MONAI#5307. This is a more normal, intuitive variant of median filtering. Signed-off-by: Dženan Zukić <[email protected]> Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Signed-off-by: Behrooz <[email protected]>
Co-authored-by: @ebrahimebrahim. Closes #5264. <!--- 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). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] 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 --disttests`. - [x] In-line docstrings updated. - [x] Documentation updated, tested `make html` command in the `docs/` folder.
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant of median filtering. Signed-off-by: Dženan Zukić <[email protected]> Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]>
Co-authored-by: @ebrahimebrahim. Closes #5264. <!--- 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). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] 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 --disttests`. - [x] In-line docstrings updated. - [x] Documentation updated, tested `make html` command in the `docs/` folder.
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant of median filtering. Signed-off-by: Dženan Zukić <[email protected]> Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]>
Co-authored-by: @ebrahimebrahim. Closes #5264. ### 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). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] 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 --disttests`. - [x] In-line docstrings updated. - [x] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: KumoLiu <[email protected]>
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant of median filtering. Signed-off-by: Dženan Zukić <[email protected]> Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Co-authored-by: Wenqi Li <[email protected]> Signed-off-by: KumoLiu <[email protected]>
Co-authored-by: @ebrahimebrahim. Closes #5264.
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.