cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

ash
Journeyman III

Relative position between 2 images for interpolation?

Hi everybody,

I want to change an image's scale.

I read some theory about bilinear interpolation and wanted to use it in OpenCL.

So my images are CL_FLOAT in greyscale - CL_LUMINANCE. And my sampler is described as following :

sampler_t smp = CLK_NORMALIZED_COORDS_FALSE |//Natural coordinates

CLK_ADDRESS_CLAMP |//Clamp to zeros

CLK_FILTER_LINEAR;//Linear

But I get different values compared to the CPU implementation.

My question is when you're looking for the value of a pixel in the destination image, how do you find the position in the source image.

Because each image has its own point of origin ( 0,0) which is the top left corner. How do you know the relative position between 2 images?

Best regards,

ash

0 Likes
1 Solution
soylentgraham
Adept II

Ignoring...

But I get different values compared to the CPU implementation.

If I understand right, what you want to do is simply convert coordinates from one space (destination image) to another space (source image).

int DestX = 10;

int DestY = 10;

You should normalise the coordinates so you can turn them into src image coords

int DestWidth = 200;

int DestHeight = 200;

float NormX = DestX / DestWidth;

float NormY = DestY / DestHeight;

Then convert to source-image space

int SrcWidth = 100;

int SrcHeight = 100;

NormX *= SrcWidth;

NormY *= SrcHeight;

Now your destination coordinates are in screen space.

float4 SrcColour = ReadImage( SrcImage, NormX, NormY );

WriteImage( DestImage, DestX, DestY, SrcColour );

This would be easy peasy to make into an opencl kernel.

As for the bilinear filtering, the ReadImage() would take care of that when sampling sub-pixels. (eg. 5.3f x 5.3f )

View solution in original post

0 Likes
2 Replies
soylentgraham
Adept II

Ignoring...

But I get different values compared to the CPU implementation.

If I understand right, what you want to do is simply convert coordinates from one space (destination image) to another space (source image).

int DestX = 10;

int DestY = 10;

You should normalise the coordinates so you can turn them into src image coords

int DestWidth = 200;

int DestHeight = 200;

float NormX = DestX / DestWidth;

float NormY = DestY / DestHeight;

Then convert to source-image space

int SrcWidth = 100;

int SrcHeight = 100;

NormX *= SrcWidth;

NormY *= SrcHeight;

Now your destination coordinates are in screen space.

float4 SrcColour = ReadImage( SrcImage, NormX, NormY );

WriteImage( DestImage, DestX, DestY, SrcColour );

This would be easy peasy to make into an opencl kernel.

As for the bilinear filtering, the ReadImage() would take care of that when sampling sub-pixels. (eg. 5.3f x 5.3f )

0 Likes

Yeah got it, quite a dumb question in fact.

Sorry for the bother and thanks!

0 Likes