def questions1_6():
    path_wheel = "../resource/wheele.pgm"

# Question 1.1
    img = read_pgm(path_wheel)
    (width, height) = img.shape
    display_image(img, True)

# Question 1.2
    ft2d    = fft2(img)
    sum     = sum_pixels(img)
    freqSol = solve_discret_equation_FT(ft2d, sum)

# Question 1.3
    spectrum_2D = power_spectrum_2D(ft2d)
    display_image(spectrum_2D, vmin=min(spectrum_2D.flatten()), vmax=max(spectrum_2D.flatten()), xlabel='u (frequency)', ylabel='v (frequency)')

# Question 1.4
    ft2d_shifted        = fftshift(ft2d)
    spectrum_shifted_2D = power_spectrum_2D(ft2d_shifted)
    img_size = img.shape[0] * img.shape[1]
    display_image(spectrum_shifted_2D,
                  vmin=min(spectrum_shifted_2D.flatten()),
                  vmax=max(spectrum_shifted_2D.flatten()),
                  extent=[- height / 2 + 1, height / 2 + 1, - width / 2 + 1, width / 2 + 1])


# Question 1.6
    img_computed = ifft2(ft2d)
    img_computed = img_computed.astype(int)
    display_image(img_computed, True)
Ejemplo n.º 2
0
def pfft(f, nR = -1):
	if(nR < 0):
		nR = int(round(sqrt(2.) * norm(f.shape) + 1))
	tf = f
	if(norm(f.shape) < nR):
		tf = cpad(f, array([nR, nR]))
	return rect2polar(ifftshift(fft2(ifftshift(tf))), nR)
Ejemplo n.º 3
0
def questions1_6():
    path_wheel = "../resource/wheele.pgm"

    # Question 1.1
    img = read_pgm(path_wheel)
    (width, height) = img.shape
    display_image(img)

    # Question 1.2
    ft2d = fft2(img)
    sum = sum_pixels(img)
    freqSol = solve_discret_equation_FT(ft2d, sum)

    # Question 1.3

    # there is the first version of the answer
    # epsilon         = np.finfo(float).eps
    # axis            = np.array(range(0, width * height))
    # spectrum        = power_spectrum(ft2d)
    # display_plot(axis, spectrum,
    #              xlabel='Fourier domain\'s index (= x + y*width)',
    #              ylabel='log(modulus(ft(x, y))^2)',
    #              limits=[0, width * height, min(spectrum), max(spectrum)])

    # here what i think is right (another version)
    spectrum_2D = power_spectrum_2D(ft2d)
    display_image(spectrum_2D,
                  vmin=min(spectrum_2D.flatten()),
                  vmax=max(spectrum_2D.flatten()))

    # Question 1.4

    # there is the first version of the answer
    # ft2d_shifted = fftshift(ft2d)
    # spectrum_shifted = power_spectrum(ft2d_shifted)
    # axis = np.array(range(- width*height / 2 + 1, width * height / 2 + 1))
    # display_plot(axis, spectrum_shifted,
    #              xlabel='Fourier domain\'s index (= x + y*width)',
    #              ylabel='log(modulus(ft(x, y))^2)',
    #              limits=[- width * height / 2, width * height / 2 + 2, min(spectrum), max(spectrum)])

    # here what i think is right (another version)
    ft2d_shifted = fftshift(ft2d)
    spectrum_shifted_2D = power_spectrum_2D(ft2d_shifted)
    img_size = img.shape[0] * img.shape[1]
    display_image(spectrum_shifted_2D,
                  vmin=min(spectrum_shifted_2D.flatten()),
                  vmax=max(spectrum_shifted_2D.flatten()),
                  extent=[
                      -height / 2 + 1, height / 2 + 1, -width / 2 + 1,
                      width / 2 + 1
                  ])

    # Question 1.6
    img_computed = ifft2(ft2d_shifted)
    img_computed = img_computed.astype(int)
    display_image(img_computed)
def questions1_6():
    path_wheel = "../resource/wheele.pgm"

# Question 1.1
    img = read_pgm(path_wheel)
    (width, height) = img.shape
    display_image(img)

# Question 1.2
    ft2d    = fft2(img)
    sum     = sum_pixels(img)
    freqSol = solve_discret_equation_FT(ft2d, sum)
    
# Question 1.3

# there is the first version of the answer
    # epsilon         = np.finfo(float).eps
    # axis            = np.array(range(0, width * height))
    # spectrum        = power_spectrum(ft2d)
    # display_plot(axis, spectrum,
    #              xlabel='Fourier domain\'s index (= x + y*width)',
    #              ylabel='log(modulus(ft(x, y))^2)',
    #              limits=[0, width * height, min(spectrum), max(spectrum)])

# here what i think is right (another version)
    spectrum_2D = power_spectrum_2D(ft2d)
    display_image(spectrum_2D, vmin=min(spectrum_2D.flatten()), vmax=max(spectrum_2D.flatten()))

# Question 1.4

