Hello

I`ve made a little testscript to test the bilinear interpolation of image2d_t-objects.
The script:

import pyopencl as cl
import numpy as np
import cv2 # OpenCV 2.3.1

Img = cv2.imread("Test.jpg") # read Image with width = 709px and height = 472px
Img = cv2.cvtColor(Img, cv2.COLOR_BGR2GRAY)    # convert to grayscale
print Img.shape    # prints: (472L, 709L)
OutImg = np.empty(shape=Img.shape, dtype=np.uint8) # create Output-Image

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

mf = cl.mem_flags
dev_Img = cl.Image(ctx,
                    mf.READ_ONLY | mf.COPY_HOST_PTR,
cl.ImageFormat(cl.channel_order.R, cl.channel_type.UNSIGNED_INT8),
                    hostbuf=Img)
dev_OutImg = cl.Image(ctx,
                    mf.WRITE_ONLY | mf.ALLOC_HOST_PTR,
cl.ImageFormat(cl.channel_order.R, cl.channel_type.UNSIGNED_INT8),
                    shape=Img.shape)

prg = cl.Program(ctx, """
const sampler_t smp = CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR | CLK_ADDRESS_NONE;

__kernel void ImageCopy(__read_only image2d_t Img, __write_only image2d_t Out)
    {
        const int2 dims = get_image_dim(Img);
        const int2 Coords = (int2)(get_global_id(0), get_global_id(1));
const float2 NormCoords = (convert_float2(Coords) + (float2)(0.5f) + (float2)(0.4f)) / convert_float2(dims); // = (x + 0.5 + 0.4)/h ; (y + 0.5 + 0.2)/w

        uint4 Pixel = read_imageui(Img, smp, NormCoords);
        write_imageui(Out, Coords, Pixel);
    }
    """).build()

prg.ImageCopy(queue, Img.shape, None, dev_Img, dev_OutImg)
cl.enqueue_read_image(queue, dev_OutImg, (0, 0), OutImg.shape, OutImg).wait()
cv2.imwrite("Out.jpg", OutImg)

The problem: This is the input-image: http://s7.directupload.net/file/d/2692/hkbb8pn2_jpg.htm And when i add a small offset to the image-coords ( here 0.4f) the output is something like this: http://s1.directupload.net/file/d/2692/xuqzmtp4_jpg.htm When i don't add this little offset or use CLK_FILTER_NEAREST then the result is o.k. The effect is proportional to the ratio of the image height and width and the absolute value of the offset. Also only the offset in image-width direction has a influence ( if i add (float2)(0.4f,0.0f) the result is nearly o.k. - 4 diagonal pixel-bands remains)
A quadratic image produces allways the correct output.
The script runs on a NVidia NVS3100M with image-support.
I`ve tried to swap the Image-shapes and Coords in all ways in and outside the kernel - no good result.

Hope that somebody can guide me back to the right way

Thx Sylvan

_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to