Skip to content
Snippets Groups Projects
Commit 51123396 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Fixed up fslmaths module

parent b118c2d0
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,8 @@ for the ``fslmaths`` command-line tool.
"""
import fsl.utils.run as run
import fsl.utils.run as run
from . import wrapperutils as wutils
class fslmaths(object):
......@@ -17,142 +18,143 @@ class fslmaths(object):
def __init__(self, input):
"""Constructor."""
self.inputImage = input
self.outputImage = None
self.operations = []
self.__input = input
self.__args = []
def abs(self):
"""Absolute value."""
self.operations.append("-abs")
self.__args.append("-abs")
return self
def bin(self):
"""Use (current image>0) to binarise."""
self.operations.append("-bin")
self.__args.append("-bin")
return self
def binv(self):
"""Binarise and invert (binarisation and logical inversion)."""
self.operations.append("-binv")
self.__args.append("-binv")
return self
def recip(self):
"""Reciprocal (1/current image)."""
self.operations.append("-recip")
self.__args.append("-recip")
return self
def Tmean(self):
"""Mean across time."""
self.operations.append("-Tmean")
self.__args.append("-Tmean")
return self
def Tstd(self):
"""Standard deviation across time."""
self.operations.append("-Tstd")
self.__args.append("-Tstd")
return self
def Tmin(self):
"""Min across time."""
self.operations.append("-Tmin")
self.__args.append("-Tmin")
return self
def Tmax(self):
"""Max across time."""
self.operations.append("-Tmax")
self.__args.append("-Tmax")
return self
def fillh(self):
"""fill holes in a binary mask (holes are internal - i.e. do not touch
the edge of the FOV)."""
self.operations.append("-fillh")
self.__args.append("-fillh")
return self
def ero(self, repeat=1):
"""Erode by zeroing non-zero voxels when zero voxels in kernel."""
for i in range(repeat):
self.operations.append("-ero")
self.__args.append("-ero")
return self
def dilM(self, repeat=1):
"""Mean Dilation of non-zero voxels."""
for i in range(repeat):
self.operations.append("-dilM")
self.__args.append("-dilM")
return self
def dilF(self, repeat=1):
"""Maximum filtering of all voxels."""
for i in range(repeat):
self.operations.append("-dilF")
self.__args.append("-dilF")
return self
def add(self, input):
def add(self, image):
"""Add input to current image."""
self.operations.append("-add {0}".format(input))
self.__args.extend(("-add", image))
return self
def sub(self, input):
"""Subtract input from current image."""
self.operations.append("-sub {0}".format(input))
def sub(self, image):
"""Subtract image from current image."""
self.__args.extend(("-sub", image))
return self
def mul(self, input):
"""Multiply current image by input."""
self.operations.append("-mul {0}".format(input))
def mul(self, image):
"""Multiply current image by image."""
self.__args.extend(("-mul", image))
return self
def div(self, input):
"""Divide current image by input."""
self.operations.append("-div {0}".format(input))
def div(self, image):
"""Divide current image by image."""
self.__args.extend(("-div", image))
return self
def mas(self, image):
"""Use image (>0) to mask current image."""
self.operations.append("-mas {0}".format(image))
self.__args.extend(("-mas", image))
return self
def rem(self, input):
"""Divide current image by following input and take remainder."""
self.operations.append("-rem {0}".format(input))
def rem(self, image):
"""Divide current image by following image and take remainder."""
self.__args.extend(("-rem", image))
return self
def thr(self, input):
"""use input number to threshold current image (zero < input)."""
self.operations.append("-thr {0}".format(input))
def thr(self, image):
"""use image number to threshold current image (zero < image)."""
self.__args.extend(("-thr", image))
return self
def uthr(self, input):
"""use input number to upper-threshold current image (zero
def uthr(self, image):
"""use image number to upper-threshold current image (zero
anything above the number)."""
self.operations.append("-uthr {0}".format(input))
self.__args.extend(("-uthr", image))
return self
def inm(self, input):
def inm(self, image):
"""Intensity normalisation (per 3D volume mean)"""
self.operations.append("-inm {0}".format(input))
self.__args.extend(("-inm", image))
return self
def bptf(self, hp_sigma, lp_sigma):
"""Bandpass temporal filtering; nonlinear highpass and Gaussian linear
lowpass (with sigmas in volumes, not seconds); set either sigma<0 to
skip that filter."""
self.operations.append("-bptf {0} {1}".format(hp_sigma, lp_sigma))
self.__args.extend(("-bptf", hp_sigma, lp_sigma))
return self
def toString(self):
"""Generate fslmaths command string."""
cmd = "fslmaths {0} ".format(self.inputImage)
for oper in self.operations:
cmd = cmd + oper + " "
cmd = cmd + self.outputImage
return cmd
def run(self, output=None):
"""Save output of operations to image."""
if output:
self.outputImage = output
else:
self.outputImage = self.inputImage
run.runfsl(self.toString())
cmd = ['fslmaths', self.__input] + self.__args
if output is None: cmd += [wutils.LOAD]
else: cmd += [output]
result = self.__run(*cmd)
# if output is LOADed, there
# will only be one entry in
# the result dict.
if output is None: return list(result.values())[0]
else: return output
return self.outputImage
@wutils.fileOrImage()
def __run(self, *cmd):
"""Run the given ``fslmaths`` command. """
return run.runfsl([str(c) for c in cmd])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment