def large_1d_blur():
    large_1d_blur_filter = luo_fspecial(25, 1, 10)
    large_blur_image = my_imfilter(test_image, large_1d_blur_filter)
    large_blur_image = my_imfilter(large_blur_image, large_1d_blur_filter)
    luo_imshow("Figure 4", large_blur_image)
    luo_imwrite(large_blur_image, 'large_blur_image.jpg')
    return large_blur_image
def blur():
    blur_filter = np.array(([1, 1, 1], [1, 1, 1], [1, 1, 1]), dtype="float32")
    blur_filter = blur_filter / np.sum(blur_filter)
    blur_image = my_imfilter(test_image, blur_filter)
    luo_imshow("Figure 3", blur_image)
    luo_imwrite(blur_image, 'blur_image.jpg')
    return blur_image
def laplacian():
    laplacian_filter = np.array(([0, 1, 0], [1, -4, 1], [0, 1, 0]),
                                dtype="float32")
    laplacian_image = my_imfilter(test_image, laplacian_filter)
    # 0.5 added because the output image is centered around zero otherwise and mostly black
    luo_imshow("Figure 6", laplacian_image + 0.5)
    luo_imwrite(laplacian_image + 0.5, "laplacian_image.jpg")
    return laplacian_image
def sobel():
    sobel_filter = np.array(([-1, 0, 1], [-2, 0, 2], [-1, 0, 1]),
                            dtype="float32")
    sobel_image = my_imfilter(test_image, sobel_filter)
    # 0.5 added because the output image is centered around zero otherwise and mostly black
    luo_imshow("Figure 5", sobel_image + 0.5)
    luo_imwrite(sobel_image + 0.5, "sobel_image.jpg")
    return sobel_image
def identity():
    identity_filter = np.array(
        ([0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 1, 0], [0, 0, 0], [0, 0, 0
                                                                 ], [0, 0, 0]),
        dtype="float32")
    identity_image = my_imfilter(test_image, identity_filter)
    luo_imshow("Figure 2", identity_image)
    luo_imwrite(identity_image, 'identity_image.jpg')
    return identity_image
示例#6
0
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

## Visualize and save outputs
luo_imshow("low", low_frequencies)
luo_imshow("high", high_frequencies)
luo_imshow("vis_hybrid_image", hybrid_image)
vis = vis_hybrid_image(hybrid_image)
luo_imshow("vis", vis)
luo_imwrite(low_frequencies, "low_frequencies.jpg")
luo_imwrite(high_frequencies, "high_frequencies.jpg")
luo_imwrite(hybrid_image, "hybrid_image.jpg")
luo_imwrite(vis, "vis.jpg")

import time

time.sleep(100)
def high_pass():
    high_pass_image = test_image - blur()
    luo_imshow("Figure 7", high_pass_image + 0.5)
    luo_imwrite(high_pass_image + 0.5, "high_pass_image.jpg")
    return high_pass_image
from my_imfilter import my_imfilter
from utils import luo_imshow, luo_imwrite, luo_fspecial
from vis_hybrid_image import vis_hybrid_image

# this script has test cases to help you test my_imfilter() which you will
# write. You should verify that you get reasonable output here before using
# your filtering to construct a hybrid image in proj1.m. The outputs are
# all saved and you can include them in your writeup. You can add calls to
# imfilter() if you want to check that my_imfilter() is doing something
# similar.
cv2.destroyAllWindows()

## Setup
test_image = cv2.imread("../data/cat.bmp")
test_image = cv2.resize(test_image, (0, 0), fx=0.7, fy=0.7)
luo_imshow("Figure 1", test_image)


## Identify filter
# This filter should do nothing regardless of the padding method you use.
def identity():
    identity_filter = np.array(
        ([0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 1, 0], [0, 0, 0], [0, 0, 0
                                                                 ], [0, 0, 0]),
        dtype="float32")
    identity_image = my_imfilter(test_image, identity_filter)
    luo_imshow("Figure 2", identity_image)
    luo_imwrite(identity_image, 'identity_image.jpg')
    return identity_image