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

BUG: Fixed resizing for wavelet filtering (resizing was scrambling image) #346

Merged
merged 2 commits into from
Feb 21, 2018

Conversation

michaelschwier
Copy link
Contributor

@michaelschwier michaelschwier commented Feb 16, 2018

The resizing in _swt3, which is called by getWaveletImage to extend images to ensure image dims are multiples of 2, causes images to be scrambled, because numpy's resize simply adds zeros at the end of the buffer and changes the shape of the array (see here, esp. example 3).

Hence for enlarging we need to use numpy.pad and for shrinking back we need to use slicing (see fixed code).

This causes the wavelet results to be wrong for all images/ROIs with an odd dimension (actually for only odd z it might not be, because in this case the resize "accidentally" has the expected behavior).

All the above insights and the fixed code is courtesy of Jan Moltz/Fraunhofer MEVIS, who tracked this bug down.

To reproduce and test the bug/bugfix I created test data and implemented a little test, which you can find here.
If you run the python file, it will write a "test_out.csv" with the extracted features for different images and crop settings. It will also print all features which have different outcomes among the test images/settings and the max abs difference.

PS: You will see that the LoG filter also causes differences, but rather small ones. I assume this is expected since the ITK filter used probably doesn't use a fixed kernel size but tries to approximate a real gaussian filter. However, we might consider if this is behavior we want/accept for radiomics or if we would prefer perfectly reproducible feature values.

… image anymore. (bugfix courtesy of Jan Moltz/Fraunhofer MEVIS)
@fedorov
Copy link
Collaborator

fedorov commented Feb 16, 2018

Thank you for investigating this Michael and Jan! I am glad you found it.

data = matrix.copy()
data.resize(adjusted_shape, refcheck=False)
data = numpy.pad(data, padding, 'constant')
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed, should change boudnary mode to wrap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants