예제 #1
0
def phase_congruency(im,
                     N,
                     w,
                     sigma,
                     scales,
                     scale_factor=2,
                     model=None,
                     model_factor=1):
    plt.matshow(im)
    plt.show()
    if np.ndim(im) > 2:
        im = skc.rgb2gray(im)
    ch = np.zeros(im.shape + (2 * N + 1, scales), dtype=np.complex)

    for i in range(scales):
        spectrum = log_gabor_spectrum(im.shape[:2],
                                      w * scale_factor**i,
                                      sigma,
                                      passband='band')
        ch_i = img_chv(im, spectrum, N)
        if model is not None:
            _, ch_i, _ = create_poly(ch_i, model)
            # print(ch_i[:,400, 400, :])
            ch_i = ch_i[0] + 1j * ch_i[1]
            # print(ch_i[400,400,:])
            # ch_i = ch_i[:, :, ::model_factor]
        ch[:, :, :, i] = ch_i
        # plt.matshow(chv_norm(ch[:, :, :, i]))
        # plt.show()
    A1 = np.linalg.norm(np.sum(ch, axis=-1), axis=-1)
    A2 = np.sum(np.linalg.norm(ch, axis=-2).squeeze(), axis=-1)
    # plt.matshow(A1)
    # plt.colorbar()
    # plt.show()
    # plt.matshow(A2)
    # plt.colorbar()
    # plt.show()

    epsilon = 0.01
    plt.matshow(A1 / (A2 + epsilon))
    plt.colorbar()
    plt.show()

    plt.matshow(beta.cdf(A1 / (A2 + epsilon), 5, 1))
    plt.colorbar()
    plt.show()

    return A1 / (A2 + epsilon)
예제 #2
0
def scale(im, N, w, sigma, scales, scale_factor=2):
    if np.ndim(im) > 2:
        im = skc.rgb2gray(im)
    ch = np.zeros(im.shape + (2 * N + 1, scales), dtype=np.complex)

    A = []
    for i in range(scales):
        spectrum = log_gabor_spectrum(im.shape[:2],
                                      w * scale_factor**i,
                                      sigma,
                                      passband='band')
        ch_i = img_chv(im, spectrum, N)
        A.append(chv_norm(ch_i))
    A = np.asarray(A)

    return np.max(A, axis=0), np.argmax(A, axis=0)
    sigma = 0.65
    # CH vector weights
    weightV = weights.sinusoid_weights(N, 0, 0)
    print("Weights are: ")
    print(weightV.transpose())
    # CH vector output array
    ch = np.zeros(ch_shape, dtype=np.complex)
    # Calculate
    for i, w in enumerate(wavelengths):
        print("Calculating CH vector for wavelength {}".format(w))
        if i == 0:
            passband = 'high'
        else:
            passband = 'band'
        gf = log_gabor_spectrum(im.shape, w, sigma)
        ch[i] = chv.img_chv(im, gf, N, weightV)

    # Calculate model parameters
    # Model vectors
    U = sinusoid_pair(N, weightV)

    # Test
    # cht = U[1]
    # cht = cht[np.newaxis, np.newaxis, :]
    # poly, delt, lamb = create_poly(cht, U)
    # poly = poly[:, :, ::2]
    # roots = poly_roots(poly)
    # th = np.angle(roots)
    # val_at_roots = poly_value(poly, th)
    # max_idx = np.argmax(val_at_roots, axis=2)
    # th_max = np.take_along_axis(th, max_idx[:, :, np.newaxis], axis=2)
예제 #4
0
import skimage.io as skio
import skimage.color as skcolor
import matplotlib.pyplot as plt
import colorcet as cc

import chvector.transforms.chv as chv
from chvector.filters import log_gabor_spectrum
from chvector.models.archetypes import *
from chvector.models.solver import *

s = sinusoid_pair(7)
print(s)

im = skcolor.rgb2gray(skio.imread("COB3-orig.png"))
skio.imshow(im)
plt.show()
plt.pause(0)

gf = log_gabor_spectrum(im.shape[:2], 4, 0.5)
ch = chv.img_chv(im, gf, 7)

poly = create_poly(ch, s)

mag = np.linalg.norm(ch, axis=2)
plt.imshow(np.log(mag), cmap=cc.cm.fire)
plt.show()
plt.pause(0)
    sigma = 0.65
    # CH vector weights
    wv = weights.sinusoid_weights(N, 0, 0)
    print("Weights are: ")
    print(wv.transpose())
    # CH vector output array
    ch = np.zeros(im.shape + (2 * N + 1, len(wavelengths)), dtype=np.complex)
    # Calculate
    for i, w in enumerate(wavelengths):
        print("Calculating CH vector for wavelength {}".format(w))
        if i == 0:
            passband = 'high'
        else:
            passband = 'band'
        gf = log_gabor_spectrum(im.shape, w, sigma)
        ch[:, :, :, i] = chv.img_chv(im, gf, N, wv)

    # Calculate model parameters
    # Model vectors
    U = sinusoid_pair(N, w)
    # Model output array
    A_model = np.zeros(im.shape + (len(wavelengths), ))
    phi_model = np.zeros(im.shape + (len(wavelengths), ))
    theta_model = np.zeros(im.shape + (len(wavelengths), ))
    # Calculate
    for i in range(ch.shape[3]):
        # Create response polynomials
        poly, lamb, delt = create_poly(ch[:, :, :, i], U)
        # Solve for maximum
        # Sinusoid has poly order of 2
        poly = poly[:, :, ::2]