Example #1
0
def laplacian_test(image_low, image_high, size, sigma):
    image_low = controllers.open_image(image_low, False).astype('float32')
    image_high = controllers.open_image(image_high, False).astype('float32')

    image_low = cv2.GaussianBlur(image_low, (size, size), 20).astype('float32')
    image_low = controllers.rescale(image_low)
    oryginal_high = image_high.astype('float32') - cv2.GaussianBlur(
        image_high, (size, size), 17).astype('float32')
    oryginal_output = controllers.rescale(image_low +
                                          oryginal_high).astype('float32')

    kernel_l_o_g = controllers.l_o_g_kernel(size, sigma)
    image_high[:, :, 0] = np.array(cv2.filter2D(image_high[:, :, 0], -1,
                                                kernel_l_o_g),
                                   dtype=np.float32)
    image_high[:, :, 1] = np.array(cv2.filter2D(image_high[:, :, 1], -1,
                                                kernel_l_o_g),
                                   dtype=np.float32)
    image_high[:, :, 2] = np.array(cv2.filter2D(image_high[:, :, 2], -1,
                                                kernel_l_o_g),
                                   dtype=np.float32)
    image_high = controllers.rescale(image_high)
    log_output = controllers.rescale(image_low + image_high).astype('float32')
    cv2.imwrite('results/laplacian/log_%d_%d.jpeg' % (size, sigma),
                log_output.astype('uint8'))

    comparison = np.sqrt((oryginal_high - image_high)**2)
    comparison = controllers.rescale(comparison)
    cv2.imwrite('results/laplacian/log_comparison_%d_%d.jpeg' % (size, sigma),
                comparison.astype('uint8'))
Example #2
0
def dog_test(image_low, image_high, size, sigma_1, sigma_2):
    image_low = controllers.open_image(image_low, False).astype('float32')
    image_high = controllers.open_image(image_high, False).astype('float32')

    image_low = cv2.GaussianBlur(image_low, (size, size), 20).astype('float32')
    oryginal_high = image_high.astype('float32') - cv2.GaussianBlur(
        image_high, (size, size), 17).astype('float32')
    oryginal_output = controllers.rescale(image_low +
                                          oryginal_high).astype('float32')

    d_o_g_filter = controllers.d_o_g(size, sigma_1, sigma_2)
    image_high[:, :, 0] = np.array(cv2.filter2D(image_high[:, :, 0], -1,
                                                d_o_g_filter),
                                   dtype=np.float32)
    image_high[:, :, 1] = np.array(cv2.filter2D(image_high[:, :, 1], -1,
                                                d_o_g_filter),
                                   dtype=np.float32)
    image_high[:, :, 2] = np.array(cv2.filter2D(image_high[:, :, 2], -1,
                                                d_o_g_filter),
                                   dtype=np.float32)
    image_high = controllers.rescale(image_high)
    dog_output = controllers.rescale(image_low + image_high).astype('float32')
    cv2.imwrite('results/dog/dog_%d_%d_%d.jpeg' % (size, sigma_1, sigma_2),
                dog_output.astype('uint8'))

    comparison = np.sqrt((oryginal_high - image_high)**2)
    comparison = controllers.rescale(comparison)
    cv2.imwrite(
        'results/dog/dog_comparison_%d_%d_%d.jpeg' % (size, sigma_1, sigma_2),
        comparison.astype('uint8'))
Example #3
0
def generate_oryginal_image(image_low, image_high, size, sigma):
    image_low = controllers.open_image(image_low, False).astype('float32')
    image_high = controllers.open_image(image_high, False).astype('float32')

    oryginal_low = cv2.GaussianBlur(image_low, (size, size),
                                    33).astype('float32')
    oryginal_high = image_high.astype('float32') - cv2.GaussianBlur(
        image_high, (size, size), 17).astype('float32')
    oryginal_output = controllers.rescale(oryginal_low + oryginal_high)
    return oryginal_output
Example #4
0
def inbuilt_filtering(image_low, image_high, kernel_1_size, kernel_2_size,
                      sigma_1, sigma_2):
    kernel_1 = (kernel_1_size, kernel_1_size)
    kernel_2 = (kernel_2_size, kernel_2_size)
    image_low = controllers.open_image(low_image_path, is_grayscale)
    image_high = controllers.open_image(high_image_path, is_grayscale)

    image_low = cv2.GaussianBlur(image_low, kernel_1, 0).astype('float32')
    image_high = image_high.astype('float32') - cv2.GaussianBlur(
        image_high, kernel_2, 0).astype('float32')

    output_image = image_low + image_high

    return output_image
