示例#1
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()
示例#2
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()
示例#3
0
文件: image_ops.py 项目: 0rchard/CUV
def build_pyramid_GPU(pic,input_channels,pyramid_channels):
    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)
示例#4
0
def build_pyramid_GPU(pic, input_channels, pyramid_channels):
    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)