Exemplo n.º 1
0
def simple_image(verbose = False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)

    a = 10 * af.randu(6, 6)
    a3 = 10 * af.randu(5,5,3)

    dx,dy = af.gradient(a)
    display_func(dx)
    display_func(dy)

    display_func(af.resize(a, scale=0.5))
    display_func(af.resize(a, odim0=8, odim1=8))

    t = af.randu(3,2)
    display_func(af.transform(a, t))
    display_func(af.rotate(a, 3.14))
    display_func(af.translate(a, 1, 1))
    display_func(af.scale(a, 1.2, 1.2, 7, 7))
    display_func(af.skew(a, 0.02, 0.02))
    h = af.histogram(a, 3)
    display_func(h)
    display_func(af.hist_equal(a, h))

    display_func(af.dilate(a))
    display_func(af.erode(a))

    display_func(af.dilate3(a3))
    display_func(af.erode3(a3))

    display_func(af.bilateral(a, 1, 2))
    display_func(af.mean_shift(a, 1, 2, 3))

    display_func(af.medfilt(a))
    display_func(af.minfilt(a))
    display_func(af.maxfilt(a))

    display_func(af.regions(af.round(a) > 3))

    dx,dy = af.sobel_derivatives(a)
    display_func(dx)
    display_func(dy)
    display_func(af.sobel_filter(a))

    ac = af.gray2rgb(a)
    display_func(ac)
    display_func(af.rgb2gray(ac))
    ah = af.rgb2hsv(ac)
    display_func(ah)
    display_func(af.hsv2rgb(ah))

    display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))
Exemplo n.º 2
0
def simple_image(verbose=False):
    display_func = _util.display_func(verbose)
    print_func = _util.print_func(verbose)

    a = 10 * af.randu(6, 6)
    a3 = 10 * af.randu(5, 5, 3)

    dx, dy = af.gradient(a)
    display_func(dx)
    display_func(dy)

    display_func(af.resize(a, scale=0.5))
    display_func(af.resize(a, odim0=8, odim1=8))

    t = af.randu(3, 2)
    display_func(af.transform(a, t))
    display_func(af.rotate(a, 3.14))
    display_func(af.translate(a, 1, 1))
    display_func(af.scale(a, 1.2, 1.2, 7, 7))
    display_func(af.skew(a, 0.02, 0.02))
    h = af.histogram(a, 3)
    display_func(h)
    display_func(af.hist_equal(a, h))

    display_func(af.dilate(a))
    display_func(af.erode(a))

    display_func(af.dilate3(a3))
    display_func(af.erode3(a3))

    display_func(af.bilateral(a, 1, 2))
    display_func(af.mean_shift(a, 1, 2, 3))

    display_func(af.medfilt(a))
    display_func(af.minfilt(a))
    display_func(af.maxfilt(a))

    display_func(af.regions(af.round(a) > 3))

    dx, dy = af.sobel_derivatives(a)
    display_func(dx)
    display_func(dy)
    display_func(af.sobel_filter(a))

    ac = af.gray2rgb(a)
    display_func(ac)
    display_func(af.rgb2gray(ac))
    ah = af.rgb2hsv(ac)
    display_func(ah)
    display_func(af.hsv2rgb(ah))

    display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))
af.display(dy)

af.display(af.resize(a, scale=0.5))
af.display(af.resize(a, odim0=8, odim1=8))

t = af.randu(3,2)
af.display(af.transform(a, t))
af.display(af.rotate(a, 3.14))
af.display(af.translate(a, 1, 1))
af.display(af.scale(a, 1.2, 1.2, 7, 7))
af.display(af.skew(a, 0.02, 0.02))
h = af.histogram(a, 3)
af.display(h)
af.display(af.hist_equal(a, h))

af.display(af.dilate(a))
af.display(af.erode(a))

af.display(af.dilate3(a3))
af.display(af.erode3(a3))

af.display(af.bilateral(a, 1, 2))
af.display(af.mean_shift(a, 1, 2, 3))

af.display(af.medfilt(a))
af.display(af.minfilt(a))
af.display(af.maxfilt(a))

af.display(af.regions(af.round(a) > 3))

