Ejemplo n.º 1
0
    def find_mask(img):
        img.save(FingerprintIELib.FILE)

        image = ndimage.imread(FingerprintIELib.FILE, mode="L").astype("float64")
        image = Utils.normalize(image)
        mask = Utils.find_mask(image)

        misc.imsave(FingerprintIELib.FILE, mask)
        return Image.open(FingerprintIELib.FILE)
Ejemplo n.º 2
0
    def binarizing(img, filter_type, subdivide):
        img.save(FingerprintIELib.FILE)

        image = ndimage.imread(FingerprintIELib.FILE, mode="L").astype("float64")
        image = Utils.normalize(image)
        mask = Utils.find_mask(image)

        image = np.where(mask == 1.0, Utils.local_normalize(image), image)
        orientations = np.where(mask == 1.0, Utils.estimate_orientations(image), -1.0)

        frequencies = np.where(mask == 1.0, Utils.estimate_frequencies(image, orientations), -1.0)

        if filter_type == 'gabor':
            if subdivide:
                image = Utils.normalize(GaborUtil.gaborFilterSubdivide(image, orientations, frequencies))
            else:
                image = GaborUtil.gaborFilter(image, orientations, frequencies)
            image = np.where(mask == 1.0, image, 1.0)

            image = np.where(mask == 1.0, Utils.binarize(image), 1.0)
        elif filter_type == 'wahab':
            image = np.where(mask == 1.0, Utils.binarize(image), 1.0)
        else:
            raise SyntaxError('filter type %s is not supported' % filter_type)

        misc.imsave(FingerprintIELib.FILE, image)
        return Image.open(FingerprintIELib.FILE)
Ejemplo n.º 3
0
    def gaborFilter(image, orientations, frequencies, w=32):
        result = np.empty(image.shape)

        height, width = image.shape
        for y in range(0, height - w, w):
            for x in range(0, width - w, w):
                orientation = orientations[y+w//2, x+w//2]
                frequency = Utils.average_frequency(frequencies[y:y + w, x:x + w])

                if frequency < 0.0:
                    result[y:y+w, x:x+w] = image[y:y+w, x:x+w]
                    continue

                kernel = GaborUtil.gaborKernel(16, orientation, frequency)
                result[y:y+w, x:x+w] = Utils.convolve(image, kernel, (y, x), (w, w))

        return Utils.normalize(result)
Ejemplo n.º 4
0
    def gaborFilterSubdivide(image, orientations, frequencies, rect=None):
        if rect:
            y, x, h, w = rect
        else:
            y, x = 0, 0
            h, w = image.shape

        result = np.empty((h, w))

        orientation, deviation = Utils.average_orientation(
            orientations[y:y+h, x:x+w], deviation=True)

        if (deviation < 0.2 and h < 50 and w < 50) or h < 6 or w < 6:
            frequency = Utils.average_frequency(frequencies[y:y + h, x:x + w])

            if frequency < 0.0:
                result = image[y:y+h, x:x+w]
            else:
                kernel = GaborUtil.gaborKernel(16, orientation, frequency)
                result = Utils.convolve(image, kernel, (y, x), (h, w))

        else:
            if h > w:
                hh = h // 2

                result[0:hh, 0:w] = \
                    GaborUtil.gaborFilterSubdivide(image, orientations, frequencies, (y, x, hh, w))

                result[hh:h, 0:w] = \
                    GaborUtil.gaborFilterSubdivide(image, orientations, frequencies, (y + hh, x, h - hh, w))
            else:
                hw = w // 2

                result[0:h, 0:hw] = \
                    GaborUtil.gaborFilterSubdivide(image, orientations, frequencies, (y, x, h, hw))

                result[0:h, hw:w] = \
                    GaborUtil.gaborFilterSubdivide(image, orientations, frequencies, (y, x + hw, h, w - hw))

        if w > 20 and h > 20:
            result = Utils.normalize(result)

        return result
Ejemplo n.º 5
0
    def wahab_filter(image, orientations, w=8):
        result = np.empty(image.shape)

        height, width = image.shape
        for y in range(0, height - w, w):
            for x in range(0, width - w, w):
                orientation = orientations[y + w // 2, x + w // 2]
                kernel = WahabUtil.wahab_kernel(16, orientation)
                result[y:y + w,
                       x:x + w] = Utils.convolve(image, kernel, (y, x), (w, w))
                result[y:y + w, x:x + w] /= np.sum(kernel)

        return result
Ejemplo n.º 6
0
    def orientations(img):
        img.save(FingerprintIELib.FILE)

        image = ndimage.imread(FingerprintIELib.FILE, mode="L").astype("float64")
        image = Utils.normalize(image)
        mask = Utils.find_mask(image)

        image = np.where(mask == 1.0, Utils.local_normalize(image), image)
        orientations = np.where(mask == 1.0, Utils.estimate_orientations(image), -1.0)
        Utils.show_orientations(image, orientations, "orientations", 8)

        plt.savefig(FingerprintIELib.FILE, bbox_inches='tight', pad_inches = 0)

        return Image.open(FingerprintIELib.FILE)
Ejemplo n.º 7
0
    def gaborKernel(size, angle, frequency):
        """
        Create a Gabor kernel given a size, angle and frequency.

        Code is taken from https://github.com/rtshadow/biometrics.git
        """

        angle += np.pi * 0.5
        cos = np.cos(angle)
        sin = -np.sin(angle)

        yangle = lambda x, y: x * cos + y * sin
        xangle = lambda x, y: -x * sin + y * cos

        xsigma = ysigma = 4

        return Utils.kernel_from_function(size, lambda x, y:
        np.exp(-(
                (xangle(x, y) ** 2) / (xsigma ** 2) +
                (yangle(x, y) ** 2) / (ysigma ** 2)) / 2) *
        np.cos(2 * np.pi * frequency * xangle(x, y)))