コード例 #1
0
    def faceMeans(self, map):
        attr = "faceMeans" + self.colorSpace
        if not hasattr(map, attr):
            img = self.images.get("colored", self.images["original"])
            if self.colorSpace:
                if img.channels != 3:
                    sys.stderr.write(
                        "WARNING: Color space '%s' requested but ignored; image has only %d band!\n"
                        % (img.channels, ))
                else:
                    rgbNames = self.colorSpaceNames[-3:]
                    if self.colorSpace in rgbNames:
                        img = vigra.GrayImage(img[rgbNames.index(
                            self.colorSpace)])
                    else:
                        img = vigra.transformImage(
                            img, "\l x: RGB2%s(x)" % self.colorSpace)
            stats = statistics.FaceColorStatistics(map, img)
            stats.image = img
            setattr(map, attr, stats)

            # let MapDisplay make use of attr 'faceMeans' if applicable:
            # FIXME - 'map' != self.map here, so the action stays disabled..
            self._enableImageActions()
        return getattr(map, attr)
コード例 #2
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def gm2Gradient(gm, sigma):
    """'reverse-engineer' gradient vector image from scalar image
    via Hessian from Gaussian derivative filters of given scale"""

    # create vectors in direction of negative curvature:
    er = vigra.tensorEigenRepresentation(vigra.gaussianHessian(gm, sigma))
    return vigra.transformImage(er, gm,
                                "\l e,i: i*Vector(-sin(e[2]), cos(e[2]))")
コード例 #3
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def gm2Gradient(gm, sigma):
    """'reverse-engineer' gradient vector image from scalar image
    via Hessian from Gaussian derivative filters of given scale"""

    # create vectors in direction of negative curvature:
    er = vigra.tensorEigenRepresentation(
        vigra.gaussianHessian(gm, sigma))
    return vigra.transformImage(
        er, gm, "\l e,i: i*Vector(-sin(e[2]), cos(e[2]))")
コード例 #4
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def colorGradient(img, scale, sqrt = True):
    """Calculate Gaussian color gradient.  Calculates sum of Gaussian
    gradient tensors in all single bands, and returns pair of (gm,
    grad) where gm is the square root of the trace of the color
    gradient tensor and grad is a 2-band image with the large
    eigenvectors of the appropriate sqrt(gm2) lengths.

    If `sqrt` is set to False, returns (gm2, grad) instead, i.e. does
    not apply sqrt to the first image (slight optimization if you
    don't need the gm image)."""

    colorTensor = gradientTensor(img, scale)
    # gm2 := sum of squared magnitudes of grad. in each channel
    gm2 = vigra.tensorTrace(colorTensor)
    # rebuild vector in dir. of large eigenvector with length sqrt(gm2):
    grad = vigra.transformImage( # FIXME: use tensor2Gradient?
        vigra.tensorEigenRepresentation(colorTensor), gm2,
        "\l e, mag2: sqrt(mag2)*Vector(cos(-e[2]), sin(-e[2]))", {})
    if sqrt:
        gm = vigra.transformImage(gm2, "\l x: sqrt(x)")
        return gm, grad
    return gm2, grad
コード例 #5
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def colorGradient(img, scale, sqrt=True):
    """Calculate Gaussian color gradient.  Calculates sum of Gaussian
    gradient tensors in all single bands, and returns pair of (gm,
    grad) where gm is the square root of the trace of the color
    gradient tensor and grad is a 2-band image with the large
    eigenvectors of the appropriate sqrt(gm2) lengths.

    If `sqrt` is set to False, returns (gm2, grad) instead, i.e. does
    not apply sqrt to the first image (slight optimization if you
    don't need the gm image)."""

    colorTensor = gradientTensor(img, scale)
    # gm2 := sum of squared magnitudes of grad. in each channel
    gm2 = vigra.tensorTrace(colorTensor)
    # rebuild vector in dir. of large eigenvector with length sqrt(gm2):
    grad = vigra.transformImage(  # FIXME: use tensor2Gradient?
        vigra.tensorEigenRepresentation(colorTensor), gm2,
        "\l e, mag2: sqrt(mag2)*Vector(cos(-e[2]), sin(-e[2]))", {})
    if sqrt:
        gm = vigra.transformImage(gm2, "\l x: sqrt(x)")
        return gm, grad
    return gm2, grad