# there is the first version of the answer
    # ft2d_shifted = fftshift(ft2d)
    # spectrum_shifted = power_spectrum(ft2d_shifted)
    # axis = np.array(range(- width*height / 2 + 1, width * height / 2 + 1))
    # display_plot(axis, spectrum_shifted,
    #              xlabel='Fourier domain\'s index (= x + y*width)',
    #              ylabel='log(modulus(ft(x, y))^2)',
    #              limits=[- width * height / 2, width * height / 2 + 2, min(spectrum), max(spectrum)])

# here what i think is right (another version)
    ft2d_shifted = fftshift(ft2d)
    spectrum_shifted_2D = power_spectrum_2D(ft2d_shifted)
    img_size = img.shape[0] * img.shape[1]
    display_image(spectrum_shifted_2D,
                  vmin=min(spectrum_shifted_2D.flatten()),
                  vmax=max(spectrum_shifted_2D.flatten()),
                  extent=[- height / 2 + 1, height / 2 + 1, - width / 2 + 1, width / 2 + 1])


# Question 1.6
    img_computed = ifft2(ft2d_shifted)
    img_computed = img_computed.astype(int)
    display_image(img_computed)
Ejemplo n.º 5
0
def questions1_6():
    path_wheel = "../resource/wheele.pgm"

    # Question 1.1
    img = read_pgm(path_wheel)
    (width, height) = img.shape
    #   display_image(img, True)

    # Question 1.2
    ft2d = fft2(img)
    sum = sum_pixels(img)
    freqSol = solve_discret_equation_FT(ft2d, sum)

    # Question 1.3
    spectrum_2D = power_spectrum_2D(ft2d)
    #    display_image(
    #                  spectrum_2D,
    #                  vmin  = min(spectrum_2D.flatten()),
    #                  vmax  = max(spectrum_2D.flatten()),
    #                  xlabel= 'u (frequency parameter of the Fourier transform)',
    #                  ylabel= 'v (frequency parameter of the Fourier transform)',
    #                  title = 'Spectrum of the wheele picture')

    # Question 1.4
    ft2d_shifted = fftshift(ft2d)
    spectrum_shifted_2D = power_spectrum_2D(ft2d_shifted)
    img_size = img.shape[0] * img.shape[1]

    display_image(spectrum_shifted_2D,
                  vmin=min(spectrum_shifted_2D.flatten()),
                  vmax=max(spectrum_shifted_2D.flatten()),
                  extent=[
                      -height / 2 + 1, height / 2 + 1, -width / 2 + 1,
                      width / 2 + 1
                  ],
                  xlabel='u (frequency parameter of the Fourier transform)',
                  ylabel='v (frequency parameter of the Fourier transform)',
                  title='Spectrum of the wheele picture (shifted)')

    # Question 1.6
    img_computed = ifft2(ft2d)
    img_computed = img_computed.astype(int)
Ejemplo n.º 6
0
#    display_image(img_computed, True)

if __name__ == "__main__":
    # I moved questions 1.1-1.6 to separate function to work on the rest of questions
    questions1_6()

    path_chess = "../resource/damierHV.pgm"

    # Question 1.7
    img = read_pgm(path_chess)
    (width, height) = img.shape
    #    display_image(img, True)

    # Question 1.8
    ft2d = fft2(img)
    ft2d_shifted = fftshift(ft2d)
    spectrum_shifted_2D = power_spectrum_2D(ft2d_shifted)
    img_size = img.shape[0] * img.shape[1]

    #    display_image(spectrum_shifted_2D,
    #                  vmin=min(spectrum_shifted_2D.flatten()),
    #                  vmax=max(spectrum_shifted_2D.flatten()),
    #                  extent=[- height / 2 + 1, height / 2 + 1, - width / 2 + 1, width / 2 + 1],
    #                  xlabel= 'u (frequency parameter of the Fourier transform)',
    #                  ylabel= 'v (frequency parameter of the Fourier transform)',
    #                  title = 'Spectrum of the chess board picture')

    # print("min = " + str(min(spectrum_shifted_2D.flatten())) + ", max = " + str(max(spectrum_shifted_2D.flatten())))

    # from here i don't really understand WTF is going on
    img_computed = img_computed.astype(int)
    display_image(img_computed, True)

if __name__ == "__main__":
    # I moved questions 1.1-1.6 to separate function to work on the rest of questions
    questions1_6()

    path_chess = "../resource/damierHV.pgm"

# Question 1.7
    img = read_pgm(path_chess)
    (width, height) = img.shape
    display_image(img, True)

# Question 1.8
    ft2d = fft2(img)
    ft2d_shifted = fftshift(ft2d)
    spectrum_shifted_2D = power_spectrum_2D(ft2d_shifted)
    img_size = img.shape[0] * img.shape[1]
    display_image(spectrum_shifted_2D,
                  vmin=min(spectrum_shifted_2D.flatten()),
                  vmax=max(spectrum_shifted_2D.flatten()),
                  extent=[- height / 2 + 1, height / 2 + 1, - width / 2 + 1, width / 2 + 1])
    # print("min = " + str(min(spectrum_shifted_2D.flatten())) + ", max = " + str(max(spectrum_shifted_2D.flatten())))


# from here i don't really understand WTF is going on

# Question 1.9
    spectrum_x_0 = power_spectrum_2D(ft2d_shifted, fx=0)
    spectrum_x_26 = power_spectrum_2D(ft2d_shifted, fx=-26)