Skip to content

Commit abfe540

Browse files
author
Benjamin Aron
committed
bug fixes for adaptive patch denoising. Algorithm and shrinkage were mistakenly hard coded previously.
1 parent 5eda8ea commit abfe540

File tree

4,279 files changed

+208203
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,279 files changed

+208203
-13
lines changed

designer2/designer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def usage(cmdline): #pylint: disable=unused-variable
8585
mp_options.add_argument('-extent', metavar=('<size>'), help='MPPCA Denoising extent. Default is 5,5,5')
8686
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)
8787
mp_options.add_argument('-adaptive_patch', action='store_true', help='Run MPPCA with adaptive patching')
88-
88+
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')
89+
8990
rpe_options = cmdline.add_argument_group('Options for eddy and to specify the acquisition phase-encoding design')
9091
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')
9192
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)

docs/docs/designer/usage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ Olesen, J. L., Ianus, A., Østergaard, L., Shemesh, N., & Jespersen, S. N. (2023
9090
- 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.
9191
- 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.
9292

93+
### `-adaptive_patch_length`
94+
- Manually Specify the size of the adaptive patch.
95+
- choose a range from 1 to prod(extent). Default is 80% of the kernel size.
96+
9397
### `-phase <phase_image1,phase_image2,...>`
9498
- 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.
9599
- Used in conjunction with `-denoise` option.

lib/designer_func_wrappers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ def run_mppca(args_extent, args_phase, args_shrinkage, args_algorithm):
5656
start_time = time.time()
5757

5858
if app.ARGS.adaptive_patch:
59+
60+
if app.ARGS.adaptive_patch_length:
61+
adapt_length = int(app.ARGS.adaptive_patch_length)
62+
else:
63+
adapt_length = None
64+
5965
Signal, Sigma, Nparameters = mp.denoise(
60-
dwi, phase=args_phase, patchtype='nonlocal', shrinkage=args_shrinkage, algorithm=args_algorithm
66+
dwi, phase=args_phase, kernel=extent, patchtype='nonlocal', patchsize=adapt_length, shrinkage=args_shrinkage, algorithm=args_algorithm
6167
)
6268
else:
6369
Signal, Sigma, Nparameters = mp.denoise(

lib/mpdenoise_adaptive.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,6 @@ def process(self):
355355
# # parallel
356356
signal, sigma, npars = zip(*Parallel(n_jobs=num_cores, prefer='processes')\
357357
(delayed(self.denoise)(coords[:,i]) for i in inputs))
358-
359-
# # serial
360-
# k = self.kernel // 2
361-
# #for t in inputs:
362-
# crds = np.array([48+k[0], 38+k[1], 25+k[2]])
363-
# a, b, c = self.denoise(crds)
364358

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

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

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

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

424417
return abs(Signal), Sigma, Npars
425418

426-
# if __name__ == "__main__":
427-
# denoise()
419+
if __name__ == "__main__":
420+
denoise()
428421

rpg_cpp/fftw-3.3.10/FFTW3Config.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# defined since 2.8.3
2+
if (CMAKE_VERSION VERSION_LESS 2.8.3)
3+
get_filename_component (CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
4+
endif ()
5+
6+
# Allows loading FFTW3 settings from another project
7+
set (FFTW3_CONFIG_FILE "${CMAKE_CURRENT_LIST_FILE}")
8+
9+
set (FFTW3_LIBRARIES fftw3)
10+
set (FFTW3_LIBRARY_DIRS /Users/benaron/Desktop/DESIGNER-v2/rpg_cpp/fftw-3.3.10/build/lib)
11+
set (FFTW3_INCLUDE_DIRS /Users/benaron/Desktop/DESIGNER-v2/rpg_cpp/fftw-3.3.10/build/include)
12+
13+
include ("${CMAKE_CURRENT_LIST_DIR}/FFTW3LibraryDepends.cmake")
14+
15+
if (CMAKE_VERSION VERSION_LESS 2.8.3)
16+
set (CMAKE_CURRENT_LIST_DIR)
17+
endif ()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
set (PACKAGE_VERSION "3.3.10")
3+
4+
# Check whether the requested PACKAGE_FIND_VERSION is compatible
5+
if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
6+
set (PACKAGE_VERSION_COMPATIBLE FALSE)
7+
else ()
8+
set (PACKAGE_VERSION_COMPATIBLE TRUE)
9+
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
10+
set (PACKAGE_VERSION_EXACT TRUE)
11+
endif ()
12+
endif ()

0 commit comments

Comments
 (0)