示例#1
0
    ax[0].plot(u, v, '.', c=c)
    ax[1].plot(u, v, '.r',markersize=1)
    fareyImage[u,v] = 255
    if i == maxLines:
        break
#ax[0].set_title('Sampling (colour per line) for prime size:'+str(p))
#ax[1].set_title('Sampling (same colour per line) for prime size:'+str(p))
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))
#ax[0].set_xlim([0,M])
#ax[0].set_ylim([0,M])
#ax[1].set_xlim([0,M])
#ax[1].set_ylim([0,M])

#imageio.imsave("farey_image_"+str(p)+"_"+str(K)+".png", fareyImage)
imageio.imsave("farey_image_"+str(M)+"_"+str(K)+".png", fareyImage)

plt.show()

fig,
plt.plot(pValues, qValues, 'ro')
plt.show()

fig,
plt.gca().invert_yaxis()
maxLines = len(mValues)
old_u = M/2
old_v = M/2
#maxLines = 12
#color=iter(cm.rainbow(np.linspace(0,1,len(lines))))
for i, mValues in enumerate(mValues):
示例#2
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
# -*- coding: utf-8 -*-
"""
Test Read PGM member
Created on Sun Jan 25 21:52:38 2015

@author: shakes
"""
import _libpath  #add custom libs
import finitetransform.imageio as imageio

saveImage = False
image, depth = imageio.readPGM("../data/lena512.pgm")
print "Image dtype:", image.dtype

if saveImage:
    imageio.imsave("../data/lena.png", image)

#Plot
import matplotlib.pyplot as plt

plt.gray()
plt.imshow(image)
plt.axis('off')
plt.title('Image')

plt.show()