cancel
Showing results for
Did you mean:

# Archives Discussions

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_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

Tags (3)
1 Solution

Accepted Solutions

## Re: Relative position between 2 images for interpolation?

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 )

2 Replies

## Re: Relative position between 2 images for interpolation?

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 )

Journeyman III