Exemplo n.º 1
0
def E_step(number_of_image, priblijenie, weigths):
    #print("process {}".format(number_of_image))
    #print('calculating log(L) for {} picture'.format(number_of_image))
    #REF = priblijenie
    IMG = np.array(Image.open('img{}.png'.format(number_of_image)))

    step = np.zeros(number_of_angles)
    for i in range(number_of_angles):
        angle = i * term
        #print('angle = {}'.format(angle))
        #REF = ndimage.rotate(priblijenie, angle, reshape=False)

        #REF = np.rot90(priblijenie, -i)#при +i вертит против часовой
        REF = polar_rotate(priblijenie, -angle)

        #log_L = 0
        #for x in range(REF.shape[0]):
        #    for y in range(REF.shape[1]):
        #        log_L -= (int(IMG[x, y]) - int(REF[x, y])) ** 2/(2*sigma**2)

        a = (REF.astype(int) - IMG.astype(int)) ** 2/(2*sigma**2)
        log_L = -a.sum()
        step[i] = log_L
    vector, SUM = WeightsG(step,weigths)
    return vector, SUM
Exemplo n.º 2
0
def M_step_Matrix_calc(vect, number_of_img, a):
    IMG_arr = np.array(Image.open(way_to_img.format(number_of_img)))

    argmax = vect.argmax()
    new_vect = np.roll(vect, -argmax)
    matrix = np.zeros(a)
    for i in range(number_of_angles):
        angle = term * (i + argmax)
        IMG = polar_rotate(IMG_arr, angle)
        matrix[i] = IMG
    matrix = matrix * np.float64(
        new_vect[:, None, None])  #multiply by g_ij     IMG* * g_ij
    divider = (matrix != 0).astype(int)  # true\false to 1\0

    return matrix, divider
Exemplo n.º 3
0
def E_step(number_of_image, priblijenie, weigths):
    #print('calculating log(L) for {} picture'.format(number_of_image))
    IMG = np.array(Image.open(way_to_img.format(number_of_image)))
    step = np.zeros(number_of_angles)
    for i in range(number_of_angles):
        angle = i * term
        REF = polar_rotate(priblijenie, -angle)
        step[i] = LogL(REF, IMG)
    #print(step)
    vector, SUM = WeightsG(step, weigths)
    #if number_of_image==3:
    #    print(weigths)
    #    print("{} IMG:".format(number_of_image), vector)
    #   print(SUM)

    return vector, SUM
Exemplo n.º 4
0
def Generate1(arr, Num):

    #angle = int(90*np.random.randint(3))           #Loses values on edjes of pic
    #rotated_arr = ndimage.rotate(arr, angle, reshape=False)

    arr = put_normal_distribution(arr)
    arr = Del_pixels1(arr, del_percent)

    angle = np.random.randint(number_of_angles)*term
    polar_arr = reproject_image_into_polar(arr, 100, 100)
    rotated_arr = polar_rotate(polar_arr, angle)
    im = Image.fromarray(rotated_arr)
    if im.mode != 'L':
        im = im.convert('L')
    im.save(way_to_img.format(Num))
    print("saved img{}.png".format(Num))

    return 1
Exemplo n.º 5
0
def M_step(number_of_image,vector,weights):
    #print('calculating pixels for {} picture {}'.format(number_of_image,vector))
    #IMG = np.array(Image.open('rot{}.png'.format(number_of_image)).convert('RGB'))

    IMG_arr = np.array(Image.open('img{}.png'.format(number_of_image)))
    priblij = np.zeros(IMG_arr.shape)

    for i in range(number_of_angles):
        angle = i * term
        #print('angle = {}'.format(angle))
        #REF = ndimage.rotate(IMG, -angle, reshape=False)
        IMG = polar_rotate(IMG_arr, angle)
        a = np.float64(vector[i]/weights[i])
        priblij += a * IMG
        #print(f"{vector[i]} * {REF[55,55]} = {priblij[55,55]}")
    #plt.imshow(priblij)
    #plt.show()
    return priblij