Example #1
0
    def get_num_image(self, order_array_flat):
        '''
        This gennerates the image with information of how many times a pixel 
        was the best match.
        :param order_array_flat:
        '''

        order_image = Image.new(
            'L',
            np.flipud(self.shape) * np.flipud(self.neighbor_shape))

        max_E4 = np.max(order_array_flat)
        min_E4 = np.min(order_array_flat)

        for c in coords_iterate(self.shape):
            # find index in flat array
            k = self.estimator.flattening.cell2index[c]

            E3_local_flat = order_array_flat[k]
            E3_local_flat_normalized = 1 - (E3_local_flat - min_E4) / (max_E4 -
                                                                       min_E4)

            E3_local = E3_local_flat_normalized.reshape(self.neighbor_shape)

            # find the upper left corner to paste
            p0 = tuple(np.flipud(np.array(c) * self.neighbor_shape))
            # calculate the box to past into
            box = p0 + tuple(p0 + self.neighbor_shape)
            order_image.paste(
                Image.fromarray((E3_local * 255).astype('uint8')), box)
        return order_image
 def get_num_image(self, order_array_flat):
     '''
     This gennerates the image with information of how many times a pixel 
     was the best match.
     :param order_array_flat:
     '''
     
     order_image = Image.new('L', np.flipud(self.shape) * np.flipud(self.neighbor_shape))
     
     max_E4 = np.max(order_array_flat)
     min_E4 = np.min(order_array_flat)
     
     for c in coords_iterate(self.shape):
         # find index in flat array
         k = self.estimator.flattening.cell2index[c]
         
         E3_local_flat = order_array_flat[k]
         E3_local_flat_normalized = 1 - (E3_local_flat - min_E4) / (max_E4 - min_E4)
         
         E3_local = E3_local_flat_normalized.reshape(self.neighbor_shape)
         
         
         # find the upper left corner to paste
         p0 = tuple(np.flipud(np.array(c) * self.neighbor_shape))
         # calculate the box to past into
         box = p0 + tuple(p0 + self.neighbor_shape)
         order_image.paste(Image.fromarray((E3_local * 255).astype('uint8')), box)
     return order_image
Example #3
0
    def get_order_image(self, order_array_flat):
        '''
        This gennerates an image search_area*image_size with the order 
        array (E4 error) for each pixel.
        :param order_array_flat:
        '''
        order_image = Image.new(
            'L',
            np.flipud(self.shape) * np.flipud(self.neighbor_shape))

        max_E4 = np.max(order_array_flat)
        min_E4 = np.min(order_array_flat)

        for c in coords_iterate(self.shape):
            # find index in flat array
            k = self.estimator.flattening.cell2index[c]

            E4_local_flat = order_array_flat[k]
            '''
            Data is normalized such that 1 is no error and 0 is max error.
            This can easily be inverted by the commented line below
            '''
            E4_local_flat_normalized = 1 - (E4_local_flat - min_E4) / (max_E4 -
                                                                       min_E4)
            #            E4_local_flat_normalized = (E4_local_flat - min_E4) / (max_E4 - min_E4)

            E4_local = E4_local_flat_normalized.reshape(self.neighbor_shape)

            if c in c_peak_list:
                fig = plt.figure()
                ax = fig.gca(projection='3d')
                X, Y = np.meshgrid(range(self.neighbor_shape[0]),
                                   range(self.neighbor_shape[1]))
                ax.plot_surface(
                    X,
                    Y,
                    E4_local,
                    rstride=1,
                    cstride=1,
                    cmap=cm.jet,  #@UndefinedVariable
                    linewidth=0,
                    antialiased=False)
                if not os.path.exists(self.folder + self.name + '/peaks'):
                    os.makedirs(self.folder + self.name + '/peaks')
                plt.savefig(self.folder + self.name + '/peaks/order' + str(c) +
                            '.png')
                plt.savefig(self.folder + self.name + '/peaks/order' + str(c) +
                            '.pdf')

            # find the upper left corner to paste
            p0 = tuple(np.flipud(np.array(c) * self.neighbor_shape))
            # calculate the box to past into
            box = p0 + tuple(p0 + self.neighbor_shape)
            order_image.paste(
                Image.fromarray((E4_local * 255).astype('uint8')), box)
        return order_image
