Skip to content

Commit

Permalink
bug fixes for adaptive patch denoising. Algorithm and shrinkage were …
Browse files Browse the repository at this point in the history
…mistakenly hard coded previously.
  • Loading branch information
Benjamin Aron committed Jan 9, 2025
1 parent 5eda8ea commit abfe540
Show file tree
Hide file tree
Showing 4,279 changed files with 208,203 additions and 13 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 2 additions & 1 deletion designer2/designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def usage(cmdline): #pylint: disable=unused-variable
mp_options.add_argument('-extent', metavar=('<size>'), help='MPPCA Denoising extent. Default is 5,5,5')
mp_options.add_argument('-phase', metavar=('<image>'), help='Diffusion phases - for performing denoising on complex data. This option should not be used alongside "-rician" since denoising complex data reduces the noise floor.', default=None)
mp_options.add_argument('-adaptive_patch', action='store_true', help='Run MPPCA with adaptive patching')

mp_options.add_argument('-adaptive_patch_length', metavar=('<len>'), help='Size of the adaptive patch for MPPCA denoising. Default is 80% of the kernel size')

rpe_options = cmdline.add_argument_group('Options for eddy and to specify the acquisition phase-encoding design')
rpe_options.add_argument('-eddy', action='store_true', help='run fsl eddy (note that if you choose this command you must also choose a phase encoding option')
rpe_options.add_argument('-eddy_groups',metavar=('<index1,index2,...'),help='specify how input series should be grouped when running eddy, for use with variable TE or b-shape data. (Comma separated list of integers beginning with 1, i.e. 1,1,1,2,2,2 for 6 series where the first 3 series and second 3 series have different echo times).', default=None)
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/designer/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ Olesen, J. L., Ianus, A., Østergaard, L., Shemesh, N., & Jespersen, S. N. (2023
- Note when this argument is used, the patch size will be chosen based on the extent, where the total number of voxels in the adaptive patch is 80% of the total voxels in a patch.
- Without the `-adaptive_patch` option, the patches are chosen as blocks with a step size of floor(extent/2), this increases speed at the expense of accuracy in noise estimation.

### `-adaptive_patch_length`
- Manually Specify the size of the adaptive patch.
- choose a range from 1 to prod(extent). Default is 80% of the kernel size.

### `-phase <phase_image1,phase_image2,...>`
- Include a volume (or volumes) of phase images corresponding to the input(s) to Designer. For example, if two series are input to Designer with a total of 100 directions, there should be two phase series with 100 total volumes.
- Used in conjunction with `-denoise` option.
Expand Down
8 changes: 7 additions & 1 deletion lib/designer_func_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ def run_mppca(args_extent, args_phase, args_shrinkage, args_algorithm):
start_time = time.time()

if app.ARGS.adaptive_patch:

if app.ARGS.adaptive_patch_length:
adapt_length = int(app.ARGS.adaptive_patch_length)
else:
adapt_length = None

Signal, Sigma, Nparameters = mp.denoise(
dwi, phase=args_phase, patchtype='nonlocal', shrinkage=args_shrinkage, algorithm=args_algorithm
dwi, phase=args_phase, kernel=extent, patchtype='nonlocal', patchsize=adapt_length, shrinkage=args_shrinkage, algorithm=args_algorithm
)
else:
Signal, Sigma, Nparameters = mp.denoise(
Expand Down
15 changes: 4 additions & 11 deletions lib/mpdenoise_adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,6 @@ def process(self):
# # parallel
signal, sigma, npars = zip(*Parallel(n_jobs=num_cores, prefer='processes')\
(delayed(self.denoise)(coords[:,i]) for i in inputs))

# # serial
# k = self.kernel // 2
# #for t in inputs:
# crds = np.array([48+k[0], 38+k[1], 25+k[2]])
# a, b, c = self.denoise(crds)

# reconstruct original data matrix
Sigma = np.zeros((sx, sy, sz))
Expand Down Expand Up @@ -406,23 +400,22 @@ def denoise(img, kernel=None, patchtype=None, patchsize=None, shrinkage=None, al
# ants.image_write(out, 'phase_dn.nii')
out = ants.from_numpy(phi_dn, origin=nii.origin, spacing=nii.spacing, direction=nii.direction)
ants.image_write(out, 'phase_dn.nii')
# import pdb; pdb.set_trace()

print('magnitude denoising - adaptive patching')
img_np = np.real(img*np.exp(-1j*phi_dn))
mp = MP(img_np, kernel, patchtype='adaptive', patchsize=None, shrinkage='frob', algorithm='jespersen', crop=0)
mp = MP(img_np, kernel, patchtype='adaptive', patchsize=patchsize, shrinkage=shrinkage, algorithm=algorithm, crop=0)
Signal, Sigma, Npars = mp.process()

else:
zeroinds = np.where(img==0)
img[zeroinds] = np.finfo(img.dtype).eps

mp = MP(img.copy(), kernel, patchtype='adaptive', patchsize=None, shrinkage='frob', algorithm='cordero-grande', crop=0)
mp = MP(img.copy(), kernel, patchtype='adaptive', patchsize=patchsize, shrinkage=shrinkage, algorithm=algorithm, crop=0)
Signal, Sigma, Npars = mp.process()
Signal[zeroinds] = 0

return abs(Signal), Sigma, Npars

# if __name__ == "__main__":
# denoise()
if __name__ == "__main__":
denoise()

17 changes: 17 additions & 0 deletions rpg_cpp/fftw-3.3.10/FFTW3Config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# defined since 2.8.3
if (CMAKE_VERSION VERSION_LESS 2.8.3)
get_filename_component (CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
endif ()

# Allows loading FFTW3 settings from another project
set (FFTW3_CONFIG_FILE "${CMAKE_CURRENT_LIST_FILE}")

set (FFTW3_LIBRARIES fftw3)
set (FFTW3_LIBRARY_DIRS /Users/benaron/Desktop/DESIGNER-v2/rpg_cpp/fftw-3.3.10/build/lib)
set (FFTW3_INCLUDE_DIRS /Users/benaron/Desktop/DESIGNER-v2/rpg_cpp/fftw-3.3.10/build/include)

include ("${CMAKE_CURRENT_LIST_DIR}/FFTW3LibraryDepends.cmake")

if (CMAKE_VERSION VERSION_LESS 2.8.3)
set (CMAKE_CURRENT_LIST_DIR)
endif ()
12 changes: 12 additions & 0 deletions rpg_cpp/fftw-3.3.10/FFTW3ConfigVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

set (PACKAGE_VERSION "3.3.10")

# Check whether the requested PACKAGE_FIND_VERSION is compatible
if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set (PACKAGE_VERSION_COMPATIBLE FALSE)
else ()
set (PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set (PACKAGE_VERSION_EXACT TRUE)
endif ()
endif ()
Loading

0 comments on commit abfe540

Please sign in to comment.