コード例 #1
0
ファイル: layout.py プロジェクト: trtz/jackal
 def unzigzag(self):
     with open('zz.dat', 'rb') as f:
         new_data = pickle.load(f)
         res = un_zig_zag(new_data, 512)
         res1 = [[0 for j in range(512)] for i in range(512)]
         for i in range(512):
             for j in range(512):
                 res1[i][j] = res[j][i]
         save_arr_to_right(res1)
         self.update_img(False)
コード例 #2
0
def gla1(image_location, colors):
    image = cv2.imread(image_location, cv2.IMREAD_COLOR)
    image_height = len(image)
    image_width = len(image[0])
    block_width = 1
    block_height = 1
    vector_dimension = block_width * block_height

    codebook_size = colors
    perturbation_vector = np.full(vector_dimension, 10)

    image_vectors = []
    for i in range(0, image_width):
        for j in range(0, image_height):
            image_vectors.append(image[i, j])
    image_vectors = np.asarray(image_vectors).astype(float)

    centroid_vector = np.mean(image_vectors, axis=0)
    centroids = np.vstack(
        (centroid_vector, np.add(centroid_vector, perturbation_vector)))
    reconstruction_values, distortion = kmeans(image_vectors, centroids)

    for i in range(0, int(log(codebook_size / 2, 2)), 1):
        reconstruction_values = get_centroids(reconstruction_values,
                                              perturbation_vector)
        reconstruction_values, distortion = kmeans(image_vectors,
                                                   reconstruction_values, 1)

    print('reconstruction values finished')

    image_vector_indices, distance = vq(image_vectors, reconstruction_values)

    image_after_compression = np.zeros([image_width, image_height],
                                       dtype="uint8")
    res = [[[] for i in range(512)] for j in range(512)]
    for index, image_vector in enumerate(image_vectors):
        start_row = int(index / (image_width / block_width)) * block_height
        end_row = start_row + block_height
        start_column = (index * block_width) % image_width
        end_column = start_column + block_width
        b, g, r = list(reconstruction_values[image_vector_indices[index]])
        res[start_row][start_column] = [r, g, b]
    output_image_name = RIGHT
    save_arr_to_right(res)
コード例 #3
0
ファイル: layout.py プロジェクト: trtz/jackal
 def ycbcr(self, mode):
     res = ycbcr1(LEFT)
     curr = [[int(res[j][i][mode]) for i in range(512)] for j in range(512)]
     save_arr_to_right(curr)
     self.update_img(False)
コード例 #4
0
ファイル: layout.py プロジェクト: trtz/jackal
 def urgb442_(self):
     img = Image.open(LEFT).load()
     img1 = urgb442_(img)
     save_arr_to_right(img1)
     self.update_img(False)
コード例 #5
0
ファイル: layout.py プロジェクト: trtz/jackal
 def ycbcrq(self, x, y, z):
     img = Image.open(LEFT).load()
     img1 = ycbcrq_(img, x, y, z)
     save_arr_to_right(img1)
     self.update_img(False)
コード例 #6
0
ファイル: layout.py プロジェクト: trtz/jackal
 def mcut_(self):
     res = median_cut(LEFT, 256)
     save_arr_to_right(res)
     self.update_img(False)