Пример #1
0
def fillImageSpace():
    N=512
    M=2*N
    centered = True

    ms = range(0, N)
    ss = range(0, N/2)

    powerSpect = np.zeros((M,M))
    fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(16, 8))
    ax[0].imshow(powerSpect)
    ax[1].imshow(powerSpect)
    fareyImage = np.zeros_like(powerSpect)

    maxLines = len(ms)
    for i,m in enumerate(ms):
        u, v = radon.getSliceCoordinates2(m, powerSpect, centered, M)
        ax[0].plot(u, v, '.r', markersize=1)
        u, v = radon.getSliceCoordinates2(M-m, powerSpect, centered, M)
        ax[0].plot(u, v, '.r', markersize=1)    
        #ax[1].plot(u, v, '.r',markersize=1)
        fareyImage[u,v] = 255
        if i == maxLines:
            break

    maxLines = len(ss)
    for i,s in enumerate(ss):
        u, v = radon.getSliceCoordinates2(s, powerSpect, centered, M)
        ax[0].plot(u, v, '.r', markersize=1)
        ax[1].plot(u, v, '.r',markersize=1)
        u, v = radon.getSliceCoordinates2(M-s, powerSpect, centered, M)
        ax[0].plot(u, v, '.r', markersize=1)
        ax[1].plot(u, v, '.r',markersize=1)
        fareyImage[u,v] = 255
        if i == maxLines:
            break

    plt.show()

    print("Non-zero elements without holes: ", np.count_nonzero(fareyImage)/float(M*M) * 100)

    return
Пример #2
0
def computeLines(kSpace, angles, centered=True, twoQuads=False):
    '''
    compute finite lines coordinates
    Returns a list or list of slice 2-tuples and corresponding list of m values
    '''
    p, s = kSpace.shape
    lines = []
    mValues = []
    for angle in angles:
        m, inv = farey.toFinite(angle, p)
        u, v = radon.getSliceCoordinates2(m, kSpace, centered, p)
        lines.append((u, v))
        mValues.append(m)
        #second quadrant
        if twoQuads:
            if m != 0 and m != p:  #dont repeat these
                m = p - m
                u, v = radon.getSliceCoordinates2(m, kSpace, centered, p)
                lines.append((u, v))
                mValues.append(m)

    return lines, mValues
Пример #3
0
def createFractal4(reduction, N, proportion):
    #parameters
    M = 2*N
    twoQuads = True
    angles, lengths = mojette.angleSet_Symmetric(N,N,1,True,50)
    perpAngle = farey.farey(1,0)
    angles.append(perpAngle)
    powerSpect = np.zeros((M,M))

    #compute lines
    centered = True
    mLines = []
    sLines = []
    mValues = []
    sValues = []
    pValues = []
    qValues = []
    for angle in angles:
        m, s, p, q, inv = farey.toFinite(angle, M)
        pValues.append(p)
        qValues.append(q)
        if m not in mValues and m < M:
            u, v = radon.getSliceCoordinates2(m, powerSpect, centered, M)
            mLines.append((u,v))
            mValues.append(m)
        
        #second quadrant
        if twoQuads:
            if m != 0 and m != M: #dont repeat these
                m = M-m
                if m not in mValues and m < M:
                    u, v = radon.getSliceCoordinates2(m, powerSpect, centered, M)
                    mLines.append((u,v))
                    mValues.append(m)
                    i = (len(mValues)+len(sValues))/float(M)
                    if i >= 1:
                        break

    ss = []
    ss.append(M)
    ss.extend(range(0, N/2))

    maxLines = len(ss)
    for i,s in enumerate(ss):
        u, v = radon.getSliceCoordinates2(s, powerSpect, centered, M)
        sLines.append((u,v))
        sValues.append(s)
        i = (len(mValues)+len(sValues))/float(M)
        if i >= 1.5:
            break

    length = 0

    fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(16, 8))

    plt.gray()
    plt.tight_layout()

    maxLines = len(sLines+mLines)
    i = 0
    ax[0].imshow(powerSpect)
    ax[1].imshow(powerSpect)
    color=iter(cm.jet(np.linspace(0,1,maxLines+1)))
    fareyImage = np.zeros_like(powerSpect)
    fareyImage1 = np.zeros_like(powerSpect)
    for i, sLine in enumerate(sLines):
        u, v = sLine
        ax[1].plot(u, v, '.w',markersize=1)
        fareyImage[u,v] = 1
        length = length + 1
        i = np.count_nonzero(fareyImage)/float((M*M))
        if i >= reduction*proportion:
            break

    maxLines = len(mLines)
    for i, mLine in enumerate(mLines):
        u, v = mLine
        ax[0].plot(u, v, '.r', markersize=1)
        ax[1].plot(u, v, '.r',markersize=1)
        fareyImage[u,v] = 1
        fareyImage1[u,v] = 1
        length = length + 1
        i = np.count_nonzero(fareyImage)/float((M*M))
        if i >= reduction:
            break

    print("Proportion of M:", (length/float(M)))

    print("Non-zero elements with holes: ", np.count_nonzero(fareyImage1)/float((M*M)) * 100)
    print("Non-zero elements without holes: ", np.count_nonzero(fareyImage)/float((M*M)) * 100)

    print("Absolute difference percentage extra filled in is ", (np.count_nonzero(fareyImage)- np.count_nonzero(fareyImage1))/float((M*M)) *100)

    withHoles = np.count_nonzero(fareyImage1)/float((M*M)) * 100
    withoutHoles = np.count_nonzero(fareyImage)/float((M*M)) * 100

    percentage = (withoutHoles - withHoles)/float(withHoles) * 100

    print("Percentage difference percentage extra filled in is ", percentage)
            
    ax[0].set_title('Sampling (colour per line) for dyadic size:'+str(M))
    ax[1].set_title('Sampling (same colour per line) for dyadic size:'+str(M))
    imageio.imsave("farey_image_"+str(M)+"_"+".png", fareyImage)
    plt.show()

    lines = mLines + sLines

    return fareyImage, lines