コード例 #6
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def gaussianGradient(img, scale, sqrt = True):
    """Return (gm, grad) tuple, which is either the result of
    `colorGradient`, or of the usual `vigra.gaussianGradient` family
    for single-band images."""

    if img.channels > 1:
        return colorGradient(img, scale, sqrt)

    grad = vigra.filters.gaussianGradient(img, scale)
    if sqrt:
        # FIXME: compute gm from grad for efficiency
        gm = vigra.filters.gaussianGradientMagnitude(img, scale)
    else:
        # FIXME: port to vigranumpy
        gm = vigra.transformImage(grad, "\l x: squaredNorm(x)")
    return gm, grad
コード例 #7
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def gaussianGradient(img, scale, sqrt=True):
    """Return (gm, grad) tuple, which is either the result of
    `colorGradient`, or of the usual `vigra.gaussianGradient` family
    for single-band images."""

    if img.channels > 1:
        return colorGradient(img, scale, sqrt)

    grad = vigra.filters.gaussianGradient(img, scale)
    if sqrt:
        # FIXME: compute gm from grad for efficiency
        gm = vigra.filters.gaussianGradientMagnitude(img, scale)
    else:
        # FIXME: port to vigranumpy
        gm = vigra.transformImage(grad, "\l x: squaredNorm(x)")
    return gm, grad
コード例 #8
0
ファイル: mapdisplay.py プロジェクト: hmeine/geomap
    def setImage(self, image, normalize = None, role = None):
        """Replace displayed background image.  You may pass role as
        one of ('original', 'colored', 'bi') to replace one of the
        predefined image slots (keyboard shortcuts 1-5)."""
        if role == None:
            if image.channels == 3:
                self.images["original"] = vigra.transformImage(
#                    image, "\l x: RGB2Lab(x)")[0]
                    image, "\l x: norm(x)/%r" % math.sqrt(3))
                role = "colored"
            else:
                role = "original"
        self.images[role] = image
        self._enableImageActions()
        if normalize == None:
            normalize = self._normalizeStates[self._backgroundMode]
        if self.viewer and role == self.currentRole():
            self._setImage(image, normalize)
コード例 #9
0
ファイル: mapdisplay.py プロジェクト: hmeine/geomap
 def setImage(self, image, normalize=None, role=None):
     """Replace displayed background image.  You may pass role as
     one of ('original', 'colored', 'bi') to replace one of the
     predefined image slots (keyboard shortcuts 1-5)."""
     if role == None:
         if image.channels == 3:
             self.images["original"] = vigra.transformImage(
                 #                    image, "\l x: RGB2Lab(x)")[0]
                 image,
                 "\l x: norm(x)/%r" % math.sqrt(3))
             role = "colored"
         else:
             role = "original"
     self.images[role] = image
     self._enableImageActions()
     if normalize == None:
         normalize = self._normalizeStates[self._backgroundMode]
     if self.viewer and role == self.currentRole():
         self._setImage(image, normalize)
コード例 #10
0
ファイル: workspace.py プロジェクト: hmeine/geomap
    def faceMeans(self, map):
        attr = "faceMeans" + self.colorSpace
        if not hasattr(map, attr):
            img = self.images.get("colored", self.images["original"])
            if self.colorSpace:
                if img.channels != 3:
                    sys.stderr.write("WARNING: Color space '%s' requested but ignored; image has only %d band!\n" % (img.channels, ))
                else:
                    rgbNames = self.colorSpaceNames[-3:]
                    if self.colorSpace in rgbNames:
                        img = vigra.GrayImage(img[rgbNames.index(self.colorSpace)])
                    else:
                        img = vigra.transformImage(
                            img, "\l x: RGB2%s(x)" % self.colorSpace)
            stats = statistics.FaceColorStatistics(map, img)
            stats.image = img
            setattr(map, attr, stats)

            # let MapDisplay make use of attr 'faceMeans' if applicable:
            # FIXME - 'map' != self.map here, so the action stays disabled..
            self._enableImageActions()
        return getattr(map, attr)
コード例 #11
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def tensor2Gradient(tensor):
    """rebuild vectors in dir. of large eigenvectors with lengths sqrt(trace)"""
    return vigra.transformImage(
        vigra.tensorEigenRepresentation(tensor),
        "\l e: sqrt(e[0]+e[1])*Vector(cos(-e[2]), sin(-e[2]))", {})
コード例 #12
0
ファイル: bi_utils.py プロジェクト: hmeine/geomap
def tensor2Gradient(tensor):
    """rebuild vectors in dir. of large eigenvectors with lengths sqrt(trace)"""
    return vigra.transformImage(
        vigra.tensorEigenRepresentation(tensor),
        "\l e: sqrt(e[0]+e[1])*Vector(cos(-e[2]), sin(-e[2]))", {})