Exemplo n.º 1
0
def test_optimum_frequencies():
    for image1, image2 in hybridize:
        i = i + 1
        for cutoff_freq in freq:
            fig = plt.figure(cutoff_freq)
            filter = generate_gaussian_filter(
                (cutoff_freq * 4 + 1, cutoff_freq * 4 + 1), cutoff_freq
            )  #insert values from fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency) here
            """
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % YOUR CODE BELOW. Use my_imfilter to create 'low_frequencies' and
            % 'high_frequencies' and then combine them to create 'hybrid_image'
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % Remove the high frequencies from image1 by blurring it. The amount of
            % blur that works best will vary with different image pairs
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
            """

            low_frequencies = my_imfilter(image1, filter)
            """
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % Remove the low frequencies from image2. The easiest way to do this is to
            % subtract a blurred version of image2 from the original version of image2.
            % This will give you an image centered at zero with negative values.
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            """

            high_frequencies = image2 - my_imfilter(image2, filter)
            """
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % Combine the high frequencies and low frequencies
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            """
            hybrid_image = low_frequencies + high_frequencies
            np.clip(hybrid_image, 0, 1)
            #%% Visualize and save outputs

            # ax1 = fig.add_subplot(gs[0, 0]) # row 0, col 0
            # ax1.imshow(low_frequencies)

            # ax2 = fig.add_subplot(gs[0, 1]) # row 0, col 1
            # ax2.imshow(np.clip(high_frequencies + 0.5,0,1))

            vis = vis_hybrid_image(
                hybrid_image)  #see function script vis_hybrid_image.py
            np.clip(vis, 0, 1)

            plt.imshow(vis)
            plt.title(cutoff_freq)

    # mpimg.imsave('../Results/low_frequencies.jpg',low_frequencies)
    # mpimg.imsave('../Results/high_frequencies.jpg',np.clip(high_frequencies + 0.5,0,1))
    # mpimg.imsave('../Results/hybrid_image.jpg',hybrid_image)
    mpimg.imsave('../Results/hybrid_image_scales.jpg', np.clip(vis, 0, 1))
    plt.show()
Exemplo n.º 2
0
pulse = np.zeros_like(gaussian_filter)
pulse[cutoff_frequency * 2 + 1, cutoff_frequency * 2 + 1] = 1
# high_frequencies = np.clip(my_imfilter(image2, pulse - gaussian_filter), -0.5 ,0.5)
high_frequencies = my_imfilter(image2, pulse - gaussian_filter)

############################################################################
# Combine the high frequencies and low frequencies                         #
############################################################################
hybrid_image = normalize(high_frequencies + low_frequencies)
# hybrid_image2 = normalize(np.sqrt((high_frequencies + 0.5) * low_frequencies))
''' Visualize and save outputs '''
plt.figure(1)
plt.imshow(low_frequencies)
plt.figure(2)
plt.imshow(high_frequencies + 0.5)
vis = vis_hybrid_image(hybrid_image)
plt.figure(3)
plt.imshow(vis)
# plt.figure(4)
# vis2 = vis_hybrid_image(hybrid_image2)
# plt.imshow(vis2)
plt.imsave(main_path + '/results/low_frequencies_' + name1 + '.png',
           low_frequencies, 'quality', 95)
plt.imsave(main_path + '/results/high_frequencies_' + name2 + '.png',
           high_frequencies + 0.5, 'quality', 95)
plt.imsave(main_path + '/results/hybrid_image_' + name1 + '_' + name2 + '.png',
           hybrid_image, 'quality', 95)
plt.imsave(
    main_path + '/results/hybrid_image_scales_' + name1 + '_' + name2 + '.png',
    vis, 'quality', 95)
# plt.imsave(main_path+'/results/hybrid_image2_'+ name1 + '_' +  name2 + '.png', hybrid_image2, 'quality', 95)
Exemplo n.º 3
0
def main():
    """ function to create hybrid images """
    # read images and convert to floating point format
    main_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    image1 = mpimg.imread(os.path.join(main_path, 'data', 'fish.bmp'))
    image2 = mpimg.imread(os.path.join(main_path, 'data', 'submarine.bmp'))
    image1 = image1.astype(np.float32) / 255
    image2 = image2.astype(np.float32) / 255

    # Several additional test cases are provided for you, but feel free to make
    # your own (you'll need to align the images in a photo editor such as
    # Photoshop). The hybrid images will differ depending on which image you
    # assign as image1 (which will provide the low frequencies) and which image
    # you asign as image2 (which will provide the high frequencies)

    ### Filtering and Hybrid Image construction ###
    cutoff_frequency = 7  # This is the standard deviation, in pixels, of the
    # Gaussian blur that will remove the high frequencies from one image and
    # remove the low frequencies from another image (by subtracting a blurred
    # version from the original version). You will want to tune this for every
    # image pair to get the best results.
    gaussian_filter = gauss2D(shape=(cutoff_frequency * 4 + 1,
                                     cutoff_frequency * 4 + 1),
                              sigma=cutoff_frequency)

    #########################################################################
    # TODO: Use my_imfilter create 'low_frequencies' and                    #
    # 'high_frequencies' and then combine them to create 'hybrid_image'     #
    #########################################################################
    #########################################################################
    # Remove the high frequencies from image1 by blurring it. The amount of #
    # blur that works best will vary with different image pairs             #
    #########################################################################
    low_frequencies = my_imfilter(image1, gaussian_filter)

    ############################################################################
    # Remove the low frequencies from image2. The easiest way to do this is to #
    # subtract a blurred version of image2 from the original version of image2.#
    # This will give you an image centered at zero with negative values.       #
    ############################################################################
    high_frequencies = image2 - my_imfilter(image2, gaussian_filter)

    ############################################################################
    # Combine the high frequencies and low frequencies                         #
    ############################################################################
    hybrid_image = high_frequencies + low_frequencies

    ### Visualize and save outputs ###
    plt.figure(1)
    plt.imshow(low_frequencies)
    plt.figure(2)
    plt.imshow(high_frequencies + 0.5)
    vis = vis_hybrid_image(hybrid_image)
    plt.figure(3)
    plt.imshow(vis)
    plt.imsave(os.path.join(main_path, 'results', 'fish_frequencies.png'),
               low_frequencies,
               dpi=95)
    plt.imsave(os.path.join(main_path, 'results',
                            'submarine_high_frequencies.png'),
               high_frequencies + 0.5,
               dpi=95)
    plt.imsave(os.path.join(main_path, 'results',
                            'fish_submarine_hybrid_image.png'),
               hybrid_image,
               dpi=95)
    plt.imsave(os.path.join(main_path, 'results',
                            'fish_submarine_hybrid_image_scales.png'),
               vis,
               dpi=95)

    plt.show()