dx,dy = af.sobel_derivatives(a)
Exemplo n.º 4
0
def simple_image(verbose = False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)

    a = 10 * af.randu(6, 6)
    a3 = 10 * af.randu(5,5,3)

    dx,dy = af.gradient(a)
    display_func(dx)
    display_func(dy)

    display_func(af.resize(a, scale=0.5))
    display_func(af.resize(a, odim0=8, odim1=8))

    t = af.randu(3,2)
    display_func(af.transform(a, t))
    display_func(af.rotate(a, 3.14))
    display_func(af.translate(a, 1, 1))
    display_func(af.scale(a, 1.2, 1.2, 7, 7))
    display_func(af.skew(a, 0.02, 0.02))
    h = af.histogram(a, 3)
    display_func(h)
    display_func(af.hist_equal(a, h))

    display_func(af.dilate(a))
    display_func(af.erode(a))

    display_func(af.dilate3(a3))
    display_func(af.erode3(a3))

    display_func(af.bilateral(a, 1, 2))
    display_func(af.mean_shift(a, 1, 2, 3))

    display_func(af.medfilt(a))
    display_func(af.minfilt(a))
    display_func(af.maxfilt(a))

    display_func(af.regions(af.round(a) > 3))

    dx,dy = af.sobel_derivatives(a)
    display_func(dx)
    display_func(dy)
    display_func(af.sobel_filter(a))
    display_func(af.gaussian_kernel(3, 3))
    display_func(af.gaussian_kernel(3, 3, 1, 1))

    ac = af.gray2rgb(a)
    display_func(ac)
    display_func(af.rgb2gray(ac))
    ah = af.rgb2hsv(ac)
    display_func(ah)
    display_func(af.hsv2rgb(ah))

    display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))

    a = af.randu(6,6)
    b = af.unwrap(a, 2, 2, 2, 2)
    c = af.wrap(b, 6, 6, 2, 2, 2, 2)
    display_func(a)
    display_func(b)
    display_func(c)
    display_func(af.sat(a))

    a = af.randu(10,10,3)
    display_func(af.rgb2ycbcr(a))
    display_func(af.ycbcr2rgb(a))

    a = af.randu(10, 10)
    b = af.canny(a, low_threshold = 0.2, high_threshold = 0.8)

    display_func(af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC, af.DIFFUSION.GRAD))
Exemplo n.º 5
0
def simple_image(verbose=False):
    display_func = _util.display_func(verbose)
    print_func = _util.print_func(verbose)

    a = 10 * af.randu(6, 6)
    a3 = 10 * af.randu(5, 5, 3)

    dx, dy = af.gradient(a)
    display_func(dx)
    display_func(dy)

    display_func(af.resize(a, scale=0.5))
    display_func(af.resize(a, odim0=8, odim1=8))

    t = af.randu(3, 2)
    display_func(af.transform(a, t))
    display_func(af.rotate(a, 3.14))
    display_func(af.translate(a, 1, 1))
    display_func(af.scale(a, 1.2, 1.2, 7, 7))
    display_func(af.skew(a, 0.02, 0.02))
    h = af.histogram(a, 3)
    display_func(h)
    display_func(af.hist_equal(a, h))

    display_func(af.dilate(a))
    display_func(af.erode(a))

    display_func(af.dilate3(a3))
    display_func(af.erode3(a3))

    display_func(af.bilateral(a, 1, 2))
    display_func(af.mean_shift(a, 1, 2, 3))

    display_func(af.medfilt(a))
    display_func(af.minfilt(a))
    display_func(af.maxfilt(a))

    display_func(af.regions(af.round(a) > 3))

    dx, dy = af.sobel_derivatives(a)
    display_func(dx)
    display_func(dy)
    display_func(af.sobel_filter(a))
    display_func(af.gaussian_kernel(3, 3))
    display_func(af.gaussian_kernel(3, 3, 1, 1))

    ac = af.gray2rgb(a)
    display_func(ac)
    display_func(af.rgb2gray(ac))
    ah = af.rgb2hsv(ac)
    display_func(ah)
    display_func(af.hsv2rgb(ah))

    display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))

    a = af.randu(6, 6)
    b = af.unwrap(a, 2, 2, 2, 2)
    c = af.wrap(b, 6, 6, 2, 2, 2, 2)
    display_func(a)
    display_func(b)
    display_func(c)
    display_func(af.sat(a))

    a = af.randu(10, 10, 3)
    display_func(af.rgb2ycbcr(a))
    display_func(af.ycbcr2rgb(a))

    a = af.randu(10, 10)
    b = af.canny(a, low_threshold=0.2, high_threshold=0.8)

    display_func(
        af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC,
                                 af.DIFFUSION.GRAD))
Exemplo n.º 6
0
af.display(dy)

af.display(af.resize(a, scale=0.5))
af.display(af.resize(a, odim0=8, odim1=8))

t = af.randu(3, 2)
af.display(af.transform(a, t))
af.display(af.rotate(a, 3.14))
af.display(af.translate(a, 1, 1))
af.display(af.scale(a, 1.2, 1.2, 7, 7))
af.display(af.skew(a, 0.02, 0.02))
h = af.histogram(a, 3)
af.display(h)
af.display(af.hist_equal(a, h))

af.display(af.dilate(a))
af.display(af.erode(a))

af.display(af.dilate3(a3))
af.display(af.erode3(a3))

af.display(af.bilateral(a, 1, 2))
af.display(af.mean_shift(a, 1, 2, 3))

af.display(af.medfilt(a))
af.display(af.minfilt(a))
af.display(af.maxfilt(a))

af.display(af.regions(af.round(a) > 3))

