Example #1
0
def main(filter, kernel_size, image, sigma):
    """
    main function
    reads the image coming from the image path cli arg

    handles the switch of argument/ perams for the PA1 program.
    accepts two arguments, filter and kernel_size

    :argument filter[dict], kernel_size[integer value]
    :returns success or failure value from dict filter

    """

    image = cv2.imread(image, cv2.IMREAD_GRAYSCALE)

    # my_dict = {
    #     'box': filters.box(kernel_size, image),
    #     'median': filters.median(kernel_size, image),
    #     'guassian': filters.gaussian(kernel_size, image),
    #     'gradient': filters.gradient(kernel_size, image),
    #     'sobel': filters.sobel(image),
    #     'fast_gaussian': filters.fast_gaussian(kernel_size, image),
    #     'histogram': filters.histogram(kernel_size, image),
    #     'thresholding': filters.thesholding(kernel_size, image)
    # }
    # return my_dict[filter](kernel_size, image)

    if filter == 'box':
        return filters.box(kernel_size, image)
    elif filter == 'median':
        return filters.median(image)
    elif filter == 'gaussian':
        return filters.gaussian(kernel_size, sigma, image)
    elif filter == 'gradient':
        return filters.gradient(image)
    elif filter == 'sobel':
        return filters.sobel(image)
    elif filter == 'fast_gaussian':
        return filters.fast_gaussian(kernel_size, image, sigma)
    elif filter == 'histogram':
        return filters.histogram(kernel_size, image)
    elif filter == 'thresholding':
        return filters.thresholding(kernel_size, image)
    else:
        print("function not recognized")
        return 0
Example #2
0
def sobel_assignment(img):
    """
    This function convolves the image with the derivative of x- and y-. We can
    approach the length of gradient with the help of these deriatives.
    """
    # Get filter
    sobel_x, sobel_y = filters.sobel()

    # Apply filter
    ISx = convolve_image(img, sobel_x)
    ISy = convolve_image(img, sobel_y)

    # Approach length of gradient
    G = np.sqrt(ISx**2 + ISy**2)

    # Show result
    show_images([ISx, ISy, G])
Example #3
0
try:
    imp.find_module('filters')
    # Make things with supposed existing module
except ImportError:
    print "This program depends on the sobel filter module in filters"
    exit

img = cv2.imread('lena_gray.png',0)

kx1 = np.array(([1, 2, 1]),np.float32)
ky1 = np.array(([-1,0,1]),np.float32)

kx2 = np.array(([-1,0,1]),np.float32)
ky2 = np.array(([1,2,1]),np.float32)

gx = flt.sobel(img,kx1,ky1)
gy = flt.sobel(img,kx2,ky2)

g = np.sqrt(np.square(gx) + np.square(gy))


plt.title('1D Convolution Example')
plt.subplot(141),plt.imshow(img,cmap=cm.gray),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(142),plt.imshow(gx,cmap=cm.gray),plt.title('Gx')
plt.xticks([]), plt.yticks([])
plt.subplot(143),plt.imshow(gy,cmap=cm.gray),plt.title('Gy')
plt.xticks([]), plt.yticks([])
plt.subplot(144),plt.imshow(g,cmap=cm.gray),plt.title('G')
plt.xticks([]), plt.yticks([])
Example #4
0
from threshold import threshold as threshold
from threshold import threshold_inverse as threshold_inv
from filters import median_filter as median_filter
from filters import make_black_filter as blacker
from filters import sobel_filter as sobel
from filters import laplacian_filter as laplacian
from filters import gaussian_blur as gaussian
from pix_count import pixel_count
from draw_cont import drawer

path = 'PICS/26.JPG'  # yellow background

cap = cv2.VideoCapture(path)

while True:
    ret, frame = cap.read()

    scale_percent = 20
    width = int(frame.shape[1] * scale_percent / 100)
    height = int(frame.shape[0] * scale_percent / 100)
    dsize = (width, height)
    frame = cv2.resize(frame, dsize)

    frame1 = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
    frame4, aaaaa = sobel(frame1)
    print(frame4[0:10, 0:10])
    cv2.imshow('frame2', frame1)
    cv2.imshow('original', frame4)
    cv2.waitKey(0)
    # if cv2.waitKey(1) & 0xff == ord("q"):
    # break
Example #5
0
import cv2
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import filters as flt

img = cv2.imread('lena_gray.png',0)

kernelx = np.array(([-1,0,1],[-2,0,2],[-1,0,1]),np.float32)
kernely = np.array(([-1,-2,-1],[0,0,0],[1,2,1]),np.float32)

gx = flt.sobel(img,kernelx)
gy = flt.sobel(img,kernely)
g = np.sqrt(np.square(gx) + np.square(gy))


plt.title('2D Convolution Example')
plt.subplot(141),plt.imshow(img,cmap=cm.gray),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(142),plt.imshow(gx,cmap=cm.gray),plt.title('Gx')
plt.xticks([]), plt.yticks([])
plt.subplot(143),plt.imshow(gy,cmap=cm.gray),plt.title('Gy')
plt.xticks([]), plt.yticks([])
plt.subplot(144),plt.imshow(g,cmap=cm.gray),plt.title('G')
plt.xticks([]), plt.yticks([])

plt.show()
Example #6
0
import cv2
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import filters as flt

img = cv2.imread('lena_gray.png', 0)

kernelx = np.array(([-1, 0, 1], [-2, 0, 2], [-1, 0, 1]), np.float32)
kernely = np.array(([-1, -2, -1], [0, 0, 0], [1, 2, 1]), np.float32)

gx = flt.sobel(img, kernelx)
gy = flt.sobel(img, kernely)
g = np.sqrt(np.square(gx) + np.square(gy))

plt.title('2D Convolution Example')
plt.subplot(141), plt.imshow(img, cmap=cm.gray), plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(142), plt.imshow(gx, cmap=cm.gray), plt.title('Gx')
plt.xticks([]), plt.yticks([])
plt.subplot(143), plt.imshow(gy, cmap=cm.gray), plt.title('Gy')
plt.xticks([]), plt.yticks([])
plt.subplot(144), plt.imshow(g, cmap=cm.gray), plt.title('G')
plt.xticks([]), plt.yticks([])

plt.show()