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

Fix incorrect slicing during application of wavelet filter #182

Merged
merged 1 commit into from Jan 25, 2017

Conversation

JoostJM
Copy link
Collaborator

@JoostJM JoostJM commented Jan 17, 2017

Due to some slicing errors, the wavelet filter resulted in a 90deg rotation and a mirroring along one axis. This resulted in that the labelmaps did not align with the ROI anymore, causing the wavelet features to be incorrectly calculated.

This PR addresses this error by recoding the slicing during wavelet decomposition. Results have been checked visually. I'll add some examples later.

@JoostJM
Copy link
Collaborator Author

JoostJM commented Jan 19, 2017

Original

original

LLL: Image is flipped and rotated --> This is due to incorrect slicing, the tumor is the hyper instenisty seen at the top

wavelet_lll_old

LLH: Bottom slice is somehow 'copied' / filtered and inserted over the top slice --> This is due to the wavelet transform by the pywavelet package, will look into this further...

wavelet_llh_old

@JoostJM
Copy link
Collaborator Author

JoostJM commented Jan 19, 2017

Tests of the pywavelet functions (using Haar wavelet):

Test1, length = 8
In: [5 4 3 0 0 0 0 0]
Out-A: [ 6.364 4.9497 2.1213 0. 0. 0. 0. 3.5355]
Out-D: [ 0.7071 0.7071 2.1213 0. 0. 0. 0. -3.5355]

Test2, length = 6
In: [5 4 3 0 0 0]
Out-A: [ 6.364 4.9497 2.1213 0. 0. 3.5355]
Out-D: [ 0.7071 0.7071 2.1213 0. 0. -3.5355]

Test3, reverse
In: [0 0 0 0 0 3 4 5]
Out-A: [ 0. 0. 0. 0. 2.1213 4.9497 6.364 3.5355]
Out-D: [ 0. 0. 0. 0. -2.1213 -0.7071 -0.7071 3.5355]

Test4, reverse with extra padding
In: [0 0 0 0 0 3 4 5 0 0]
Out-A: [ 0. 0. 0. 0. 2.1213 4.9497 6.364 3.5355 0. 0. ]
Out-D: [ 0. 0. 0. 0. -2.1213 -0.7071 -0.7071 3.5355 0. 0. ]

Test5, discreet instead of stationary wavelet transform
In: [5 4 3 0 0 0 0 0]
Out-A: [ 6.364 2.1213 0. 0. ]
Out-D: [ 0.7071 2.1213 0. 0. ]

The value of 3.5355 is equal to 1/sqrt(2) * (5 + 0), i.e. looks like it wraps around for the last index:
1/sqrt(2) * (index[-1] + index[0]) for A, 1/sqrt(2) * (index[-1] - index[0]) for D

@JoostJM
Copy link
Collaborator Author

JoostJM commented Jan 19, 2017

Got a response from pywavelets: This duplication 'error' is intentional, as it is their way of handling edges: swt is forced to periodization, which appends copies of the array.
Furthermore, in swt, the wavelets overlap (i.e. first index in Haar is calculated using inidces 0 and 1, 2nd using 1 and 2, etc.), but with dwt there is no overlap. If I understand correctly, this is different from just upsampling the filter coefficients, correct? (Test 1 and 2 nicely show this, when you look at the 2nd filter)

I will look at the matlab code to see if I can find how the wavelets were calculated before...

@JoostJM JoostJM merged commit 99f668c into AIM-Harvard:master Jan 25, 2017
@JoostJM JoostJM deleted the bugfix-wavelet-filter branch February 16, 2017 09:01
@JoostJM JoostJM added this to Bugfixes in Feature definitions Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Feature definitions
  
Bugfixes
Development

Successfully merging this pull request may close these issues.

None yet

1 participant