I’m trying to tilt an image 90 degrees, currently I’m following the method presented here:
http://www.scribd.com/doc/66589491/Image-Rotation-Using-CUDA
My current code for the kernel is this:
__global__ void kernCuda(float *Source,float * Destination, int width)
{
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
int i = abs(x*cosf(theta)-y*sinf(theta));
int j = abs(x*sinf(theta)+y*cosf(theta));
if(x<width && y<width){
Destination[j*width+i]=Source[y*width+x];
}
}
The image tilts somewhat, however it seems like it is not correct, on top of that some pixels that are colored is now black(0). Any help would be appreciated
I assume that theta is a floating point number. So you are mixing floating point and integer variables. I would suggest you use the appropriate casts to make it work and look for rounding issues.
Secondly, in order to see whether your program works in general you can replace
cosf(theta)by 0 andsinf(theta)by 1.One third issue that I can see is that you only take one x,y value instead of looping over them by using a while loop. So in case your image dimension is larger than the kernel that you use, you will not get all your pixels.
Edit: I just had a brief look at the report. It really is not very good. If you want to just learn about CUDA I suggest you get the book called “CUDA by Example”.