Пример #1
0
def random_equi_rotation(image, gt_image):
    yaw = 2 * np.pi * random.random()
    roll = 2 * np.pi * (random.random() - 0.5) * 0.1
    pitch = 2 * np.pi * (random.random() - 0.5) * 0.1

    rotation_angles = np.array([yaw, roll, pitch])
    image_res = np.zeros(image.shape)
    gtimage_res = np.zeros(gt_image.shape)

    extractEquirectangular_quick(
        True, image, image_res, Algebra.rotation_matrix(rotation_angles))

    extractEquirectangular_quick(
        True, gt_image, gtimage_res, Algebra.rotation_matrix(rotation_angles))

    gtimage_res = (gtimage_res + 0.1).astype(np.int32)

    if DEBUG:
        if not np.all(np.unique(gtimage_res) == np.unique(gt_image)):
            logging.warning("np.unique(gt_image    ) {}".format(
                np.unique(gt_image)))
            logging.warning("np.unique(gt_image_res) {}".format(
                np.unique(gtimage_res)))

            for i in np.unique(gtimage_res):
                if i == 255:
                    continue
                else:
                    if i not in np.unique(gt_image):
                        logging.error("Equirectangular removed classes.")
                    assert i in np.unique(gt_image)

    return image_res, gtimage_res
Пример #2
0
def make_q(new_quest):
    """ need a new question, make one """
    if new_quest:
        x_alg = Algebra()
        x_alg.make_question()
        session['_alg_obj']=pickle.dumps(x_alg,-1)
    else:
        x_alg = pickle.loads(session['_alg_obj'])

    if x_alg.variable['q_type'] == 1:
        syslog.syslog(
            "Algebra: New simultaneous equations { Q1: %s, Q2: %s, X = %s, Y = %s } from %s" % (
                x_alg.variable['disp1'],
                x_alg.variable['disp2'],
                x_alg.variable['x'],
                x_alg.variable['y'],
                request.environ['REMOTE_ADDR']
               )
        )
        syslog.syslog("Q1: %s" % (x_alg.variable['disp1']))
        syslog.syslog("Q2: %s" % (x_alg.variable['disp2']))
        syslog.syslog("X: %s" % (x_alg.variable['x']))
        syslog.syslog("Y: %s" % (x_alg.variable['y']))
    elif x_alg.variable['q_type'] == 2:
        syslog.syslog(
            "Algebra: New expand / simplify { Q: %s, X^2 = %s, XY = %s, Y^2 = %s } from %s" % (
                x_alg.variable['exp_question'],
                x_alg.variable['x_squared'],
                x_alg.variable['x_y'],
                x_alg.variable['y_squared'],
                request.environ['REMOTE_ADDR']
              )
        )
        syslog.syslog("Q: %s" % (x_alg.variable['exp_question']))
        syslog.syslog("X^2: %s" % (x_alg.variable['x_squared']))
        syslog.syslog("XY: %s" % (x_alg.variable['x_y']))
        syslog.syslog("Y^2: %s" % (x_alg.variable['y_squared']))
    elif x_alg.variable['q_type'] == 3:
        syslog.syslog(
            "Algebra: New heron { (%d,%d,%d), p = %f, A = %s } from %s" % (
                x_alg.variable['side'][0],
                x_alg.variable['side'][1],
                x_alg.variable['side'][2],
                x_alg.variable['perm'],
                x_alg.variable['heron'],
                request.environ['REMOTE_ADDR']
            )
        )

    return x_alg
Пример #3
0
def extractEquirectangular_quick(wrap, source_image, result_image, R):

    # First dimension: Yaw
    # First dimension: Roll
    # Third dimenstion: Pitch

    Algebra.test_polar_to_polar()
    min_theta = np.pi * 4
    max_theta = -np.pi * 4
    min_psi = np.pi * 4
    max_psi = -np.pi * 4

    result_image[:, :, 0] = 255
    width = result_image.shape[1]
    height = result_image.shape[0]

    row, col = np.mgrid[0:height, 0:width]
    polar_point = np.zeros((height, width, 3))
    polar_point[:, :, 0] = 1.0
    polar_point[:, :, 1] = (row / (1.0 * height)) * np.pi
    polar_point[:, :, 2] = ((col - width // 2) / (0.5 * width)) * np.pi

    max_1 = np.max(np.max(polar_point[:, :, 1]))
    min_1 = np.min(np.min(polar_point[:, :, 1]))
    abs_max_2 = np.max(np.max(np.abs(polar_point[:, :, 2])))

    #print('max 1 min 1 absmax2 ' +str(max_1)+ ' '+str(min_1)+' ' +str(abs_max_2))
    #assert(max_1 <= np.pi) and(min_1>=0)and(abs_max_2<=np.pi) #disabled for speed

    plane_point = Algebra.polar_to_cartesian_array(polar_point)

    # assert( np.max(np.max(np.abs(Algebra.magnitude_array(plane_point)-polar_point[:,:,0]))) < 0.0001) #disabled for speed

    plane_rot = Algebra.rotate_array(R, plane_point)

    #assert(np.max(np.max(np.abs(Algebra.magnitude_array(plane_point) - Algebra.magnitude_array(plane_rot)))) < 0.0001) #disbled for speed

    eq_row, eq_col = Algebra.cartesian_to_polar_quantised_array(
        wrap, plane_rot, width, height)

    #assert ((np.min(np.min(eq_row))>=0) and (np.max(np.max(eq_row))<height)and (np.min(np.min(eq_col))>=0)  and (np.max(np.max(eq_row))<width)) #disabled for speed

    result_image[row, col, :] = source_image[eq_row, eq_col, :]
Пример #4
0
from algebra import Algebra
from node import Kind


def isConnected(const, term):
    for i in range(len(term.data)):
        if term.data[i] == const.data[i]:
            return True

    return False


pos_data = ["1100", "0011"]
neg_data = ["1010", "1000", "0010", "0101"]
constants = ["0---", "-0--", "--0-", "---0", "1---", "-1--", "--1-", "---1"]

algebra = Algebra()
algebra.insert_data(pos_data, neg_data, constants, isConnected)
algebra.mini_preprocessing_step()

algebra.enforce_negative_trace_constraints()
algebra.enforce_positive_trace_constraints()

print("all done")
Пример #5
0
def extractEquirectangular(wrap, source_image, result_image, euler_angles):
    extractEquirectangular_quick(wrap, source_image, result_image,
                                 Algebra.rotation_matrix(euler_angles))