Ejemplo n.º 1
0
def extrema(input, labels=None, index=None):
    """Calculate the minimum, the maximum and their positions of the
       values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, "Complex type not supported"
    if labels is not None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, "input and labels shape are not equal"

    min, max, minp, maxp = _nd_image.statistics(input, labels, index, 7)
    if isinstance(minp, types.ListType):
        minp = [_index_to_position(x, input.shape) for x in minp]
        maxp = [_index_to_position(x, input.shape) for x in maxp]
    else:
        minp = _index_to_position(minp, input.shape)
        maxp = _index_to_position(maxp, input.shape)
    return min, max, minp, maxp
Ejemplo n.º 2
0
def extrema(input, labels=None, index=None):
    """Calculate the minimum, the maximum and their positions of the
       values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, 'Complex type not supported'
    if labels is not None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'

    min, max, minp, maxp = _nd_image.statistics(input, labels, index, 7)
    if (isinstance(minp, types.ListType)):
        minp = [_index_to_position(x, input.shape) for x in minp]
        maxp = [_index_to_position(x, input.shape) for x in maxp]
    else:
        minp = _index_to_position(minp, input.shape)
        maxp = _index_to_position(maxp, input.shape)
    return min, max, minp, maxp
Ejemplo n.º 3
0
def sum(input, labels=None, index=None):
    """Calculate the sum of the values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numarray.asarray(input)
    if isinstance(input.type(), numarray.ComplexType):
        raise TypeError, 'Complex type not supported'
    if labels != None:
        labels = numarray.asarray(labels)
        labels = _broadcast(labels, input.shape)
        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    return _nd_image.statistics(input, labels, index, 0)
Ejemplo n.º 4
0
def sum(input, labels = None, index = None):
    """Calculate the sum of the values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numarray.asarray(input)
    if isinstance(input.type(), numarray.ComplexType):
        raise TypeError, 'Complex type not supported'
    if labels != None:
        labels = numarray.asarray(labels)
        labels = _broadcast(labels, input.shape)
        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    return _nd_image.statistics(input, labels, index, 0)
Ejemplo n.º 5
0
def minimum(input, labels=None, index=None):
    """Calculate the minimum of the values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, "Complex type not supported"
    if labels is not None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, "input and labels shape are not equal"
    return _nd_image.statistics(input, labels, index, 3)
Ejemplo n.º 6
0
def maximum(input, labels=None, index=None):
    """Return the maximum input value.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.

    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, 'Complex type not supported'
    if labels is not None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    return _nd_image.statistics(input, labels, index, 4)
Ejemplo n.º 7
0
def maximum_position(input, labels=None, index=None):
    """Find the position of the maximum of the values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numarray.asarray(input)
    if isinstance(input.type(), numarray.ComplexType):
        raise TypeError, 'Complex type not supported'
    if labels != None:
        labels = numarray.asarray(labels)
        labels = _broadcast(labels, input.shape)
        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    pos = _nd_image.statistics(input, labels, index, 6)
    if (isinstance(pos, types.ListType)):
        return [_index_to_position(x, input.shape) for x in pos]
    else:
        return _index_to_position(pos, input.shape)
Ejemplo n.º 8
0
def maximum_position(input, labels = None, index = None):
    """Find the position of the maximum of the values of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numarray.asarray(input)
    if isinstance(input.type(), numarray.ComplexType):
        raise TypeError, 'Complex type not supported'
    if labels != None:
        labels = numarray.asarray(labels)
        labels = _broadcast(labels, input.shape)
        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    pos = _nd_image.statistics(input, labels, index, 6)
    if (isinstance(pos, types.ListType)):
        return [_index_to_position(x, input.shape) for x in pos]
    else:
        return _index_to_position(pos, input.shape)
Ejemplo n.º 9
0
def sum(input, labels=None, index=None):
    """Calculate the sum of the values of the array.

    :Parameters:
        labels : array of integers, same shape as input
            Assign labels to the values of the array.

        index : scalar or array
            A single label number or a sequence of label numbers of
            the objects to be measured. If index is None, all
            values are used where 'labels' is larger than zero.

    Examples
    --------

    >>> input =  [0,1,2,3]
    >>> labels = [1,1,2,2]
    >>> sum(input, labels, index=[1,2])
    [1.0, 5.0]

    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, 'Complex type not supported'
    if labels is not None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    if index is not None:
        T = getattr(index, 'dtype', numpy.int32)
        if T not in [
                numpy.int8, numpy.int16, numpy.int32, numpy.uint8,
                numpy.uint16, numpy.bool
        ]:
            raise ValueError("Invalid index type")
        index = numpy.asarray(index, dtype=T)
    return _nd_image.statistics(input, labels, index, 0)
Ejemplo n.º 10
0
def sum(input, labels=None, index=None):
    """Calculate the sum of the values of the array.

    :Parameters:
        labels : array of integers, same shape as input
            Assign labels to the values of the array.

        index : scalar or array
            A single label number or a sequence of label numbers of
            the objects to be measured. If index is None, all
            values are used where 'labels' is larger than zero.

    Examples
    --------

    >>> input =  [0,1,2,3]
    >>> labels = [1,1,2,2]
    >>> sum(input, labels, index=[1,2])
    [1.0, 5.0]

    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, 'Complex type not supported'
    if labels is not None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    if index is not None:
        T = getattr(index,'dtype',numpy.int32)
        if T not in [numpy.int8, numpy.int16, numpy.int32,
                     numpy.uint8, numpy.uint16, numpy.bool]:
            raise ValueError("Invalid index type")
        index = numpy.asarray(index,dtype=T)
    return _nd_image.statistics(input, labels, index, 0)