dx, dy = af.sobel_derivatives(a)
Exemplo n.º 7
0
def harris_demo(console):

    root_path = os.path.dirname(os.path.abspath(__file__))
    file_path = root_path
    if console:
        file_path += "/../../assets/examples/images/square.png"
    else:
        file_path += "/../../assets/examples/images/man.jpg"
    img_color = af.load_image(file_path, True)

    img = af.color_space(img_color, af.CSPACE.GRAY, af.CSPACE.RGB)
    img_color /= 255.0

    ix, iy = af.gradient(img)
    ixx = ix * ix
    ixy = ix * iy
    iyy = iy * iy

    # Compute a Gaussian kernel with standard deviation of 1.0 and length of 5 pixels
    # These values can be changed to use a smaller or larger window
    gauss_filt = af.gaussian_kernel(5, 5, 1.0, 1.0)

    # Filter second order derivatives
    ixx = af.convolve(ixx, gauss_filt)
    ixy = af.convolve(ixy, gauss_filt)
    iyy = af.convolve(iyy, gauss_filt)

    # Calculate trace
    itr = ixx + iyy

    # Calculate determinant
    idet = ixx * iyy - ixy * ixy

    # Calculate Harris response
    response = idet - 0.04 * (itr * itr)

    # Get maximum response for each 3x3 neighborhood
    mask = af.constant(1, 3, 3)
    max_resp = af.dilate(response, mask)

    # Discard responses that are not greater than threshold
    corners = response > 1e5
    corners = corners * response

    # Discard responses that are not equal to maximum neighborhood response,
    # scale them to original value
    corners = (corners == max_resp) * corners

    # Copy device array to python list on host
    corners_list = corners.to_list()

    draw_len = 3
    good_corners = 0
    for x in range(img_color.dims()[1]):
        for y in range(img_color.dims()[0]):
            if corners_list[x][y] > 1e5:
                img_color = draw_corners(img_color, x, y, draw_len)
                good_corners += 1

    print("Corners found: {}".format(good_corners))
    if not console:
        # Previews color image with green crosshairs
        wnd = af.Window(512, 512, "Harris Feature Detector")

        while not wnd.close():
            wnd.image(img_color)
    else:
        idx = af.where(corners)

        corners_x = idx / float(corners.dims()[0])
        corners_y = idx % float(corners.dims()[0])

        print(corners_x)
        print(corners_y)
Exemplo n.º 8
0
def simple_image(verbose=False):
    display_func = _util.display_func(verbose)

    a = 10 * af.randu(6, 6)
    a3 = 10 * af.randu(5, 5, 3)

    dx, dy = af.gradient(a)
    display_func(dx)
    display_func(dy)

    display_func(af.resize(a, scale=0.5))
    display_func(af.resize(a, odim0=8, odim1=8))

    t = af.randu(3, 2)
    display_func(af.transform(a, t))
    display_func(af.rotate(a, 3.14))
    display_func(af.translate(a, 1, 1))
    display_func(af.scale(a, 1.2, 1.2, 7, 7))
    display_func(af.skew(a, 0.02, 0.02))
    h = af.histogram(a, 3)
    display_func(h)
    display_func(af.hist_equal(a, h))

    display_func(af.dilate(a))
    display_func(af.erode(a))

    display_func(af.dilate3(a3))
    display_func(af.erode3(a3))

    display_func(af.bilateral(a, 1, 2))
    display_func(af.mean_shift(a, 1, 2, 3))

    display_func(af.medfilt(a))
    display_func(af.minfilt(a))
    display_func(af.maxfilt(a))

    display_func(af.regions(af.round(a) > 3))
    display_func(
        af.confidenceCC(af.randu(10,
                                 10), (af.randu(2) * 9).as_type(af.Dtype.u32),
                        (af.randu(2) * 9).as_type(af.Dtype.u32), 3, 3, 10,
                        0.1))

    dx, dy = af.sobel_derivatives(a)
    display_func(dx)
    display_func(dy)
    display_func(af.sobel_filter(a))
    display_func(af.gaussian_kernel(3, 3))
    display_func(af.gaussian_kernel(3, 3, 1, 1))

    ac = af.gray2rgb(a)
    display_func(ac)
    display_func(af.rgb2gray(ac))
    ah = af.rgb2hsv(ac)
    display_func(ah)
    display_func(af.hsv2rgb(ah))

    display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))

    a = af.randu(6, 6)
    b = af.unwrap(a, 2, 2, 2, 2)
    c = af.wrap(b, 6, 6, 2, 2, 2, 2)
    display_func(a)
    display_func(b)
    display_func(c)
    display_func(af.sat(a))

    a = af.randu(10, 10, 3)
    display_func(af.rgb2ycbcr(a))
    display_func(af.ycbcr2rgb(a))

    a = af.randu(10, 10)
    b = af.canny(a, low_threshold=0.2, high_threshold=0.8)

    display_func(
        af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC,
                                 af.DIFFUSION.GRAD))

    a = af.randu(10, 10)
    psf = af.gaussian_kernel(3, 3)
    cimg = af.convolve(a, psf)
    display_func(
        af.iterativeDeconv(cimg, psf, 100, 0.5, af.ITERATIVE_DECONV.LANDWEBER))
    display_func(
        af.iterativeDeconv(cimg, psf, 100, 0.5,
                           af.ITERATIVE_DECONV.RICHARDSONLUCY))
    display_func(af.inverseDeconv(cimg, psf, 1.0, af.INVERSE_DECONV.TIKHONOV))