示例#1
0
def get_slice(stack, pos):
    """ Returns a slice index for an image stack. Which one
	is 	determined by pos. This can either be an integer index
	or the string "first", "center" or "last".
	"""
    num_slices = stack.dimension.z
    # Just return if we got no stacks at all
    if num_slices == 0:
        return None
    # Check the type of the position informaiton
    pos_type = type(pos)
    #return str(pos_type)
    if is_string_type(pos_type):
        if pos == "first":
            return 0
        elif pos == "center":
            return int(num_slices / 2)
        elif pos == "last":
            return num_slices - 1
    elif pos_type == int:
        # Make sure we are in bounds
        if pos >= 0 and pos < num_slices:
            return pos
    # Return None if nothing else matched
    return None
示例#2
0
def get_slice(stack, pos):
	""" Returns a slice index for an image stack. Which one
	is 	determined by pos. This can either be an integer index
	or the string "first", "center" or "last".
	"""
	num_slices = stack.dimension.z
	# Just return if we got no stacks at all
	if num_slices == 0:
		return None
	# Check the type of the position informaiton
	pos_type = type(pos)
	#return str(pos_type)
	if is_string_type( pos_type ):
		if pos == "first":
			return 0
		elif pos == "center":
			return int(num_slices / 2)
		elif pos == "last":
			return num_slices - 1
	elif pos_type == int:
		# Make sure we are in bounds
		if pos >= 0 and pos < num_slices:
			return pos
	# Return None if nothing else matched
	return None
示例#3
0
def filter_stacks(stacks, pos):
    """ Returns a list of filtered stacks according to the
	pos parameter. This list can contain all stacks (pos is
	"all"), a specific stack (pos is a number), the first or
	the last stack (pos is "first" or "last").
	"""
    if is_string_type(type(pos)) and pos == "all":
        return stacks
    else:
        s = get_stack(stacks, pos)
        if s is None:
            return []
        else:
            return [s]
示例#4
0
def filter_stacks(stacks, pos):
	""" Returns a list of filtered stacks according to the
	pos parameter. This list can contain all stacks (pos is
	"all"), a specific stack (pos is a number), the first or
	the last stack (pos is "first" or "last").
	"""
	if is_string_type( type(pos) ) and pos == "all":
		return stacks.order_by('id')
	else:
		s = get_stack( stacks, pos )
		if s is None:
			return []
		else:
			return [ s ]
示例#5
0
def get_stack(stacks, pos):
    """ Returns an image stack out of stacks. Which one is
	determined by pos. This can either be an integer index
	or the string "first" or "last".
	"""
    num_stacks = len(stacks)
    # Just return if we got no stacks at all
    if num_stacks == 0:
        return None
    # Check the type of the position informaiton
    pos_type = type(pos)
    if is_string_type(pos_type):
        if pos == "first":
            return stacks[0]
        elif pos == "last":
            return stacks[num_stacks - 1]
    elif pos_type == int:
        # Make sure we are in bounds
        if pos >= 0 and pos < num_stacks:
            return stacks[pos]
    # Return None if nothing else matched
    return None
示例#6
0
def get_stack(stacks, pos):
	""" Returns an image stack out of stacks. Which one is
	determined by pos. This can either be an integer index
	or the string "first" or "last".
	"""
	num_stacks = stacks.count()
	# Just return if we got no stacks at all
	if num_stacks == 0:
		return None
	# Check the type of the position informaiton
	pos_type = type(pos)
	if is_string_type( pos_type ):
		if pos == "first":
			return stacks.order_by('id')[0]
		elif pos == "last":
			return stacks.order_by('id')[num_stacks - 1]
	elif pos_type == int:
		# Make sure we are in bounds
		if pos >= 0 and pos < num_stacks:
			return stacks.order_by('id')[pos]
	# Return None if nothing else matched
	return None