Exemplo n.º 4
0
#%% Visualize and save outputs

imgLr = np.clip(low_frequencies, 0, 1.0)
imgRr = np.clip(high_frequencies + 0.5, 0, 1.0)

f = plt.figure()
f.add_subplot(1, 2, 1)
plt.title("Low Frequency")
plt.imshow(imgLr)
f.add_subplot(1, 2, 2)
plt.title("High Frequency")
plt.imshow(imgRr)
plt.show(block=True)

vis = vis_hybrid_image(hybrid_image)  #see function script vis_hybrid_image.py
plt.figure(3)
plt.imshow(np.clip(vis, 0, 1))
plt.show()
'''
plt.figure(1)
plt.imshow(low_frequencies)
plt.figure(2)
plt.imshow(high_frequencies + 0.5);
vis = vis_hybrid_image(hybrid_image) #see function script vis_hybrid_image.py
plt.figure(3)
plt.imshow(vis)

# outputPath = join(''.join([PATH_OUTPUT_IMAGES, '/']))

mpimg.imsave('Results/low_frequencies.jpg',np.clip(low_frequencies, 0, 1.0)) 
# Combine the high frequencies and low frequencies                         #
############################################################################
hybrid_image = normalize(low_frequencies + high_frequencies)
hybrid_image_2 = normalize(low_frequencies_2 + high_frequencies_2)
hybrid_image_3 = normalize(low_frequencies_3 + high_frequencies_3)
hybrid_image_4 = normalize(low_frequencies_4 + high_frequencies_4)
hybrid_image_5 = normalize(low_frequencies_5 + high_frequencies_5)
hybrid_image_6 = normalize(low_frequencies_6 + high_frequencies_6)
''' Visualize and save outputs '''
print("Cat and Dog")
print("Cutoff frequency", cutoff_frequency)
plt.figure(1)
plt.imshow(low_frequencies)
plt.figure(2)
plt.imshow(high_frequencies + 0.5)
vis = vis_hybrid_image(hybrid_image)
plt.figure(3)
plt.imshow(vis)
plt.imsave(main_path + '/results/low_frequencies.png', low_frequencies,
           'quality', 95)
plt.imsave(main_path + '/results/high_frequencies.png', high_frequencies + 0.5,
           'quality', 95)
plt.imsave(main_path + '/results/hybrid_image.png', hybrid_image, 'quality',
           95)
plt.imsave(main_path + '/results/hybrid_image_scales.png', vis, 'quality', 95)
plt.show()
print("Marilyn and Einstein")
print("Cutoff frequency", cutoff_frequency_2)
plt.figure(4)
plt.imshow(low_frequencies_2)
plt.figure(5)
Exemplo n.º 6
0
############################################################################
high_frequencies = I_2 - my_imfilter(I_2, gaussian_filter)
high_frequencies_1 = I_4 - my_imfilter(I_4, gaussian_filter)
high_frequencies = normalize(high_frequencies)
high_frequencies_1 = normalize(high_frequencies_1)
############################################################################
# Combine the high frequencies and low frequencies                         #
############################################################################
hybrid_image = normalize(low_frequencies + high_frequencies)
hybrid_image_1 = normalize(low_frequencies_1 + high_frequencies_1)
''' Visualize and save outputs '''
plt.figure(1)
plt.imshow(low_frequencies)
plt.figure(2)
plt.imshow(high_frequencies)
vis = vis_hybrid_image(hybrid_image)
plt.figure(3)
plt.imshow(vis)
plt.figure(4)
plt.imshow(low_frequencies_1)
plt.figure(5)
plt.imshow(high_frequencies_1)
vis_1 = vis_hybrid_image(hybrid_image_1)
plt.figure(6)
plt.imshow(vis_1)

#plt.figure(4)
#plt.hist(fft_I_1, bins = 'auto')
#plt.figure(5)
#plt.hist(fft_I_2, bins = 'auto')
plt.imsave('../results/image/low_frequencies.png', low_frequencies, 'quality',