View Full Version : opencl, images,samplers and interpolation

11-28-2012, 04:27 AM
I'm studing opencl, in particular image processing.
is possible to create a sampler that interpolates values from two color: start and end color and the normalized coordinates from 0 to 1 in automatic mode?
I wish use bilinear interpolation.
I must create a texture with interpolated colors or is possible to set the bilinear interpolation in the creation of the sampler?

next, is possible use integer coordinates(for ex from 0px to 600px) and interpolation in the same mode?


11-28-2012, 05:39 AM

to clarify this. You want to have an image of e.g. 600x600 pixels and you want to set (0:0) to white and (1.0:1.0) to Red and the sampler should interpolate all the values in between? Or do you want to interpolate between Pixel (0.5:0.5) and (0.6:0.5) in a bicubic way?

In general it is possible to generate an interpolating sampler like in openGL. Check Chapter 5.5 in the openCL 1.1 spec or above if you need 1.2 spec. In 1.1 there is only non or linear interpolation available.

And you don't have to use normalized coordiantes to access the image. This is also described in the spec.


11-28-2012, 08:49 AM
You want to have an image of e.g. 600x600 pixels and you want to set (0:0) to white and (1.0:1.0) to Red and the sampler should interpolate all the values in between?

yes .

11-28-2012, 09:08 AM
you could create an image containing of 4 pixels, with your defined colors. After upscaling that with bicubic interpolation you should get what you want. but again, this is not available in opencl 1.1

You could write a kernel that computes that image quite easy like in that pseudocode. thats just for x dimension. so you need to interpolate these 4 values correctly with the global id's of both dimensions

__kernel interpolate(inImage2x2, outImage600x600)
outimage[workitemindex] = inimage[0,0] * globalid(0) + 1.- inimage[0,1] * (globalsize(0) - globalid(0));


12-01-2012, 01:56 PM
clint, the OP asked about bilinear interpolation, not bicubic.

OpenCL supports bilinear interpolation and can use normalize or unnormalized coordinates. As I interpret the original posting, the answer is "yes, OpenCL can do that". Read the section of the specification regarding samplers. You want to use read_imagef with float coordinates. The underlying image can be 8-bit or other formats but this API already returns a float4 pixel and can do bilinear interpolation.

12-03-2012, 04:39 AM
thanks, i saw in the specification 1,1 and the CLK_FILTER_LINEAR parameter sets the linear interpolation for the sampler_t, but :
1)how i can set the start color and the final color?
2)what kind of image i must read with the sampler_t and what are the resolution if i use only two point(the start color and the final color)?
Is possible using only two color?
I'm sorry, but i don't understand .

12-05-2012, 09:54 AM
If you just want a grayscale with startcolor white, endcolor black, use an 1D kernel, pass the thwo colors and execute each item to divide the color. Or create an 1D image with only two pixels and interpolate them to a larger resolution.

12-06-2012, 07:29 AM
Is possible create a four color interpolation in a rectangle , one interpolation for the x and one interpolation for the y.
My goal is to take two color : from color A to color B and find the distance with the difference of B -A.

Is an idea ,I wish do it for manage the collisions with opencl of a world in opengl.
In theory i can do the same in 3d ,
I save for each boundingbox the interpolated color of his position(under there is the interpolated image that have an interpolate color based on the distance from x and y)and use a sort (parallel like radixsort)algorithm for find all the possible collision that are the groups of more similar color , if two object have the same color collide.
Then i can move the moved entities and simply refresh a part or the entire world with a sort algorithm in opencl.
Is also usefull for know the neighbors entities of a light source for apply the light only at a range of entities at distance -RANGE- ecc...
Is only an idea.

12-09-2012, 03:50 AM
the idea is completely wrong.
don't has a sense look up a color from an iterpolation , when i have the x and the y , but is sufficent create a sort algorithm with an index that has two or more values, exist sort algorithms that do that?(the sort of a set with more than one index?)