Beispiel #1
0
def draw_curve(ax, num_bits):

    # The maximum Hilbert integer.
    max_h = 2**(num_bits * num_dims)

    # Generate a sequence of Hilbert integers.
    hilberts = np.arange(max_h)

    # Compute the 2-dimensional locations.
    locs = decode(hilberts, num_dims, num_bits)
    locs = locs + 0.5

    # Draw
    ax.plot(locs[:, 0], locs[:, 1], '.-')
    ax.set_xlim([0, pow(2, num_bits)])
    ax.set_ylim([0, pow(2, num_bits)])
    if (num_bits % 2) == 0:
        ax.set_xticks(range(0, pow(2, num_bits) + 1, num_bits))
        ax.set_yticks(range(0, pow(2, num_bits) + 1, num_bits))
    else:
        ax.set_xticks(range(0, pow(2, num_bits) + 1, num_bits - 1))
        ax.set_yticks(range(0, pow(2, num_bits) + 1, num_bits - 1))
    ax.set_aspect('equal')
    ax.set_title('%d bits per dimension' % (num_bits), fontdict={'size': 16})
    ax.set_xlabel('xlabel', fontdict={'size': 16})
    ax.set_ylabel('ylabel', fontdict={'size': 16})
    def _hcv_weight_init(self, num_dims):
        max_hilberts = np.arange(self._m * self._n)
        hilbert_vectors = decode(max_hilberts, self._dim, num_dims)
        scaler = MinMaxScaler()
        hilbert_vectors = scaler.fit_transform(hilbert_vectors)
        weights_tensor = tf.Variable(hilbert_vectors, dtype=tf.float32)

        return weights_tensor
Beispiel #3
0
def hilbertGenerate(num_bits, num_dims):
    # The maximum Hilbert integer.
    max_h = 2**(num_bits * num_dims)

    # Generate a sequence of Hilbert integers.
    hilberts = np.arange(max_h)

    # Compute the 2-dimensional locations.
    locs = decode(hilberts, num_dims, num_bits)
    return locs
Beispiel #4
0
def draw_curve(ax, num_bits):

  # The maximum Hilbert integer.
  max_h = 2**(num_bits*num_dims)

  # Generate a sequence of Hilbert integers.
  hilberts = np.arange(max_h)

  # Compute the 2-dimensional locations.
  locs = decode(hilberts, num_dims, num_bits)

  # Draw
  ax.plot(locs[:,0], locs[:,1], '.-')
  ax.set_aspect('equal')
  ax.set_title('%d bits per dimension' % (num_bits))
  ax.set_xlabel('dim 1')
  ax.set_ylabel('dim 2')
def hilbert_compression(array):
    """ Takes an array, perform wavelet transform, do hilbert scan and return coefficients """
    output = np.zeros((array.shape[0] * 2, array.shape[1], 3))
    print("Performing integer wavelet and hilbert scan on each channel...")

    for i in range(3):
        band = array[:, :, i]
        # Perform IWT on array
        coefficients = wavelet.iwt2(band)
        coefficients = coefficients[:band.shape[0], :band.shape[1]]
        # Perform Hilbert scan on coefficients
        hb = hilbert.decode(coefficients, 2, 5)

        hb = hb.reshape(output[:, :, i].shape)
        output[:, :, i] = hb

    return output
from mpl_toolkits.mplot3d import Axes3D

from hilbert import decode

num_bits = 5
num_dims = 3

# The maximum Hilbert integer.
max_h = 2**(num_bits*num_dims)

# Generate a sequence of Hilbert integers.
hilberts = np.arange(max_h)

# Compute the 3-dimensional locations.
locs = decode(hilberts, num_dims, num_bits)

# Draw
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111, projection='3d')

# Choose pretty colors.
cmap = matplotlib.cm.get_cmap('copper')

# Draw. This may be a little slow.
for ii in range(max_h-1):
  print(ii, max_h)
  ax.plot([locs[ii,0], locs[ii+1,0]],
          [locs[ii,1], locs[ii+1,1]],
          [locs[ii,2], locs[ii+1,2]],
          '-', color=cmap(ii/max_h))
Beispiel #7
0
        return torch.tensor(to_distanceTransform2(srcs)).float()
    elif label == 'avg':
        return torch.tensor(to_avg(srcs)).float()
    elif "gauss" in label:
        sigma = float(label.split('-')[-1])
        return torch.tensor(to_gauss(srcs, sigma)).float()
    elif label == "hilbert":
        return torch.tensor(to_hilbert(srcs)).float()
    else:
        print(f"Prec not found: |{label}|, try: ske, dt, gauss-1.5")


# WIP
max_h = 2**(2 * 8)
hilberts = np.arange(max_h)
hilbert_loc = decode(hilberts, 2, 8)


def get_hilbert_curve(src, num_bits=8, verbose=False, num_dims=2):

    dim = src.shape[0]
    dst = np.zeros((dim, dim))

    ravel = []
    for pts in hilbert_loc:
        ravel.append(src[pts[1], pts[0]])
    ravel = np.array(ravel)

    for idy in range(dim):
        for idx in range(dim):
            index = idx + (idy * dim)
from PIL import Image
import math
#============================== Uploading the image
im = Image.open('roomie.jpg')  # Can be many different formats.
pix = im.load()
imwidth, imheight = im.size
#print(pix[0,0])  # Get the RGBA Value of the a pixel of an image

#============================== Getting the curve
squaresize = 8  #side of the square in bits
bits = 2 * squaresize - 1
array = np.array(list(range(1, (2**(bits + 1)))))
# Turn an ndarray of Hilber integers into locations.
# first no. is the number of dimensions, second is the number of bits per dimension
#print(array)
locs = decode(array, 2, bits)
points = list(locs)
#print(points)
xpoints = [points[k][0] for k in range(len(points))]
ypoints = [points[k][1] for k in range(len(points))]
#scale the coordinates so we get the entire image in colour
#also adjust so final image isn't upside down
xpix = [
    imwidth - 1 - math.floor(xpoints[k] * imwidth / (2**squaresize))
    for k in range(len(xpoints))
]
ypix = [
    imheight - 1 - math.floor(ypoints[k] * imheight / (2**squaresize))
    for k in range(len(ypoints))
]
#print(ypix)