Esempio n. 1
0
    def __init__(self, context, flags, dim=None, dtype=None, hostbuf=None):
        if hostbuf != None:
            dim = (hostbuf.shape[1], hostbuf.shape[0])
            dtype = hostbuf.dtype
        else:
            if dim == None or dtype == None:
                raise ValueError("Dimensions and datatype required")

        pad = alignedDim(dim, dtype)

        if hostbuf != None:
            hostbuf = padArray2D(hostbuf, (hostbuf.shape[0], pad), "constant")
            cl.Buffer.__init__(self, context, flags, hostbuf=hostbuf)
        else:
            cl.Buffer.__init__(self, context, flags, size=np.dtype(dtype).itemsize * pad * dim[1])

        self.dim = dim
        self.dtype = dtype
Esempio n. 2
0
if img.mode != 'RGBA':
    img = img.convert('RGBA')

app = QtGui.QApplication(sys.argv)
canvas = CLCanvas(img.size)
window = CLWindow(canvas)

clContext = canvas.context
devices = clContext.get_info(cl.context_info.DEVICES)
queue = cl.CommandQueue(clContext, properties=cl.command_queue_properties.PROFILING_ENABLE)

shapeNP = (img.size[1], img.size[0])
shapeNP = roundUp(shapeNP, QuickBrush.lWorksize)
shapeCL = (shapeNP[1], shapeNP[0])

hImg = padArray2D(np.array(img).view(np.uint32).squeeze(), shapeNP, 'edge')

dImg = Image2D(clContext,
    cl.mem_flags.READ_ONLY,
    cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.UNSIGNED_INT8),
    shapeCL
)
cl.enqueue_copy(queue, dImg, hImg, origin=(0, 0), region=shapeCL).wait()
dBuf = Buffer2D(clContext, cm.READ_ONLY | cm.COPY_HOST_PTR, hostbuf=hImg)

dStrokes = Buffer2D(clContext, cm.READ_WRITE, shapeCL, dtype=np.uint8)

brush = QuickBrush(clContext, devices, dImg, dStrokes)
brush.setRadius(20)

label = 1
Esempio n. 3
0
np.set_printoptions(suppress=True)

src = Image.open("/Users/marcdeklerk/msc/code/dataset/processed/source/800x600/GT04.png")
if src.mode != 'RGBA':
    src = src.convert('RGBA')

width = src.size[0]
height = src.size[1]
shape = src.size
shapeNp = (src.size[1], src.size[0])
size = width * height

lWorksize = (16, 16)

hSrc = padArray2D(np.array(src).view(np.uint32).squeeze(), roundUp(shapeNp, lWorksize), 'edge')
dSrc = cl.Buffer(context, cm.READ_ONLY | cm.COPY_HOST_PTR, hostbuf=hSrc)
rgb = hSrc.reshape(-1, 1).view(np.uint8).astype(np.float32)[:, 0:3]

x0 = 0
x1 = 500
y0 = 200
y1 = 220

rect = (y1-y0, x1-x0)

nSamples = rect[0]*rect[1]
nIter = 65
nComp = 4
nDim = 3
Esempio n. 4
0
import Image
import os, sys
from clutil import roundUp, padArray2D
from Buffer2D import Buffer2D
import numpy as np
import pyopencl as cl
import time

cm = cl.mem_flags

img = Image.open("/Users/marcdeklerk/msc/code/dataset/processed/source/800x600/GT04.png")
if img.mode != 'RGBA':
    img = img.convert('RGBA')

shape = (img.size[1], img.size[0])
hImg = padArray2D(np.array(img).view(np.uint32).squeeze(), roundUp(shape, GraphCut.lWorksize), 'edge')

width = hImg.shape[1]
height = hImg.shape[0]
dim = (width, height)
shape = (height, width)

app = QtGui.QApplication(sys.argv)
canvas = CLCanvas(dim)
window = CLWindow(canvas)

context = canvas.context
queue = cl.CommandQueue(context)

dImg = Buffer2D(context, cm.READ_WRITE | cm.COPY_HOST_PTR, hostbuf=hImg)