Example #4
0
    def get_similarity_image(self, sim_array):
        '''
        This gennerates a image with the simmilarity function E1 for each pixel.
        :param sim_array:
        '''

        sim_image = Image.new(
            'L',
            np.flipud(self.shape) * np.flipud(self.neighbor_shape))

        max_sim = np.max(sim_array)
        min_sim = np.min(sim_array)

        for c in coords_iterate(self.shape):
            # find index in flat array
            k = self.estimator.flattening.cell2index[c]

            sim_local_flat = sim_array[k]
            '''
            Data is normalized such that 1 is no error and 0 is max error.
            This can easily be inverted by the commented line below
            '''
            sim_local_flat_normalized = 1 - (sim_local_flat -
                                             min_sim) / (max_sim - min_sim)
            #            sim_local_flat_normalized = (sim_local_flat - min_sim) / (max_sim - min_sim)

            sim_local = sim_local_flat_normalized.reshape(self.neighbor_shape)

            if c in c_peak_list:
                fig = plt.figure()
                ax = fig.gca(projection='3d')
                X, Y = np.meshgrid(range(self.neighbor_shape[0]),
                                   range(self.neighbor_shape[1]))
                ax.plot_surface(
                    X,
                    Y,
                    sim_local,
                    rstride=1,
                    cstride=1,
                    cmap=cm.jet,  #@UndefinedVariable
                    linewidth=0,
                    antialiased=False)
                if not os.path.exists(self.folder + self.name + '/peaks'):
                    os.makedirs(self.folder + self.name + '/peaks')
                plt.savefig(self.folder + self.name + '/peaks/sim' + str(c) +
                            '.png')
                plt.savefig(self.folder + self.name + '/peaks/sim' + str(c) +
                            '.pdf')

            # find the upper left corner to paste
            p0 = tuple(np.flipud(np.array(c) * self.neighbor_shape))
            # calculate the box to past into
            box = p0 + tuple(p0 + self.neighbor_shape)
            sim_image.paste(Image.fromarray((sim_local * 255).astype('uint8')),
                            box)
        return sim_image
    def get_order_image(self, order_array_flat):
        '''
        This gennerates an image search_area*image_size with the order 
        array (E4 error) for each pixel.
        :param order_array_flat:
        '''
        order_image = Image.new('L', np.flipud(self.shape) * np.flipud(self.neighbor_shape))
        
        max_E4 = np.max(order_array_flat)
        min_E4 = np.min(order_array_flat)
        
        for c in coords_iterate(self.shape):
            # find index in flat array
            k = self.estimator.flattening.cell2index[c]
            
            E4_local_flat = order_array_flat[k]
            '''
            Data is normalized such that 1 is no error and 0 is max error.
            This can easily be inverted by the commented line below
            '''
            E4_local_flat_normalized = 1 - (E4_local_flat - min_E4) / (max_E4 - min_E4)
#            E4_local_flat_normalized = (E4_local_flat - min_E4) / (max_E4 - min_E4)
            
            E4_local = E4_local_flat_normalized.reshape(self.neighbor_shape)
            
            
            if c in c_peak_list:
                fig = plt.figure()
                ax = fig.gca(projection='3d')
                X, Y = np.meshgrid(range(self.neighbor_shape[0]), range(self.neighbor_shape[1]))
                ax.plot_surface(X, Y, E4_local, rstride=1, cstride=1, cmap=cm.jet, #@UndefinedVariable
                                       linewidth=0, antialiased=False)
                if not os.path.exists(self.folder + self.name + '/peaks'):
                    os.makedirs(self.folder + self.name + '/peaks')
                plt.savefig(self.folder + self.name + '/peaks/order' + str(c) + '.png')
                plt.savefig(self.folder + self.name + '/peaks/order' + str(c) + '.pdf')
            
            # find the upper left corner to paste
            p0 = tuple(np.flipud(np.array(c) * self.neighbor_shape))
            # calculate the box to past into
            box = p0 + tuple(p0 + self.neighbor_shape)
            order_image.paste(Image.fromarray((E4_local * 255).astype('uint8')), box)
        return order_image
    def get_similarity_image(self, sim_array):
        '''
        This gennerates a image with the simmilarity function E1 for each pixel.
        :param sim_array:
        '''
        
        sim_image = Image.new('L', np.flipud(self.shape) * np.flipud(self.neighbor_shape))
        
        max_sim = np.max(sim_array)
        min_sim = np.min(sim_array)

        for c in coords_iterate(self.shape):
            # find index in flat array
            k = self.estimator.flattening.cell2index[c]
            
            sim_local_flat = sim_array[k]
            '''
            Data is normalized such that 1 is no error and 0 is max error.
            This can easily be inverted by the commented line below
            '''
            sim_local_flat_normalized = 1 - (sim_local_flat - min_sim) / (max_sim - min_sim)
