예제 #1
0
파일: image_ops.py 프로젝트: 0rchard/CUV
def test_cuda_array(pic):
    pic_h = cp.push_host(pic)

    # downsample pic_h
    tmp = (np.array([pic_h.h,pic_h.w])/2).astype('uint32')
    down  = cp.dev_matrix_rmf(tmp[0],tmp[1])
    ca    = cp.dev_cuda_array_f(pic_h.h,pic_h.w)
    ca.assign(pic_h)
    cp.gaussian_pyramid_downsample(down,ca)

    # upsample downsampled
    ca    = cp.dev_cuda_array_f(down.h,down.w)
    ca.assign(down)
    up    = cp.dev_matrix_rmf(pic_h.h, pic_h.w)
    cp.gaussian_pyramid_upsample(up,ca)
    print cp.pull(up)

    plt.matshow(cp.pull(down))
    plt.title("Downsampled")
    plt.matshow(pic)
    plt.title("Original")
    plt.matshow(cp.pull(up))
    plt.title("Upsampled")
    plt.show()
    ca.dealloc()
예제 #2
0
def test_cuda_array(pic):
    pic_h = cp.push_host(pic)

    # downsample pic_h
    tmp = (np.array([pic_h.h, pic_h.w]) / 2).astype('uint32')
    down = cp.dev_matrix_rmf(tmp[0], tmp[1])
    ca = cp.dev_cuda_array_f(pic_h.h, pic_h.w)
    ca.assign(pic_h)
    cp.gaussian_pyramid_downsample(down, ca)

    # upsample downsampled
    ca = cp.dev_cuda_array_f(down.h, down.w)
    ca.assign(down)
    up = cp.dev_matrix_rmf(pic_h.h, pic_h.w)
    cp.gaussian_pyramid_upsample(up, ca)
    print cp.pull(up)

    plt.matshow(cp.pull(down))
    plt.title("Downsampled")
    plt.matshow(pic)
    plt.title("Original")
    plt.matshow(cp.pull(up))
    plt.title("Upsampled")
    plt.show()
    ca.dealloc()
예제 #3
0
def test_pixel_classes():
    w, h = 512, 512
    input_channels, pyramid_channels = 4, 3
    pic = Image.open("tests/data/lena.bmp").resize((w, h)).convert("RGBA")
    pic = np.asarray(pic).reshape(h, w * 4)
    pic_d = cp.push(pic)
    pyr = cp.dev_image_pyramid_f(pic_d.h / 2, pic_d.w / input_channels / 2, 4,
                                 pyramid_channels)
    pyr.build(pic_d, 4)
    plt.matshow(pic[0:h:2, 0:4 * w:8])
    #plt.matshow(cp.pull(pyr.get(1,0)))
    #plt.title("Channel0")
    #plt.matshow(cp.pull(pyr.get(1,1)))
    #plt.title("Channel1")
    #plt.matshow(cp.pull(pyr.get(1,2)))
    #plt.title("Channel2")
    #plt.matshow(cp.pull(pyr.get_all_channels(1)))
    #plt.title("allchannels level 1")
    #plt.show()

    # create source image from higher level of pyramid
    pic1 = pyr.get_all_channels(0)
    for i in xrange(10):
        smooth(pic1)
    plt.matshow(cp.pull(pic1)[:h / 2, :w])
    ca = cp.dev_cuda_array_f(pic1.h, pic1.w, 1)
    ca.assign(pic1)

    # create destination matrix
    pic0 = pyr.get(0)
    dst = cp.dev_matrix_rmuc(pic0.h, pic0.w * 4)  # uchar4

    # generate pixel classes and visualize
    cp.get_pixel_classes(dst, ca, 1)
    tmp = cp.pull(dst)
    tmp = Image.frombuffer("CMYK", (pic0.w, pic0.h),
                           cp.pull(dst).flatten(), "raw", "CMYK", 0, 1).resize(
                               (2 * 512, 2 * 512), Image.NEAREST)
    tmp.show()
    print cp.pull(dst)
    plt.show()
예제 #4
0
파일: image_ops.py 프로젝트: 0rchard/CUV
def test_pixel_classes():
    w, h = 512,512
    input_channels, pyramid_channels = 4,3
    pic = Image.open("tests/data/lena.bmp").resize((w,h)).convert("RGBA")
    pic = np.asarray(pic).reshape(h,w*4)
    pic_d = cp.push(pic)
    pyr = cp.dev_image_pyramid_f(pic_d.h/2,pic_d.w/input_channels/2,4,pyramid_channels)
    pyr.build(pic_d,4)
    plt.matshow(pic[0:h:2,0:4*w:8])
    #plt.matshow(cp.pull(pyr.get(1,0)))
    #plt.title("Channel0")
    #plt.matshow(cp.pull(pyr.get(1,1)))
    #plt.title("Channel1")
    #plt.matshow(cp.pull(pyr.get(1,2)))
    #plt.title("Channel2")
    #plt.matshow(cp.pull(pyr.get_all_channels(1)))
    #plt.title("allchannels level 1")
    #plt.show()

    # create source image from higher level of pyramid
    pic1 = pyr.get_all_channels(0)
    for i in xrange(10): smooth(pic1)
    plt.matshow(cp.pull(pic1)[:h/2,:w])
    ca = cp.dev_cuda_array_f(pic1.h,pic1.w,1)
    ca.assign(pic1)

    # create destination matrix
    pic0 = pyr.get(0)
    dst = cp.dev_matrix_rmuc(pic0.h,pic0.w*4) # uchar4

    # generate pixel classes and visualize
    cp.get_pixel_classes(dst,ca,1)
    tmp = cp.pull(dst)
    tmp = Image.frombuffer("CMYK", (pic0.w,pic0.h), cp.pull(dst).flatten(), "raw", "CMYK", 0, 1 ).resize((2*512,2*512), Image.NEAREST)
    tmp.show()
    print cp.pull(dst)
    plt.show()
예제 #5
0
파일: image_ops.py 프로젝트: 0rchard/CUV
def smooth(pic):
    ca = cp.dev_cuda_array_f(pic.h,pic.w,1)
    ca.assign(pic)
    cp.gaussian(pic,ca)
    ca.dealloc()
예제 #6
0
def smooth(pic):
    ca = cp.dev_cuda_array_f(pic.h, pic.w, 1)
    ca.assign(pic)
    cp.gaussian(pic, ca)
    ca.dealloc()