Пример #4
0
#np.set_printoptions(threshold=np.nan)

#compute lines
print("Computing Finite lines...")
centered = True
lines = []
mValues = []
pValues = []
qValues = []
z=25
for angle in angles:
    #m, inv = farey.toFinite(angle, p)
    #u, v = radon.getSliceCoordinates2(m, powerSpect, centered, p)
    m, p, q, inv = farey.toFinite(angle, M)
    u, v = radon.getSliceCoordinates2(m, powerSpect, centered, M)
    lines.append((u,v))
    mValues.append(m)
    pValues.append(p)
    qValues.append(q)
    
    #second quadrant
    if twoQuads:
        #if m != 0 and m != p: #dont repeat these
        if m != 0 and m != M: #dont repeat these
            #m = p-m
            #u, v = radon.getSliceCoordinates2(m, powerSpect, centered, p)
            m = M-m
            z = M-2*z
            u, v = radon.getSliceCoordinates2(m, powerSpect, centered, M)
            lines.append((u,v))
Пример #5
0
print("Number of Angles:", len(angles))
print("angles:", angles)

powerSpect = np.zeros((p, p))

#compute lines
print("Computing Finite lines...")
centered = True
lines = []
mValues = []
pValues = []
qValues = []

for angle in angles:
    m, p1, q, inv = farey.toFinite(angle, p)
    u, v = radon.getSliceCoordinates2(m, powerSpect, centered, p)
    lines.append((u, v))
    mValues.append(m)
    pValues.append(p1)
    qValues.append(q)
    #second quadrant
    if twoQuads:
        if m != 0 and m != p:  #dont repeat these
            m = p - m
            u, v = radon.getSliceCoordinates2(m, powerSpect, centered, p)
            lines.append((u, v))
            mValues.append(m)
mu = len(lines)
print("Number of lines:", len(lines))
print("Proportion of p:", len(lines) / float(p))
print("Proportion of 2D space:", 2.0 - len(lines) / float(p))
Пример #6
0
psnr = imageio.impsnr(lena, np.abs(reconLena))
print("Acutal RMSE:", math.sqrt(mse))
print("Acutal SSIM:", ssim)
print("Acutal PSNR:", psnr)

#compute lines
centered = True
subsetsLines = []
subsetsMValues = []
mu = 0
for angles in subsetsAngles:
    lines = []
    mValues = []
    for angle in angles:
        m, inv = farey.toFinite(angle, p)
        u, v = radon.getSliceCoordinates2(m, powSpectLena, centered, p)
        lines.append((u, v))
        mValues.append(m)
        #second quadrant
        if twoQuads:
            if m != 0 and m != p:  #dont repeat these
                m = p - m
                u, v = radon.getSliceCoordinates2(m, powSpectLena, centered, p)
                lines.append((u, v))
                mValues.append(m)
    subsetsLines.append(lines)
    subsetsMValues.append(mValues)
    mu += len(lines)
print("Number of lines:", mu)
print(subsetsMValues)