#            sim_local_flat_normalized = (sim_local_flat - min_sim) / (max_sim - min_sim)
            
            sim_local = sim_local_flat_normalized.reshape(self.neighbor_shape)
            
            if c in c_peak_list:
                fig = plt.figure()
                ax = fig.gca(projection='3d')
                X, Y = np.meshgrid(range(self.neighbor_shape[0]), range(self.neighbor_shape[1]))
                ax.plot_surface(X, Y, sim_local, rstride=1, cstride=1, cmap=cm.jet, #@UndefinedVariable
                                       linewidth=0, antialiased=False)
                if not os.path.exists(self.folder + self.name + '/peaks'):
                    os.makedirs(self.folder + self.name + '/peaks')
                plt.savefig(self.folder + self.name + '/peaks/sim' + str(c) + '.png')
                plt.savefig(self.folder + self.name + '/peaks/sim' + str(c) + '.pdf')
            
            # find the upper left corner to paste
            p0 = tuple(np.flipud(np.array(c) * self.neighbor_shape))
            # calculate the box to past into
            box = p0 + tuple(p0 + self.neighbor_shape)
            sim_image.paste(Image.fromarray((sim_local * 255).astype('uint8')), box)
        return sim_image
Example #7
0
def diffeo_from_function_viewport(diffeo, manifold, viewport, shape):
    domain = SquareDomain([[0, shape[0]], [0, shape[1]]])
    domain2viewport = LinearCoordinateChange(domain.bounds, viewport.bounds)
    viewport2domain = domain2viewport.get_inverse()
    # Prepare the grid
    M = shape[0]
    N = shape[1]
    D = np.zeros((M, N, 2), dtype='int32')
    # Uncertainty (here, 0 or 1)
    info = np.zeros((M, N), dtype='float32')
    # Iterate at each cell
    for coords in coords_iterate(shape):
        # coords = (i,j)
        # coordinates of the center of the cell
        center_offset = np.array([0.5, 0.5])
        cell_center = coords + center_offset
        # the domain is ([0,M]x[0,N]) so it is still inside
        assert domain.belongs(cell_center)
        # transform to the "world"
        world = domain2viewport(cell_center)
        # apply the diffeomorphism
        world2 = manifold.normalize(diffeo(world))
        # Are we inside the viewport?
        if viewport.belongs(world2):
            cell2 = viewport2domain(world2)
            assert domain.belongs(cell2)
            new_cell = np.floor(cell2)
            approx = np.linalg.norm(cell2 - (new_cell + center_offset))
            quality = np.exp(-approx)
            quality = 1
            info[coords[0], coords[1]] = quality
            D[coords[0], coords[1], 0] = new_cell[0]
            D[coords[0], coords[1], 1] = new_cell[1]
        else:
            # we don't know
            info[coords[0], coords[1]] = 0
            # we put the identity as a dummy value
            D[coords[0], coords[1], 0] = coords[0]
            D[coords[0], coords[1], 1] = coords[1]
    return D, info
Example #8
0
def diffeo_from_function_viewport(diffeo, manifold, viewport, shape):
    domain = SquareDomain([[0, shape[0]], [0, shape[1]]]) 
    domain2viewport = LinearCoordinateChange(domain.bounds, viewport.bounds)
    viewport2domain = domain2viewport.get_inverse()
    # Prepare the grid
    M = shape[0]
    N = shape[1]
    D = np.zeros((M, N, 2), dtype='int32')
    # Uncertainty (here, 0 or 1)
    info = np.zeros((M, N), dtype='float32')
    # Iterate at each cell
    for coords in coords_iterate(shape):
        # coords = (i,j)
        # coordinates of the center of the cell
        center_offset = np.array([0.5, 0.5])
        cell_center = coords + center_offset
        # the domain is ([0,M]x[0,N]) so it is still inside
        assert domain.belongs(cell_center)
        # transform to the "world"
        world = domain2viewport(cell_center)
        # apply the diffeomorphism
        world2 = manifold.normalize(diffeo(world)) 
        # Are we inside the viewport?
        if viewport.belongs(world2):
            cell2 = viewport2domain(world2)
            assert domain.belongs(cell2)
            new_cell = np.floor(cell2)
            approx = np.linalg.norm(cell2 - (new_cell + center_offset))
            quality = np.exp(-approx)
            quality = 1
            info[coords[0], coords[1]] = quality
            D[coords[0], coords[1], 0] = new_cell[0]
            D[coords[0], coords[1], 1] = new_cell[1]
        else:
            # we don't know
            info[coords[0], coords[1]] = 0
            # we put the identity as a dummy value
            D[coords[0], coords[1], 0] = coords[0]
            D[coords[0], coords[1], 1] = coords[1]
    return D, info