Example #5
0
def sobel_test(image_low, image_high, size, sigma):
    kernel = controllers.GaussianKernel(size, sigma)
    image_low = controllers.open_image(image_low, False).astype('float32')
    image_high = controllers.open_image(image_high, False).astype('float32')

    image_low = controllers.filtering(image_low, kernel)
    image_low = controllers.rescale(image_low)

    sobel_high = controllers.sobel_filtering(image_high)
    sobel_high = controllers.rescale(sobel_high)
    sobel_output = controllers.rescale(image_low + sobel_high)
    cv2.imwrite('results/sobel/sobel_%d.jpeg' % sigma,
                sobel_output.astype('uint8'))

    oryginal_high = image_high.astype('float32') - cv2.GaussianBlur(
        image_high, (size, size), 17).astype('float32')
    oryginal_high = controllers.rescale(oryginal_high)
    oryginal = controllers.rescale(image_low + oryginal_high).astype('float32')
    comparison = np.sqrt((oryginal_high - sobel_high)**2)
    comparison = controllers.rescale(comparison)
    cv2.imwrite('results/sobel/sobel_comparison_%d.jpeg' % sigma,
                comparison.astype('uint8'))
Example #6
0
    args = parser.parse_args()

    low_image_path = args.low_freq_image
    high_image_path = args.high_freq_image
    is_grayscale = True if args.gray_scale == 'T' or args.gray_scale == 'True' else False
    kernel_1_size = int(args.kernel_1_size)
    kernel_2_size = int(args.kernel_2_size)
    sigma_1 = int(args.sigma_1)
    sigma_2 = int(args.sigma_2)
    path = args.path

    if kernel_1_size % 2 == 0 or kernel_2_size % 2 == 0:
        print('Kernel size has to be odd!')
        sys.exit()

    image_low = controllers.open_image(low_image_path,
                                       is_grayscale).astype('float32')
    image_high = controllers.open_image(high_image_path,
                                        is_grayscale).astype('float32')

    kernel_1 = controllers.GaussianKernel(kernel_1_size, sigma_1)
    kernel_2 = controllers.GaussianKernel(kernel_2_size, sigma_2)
    image_low = controllers.filtering(image_low, kernel_1)
    image_high -= controllers.filtering(image_high, kernel_2)
    output_image = controllers.rescale(image_low + image_high)

    path = '' if path == None else path

    cv2.imwrite(os.path.join(path, 'second_task_result.jpg'),
                controllers.rescale(output_image).astype('uint8'))

    #comparizon
Example #7
0
    args = parser.parse_args()

    low_image_path = args.low_freq_image
    high_image_path = args.high_freq_image
    is_grayscale = True if args.gray_scale == 'T' or args.gray_scale == 'True' else False
    kernel_1_size = int(args.kernel_1_size)
    kernel_2_size = int(args.kernel_2_size)
    sigma_1 = 0 if args.sigma_1 == None else int(args.sigma_1)
    sigma_2 = 0 if args.sigma_2 == None else int(args.sigma_2)
    path = args.path

    if kernel_1_size % 2 == 0 or kernel_2_size % 2 == 0:
        print('Kernel size has to be odd!')
        sys.exit()

    kernel_1 = (kernel_1_size, kernel_1_size)
    kernel_2 = (kernel_2_size, kernel_2_size)
    image_low = open_image(low_image_path, is_grayscale)
    image_high = open_image(high_image_path, is_grayscale)

    image_low = cv2.GaussianBlur(image_low, kernel_1, 0).astype('float32')
    image_high = image_high.astype('float32') - cv2.GaussianBlur(
        image_high, kernel_2, 0).astype('float32')

    output_image = image_low + image_high
    # rescale to 255
    output_image = rescale(output_image).astype('uint8')

    path = '' if path == None else path
    cv2.imwrite(os.path.join(path, 'first_task_result.jpg'), output_image)
import cv2
import numpy as np

# R = [0, 0, 1.0] based on the following page
# http://pages.cs.wisc.edu/~csverma/CS766_09/Stereo/stereo.html

with open('psmImages/chrome.txt', 'r') as file:
    number_of_files = int(file.readline().rstrip())
    images_paths = []
    for i in range(number_of_files):
        images_paths.append(file.readline().rstrip())
    images_mask = file.readline().rstrip()

images = []
for image_path in images_paths:
    images.append(open_image(image_path))

mask_image = open_image(images_mask)
mask_image = cv2.cvtColor(mask_image, cv2.COLOR_BGR2GRAY)

#calculate center of the ball
max_val = np.max(mask_image)
coords = np.argwhere(mask_image == max_val)
y_min = np.min(coords[:, 0])
y_max = np.max(coords[:, 0])
x_min = np.min(coords[:, 1])
x_max = np.max(coords[:, 1])

y_centre = (y_max + y_min) / 2.0
x_centre = (x_max + x_min) / 2.0
radius = (x_max - x_min) / 2.0