-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmooth_3D_image.py
executable file
·47 lines (37 loc) · 1.41 KB
/
smooth_3D_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
This script performs a gaussian smoothing on a
4D IRMf data image (nifti format).
Author: Bertrand Thirion
"""
import numpy as np
import scipy.ndimage as sn
from nipy.io.imageformats import load, Nifti1Image, save
# -----------------------------------------------------------
# --------- Paths -------------------------------------------
# -----------------------------------------------------------
from database_archi import *
#----- Path to the original image
#orig_data_path = ?
#----- Output path for the smoothed image
#smoothed_data_path = ?
# -----------------------------------------------------------
# --------- Parameters -------------------------------------
# -----------------------------------------------------------
#----- Amount of (gaussian) smoothing
#SIGMA3D = ?
# -----------------------------------------------------------
# --------- Script starts -----------------------------------
# -----------------------------------------------------------
# Read input image
input_image = load(orig_data_path)
input_data = input_image.get_data()
shape = input_image.get_shape()
affine = input_image.get_affine()
# Init output data
output_data = input_data.copy()
# Perform smoothing
output_data = sn.gaussian_filter(output_data,
[SIGMA3D/3., SIGMA3D/3., SIGMA3D/3., 0])
output_image = Nifti1Image(output_data, affine)
# Save output image
save(output_image, smoothed_data_path)