Read large TIFF file into float array for CUDA

Hi All,

I am having an issue reading a TIFF file into a float array to ‘feed’ into my CUDA coda for image processing.

Is there any way that this can be done using CUDA? I can get the TIFF data into a BYTE array no problem but from there I am not having much luck.

I am using VC++.

Any help will be appreciated.

Thanks in advance.

AK

Load it as bytes, pass it likewise to CUDA kernel and convert any sample You take to float, before doing other operations.

MK

Hi MK,

Thank you very much for the response. Much appreciated. How would I go about doing the conversion from bytes to float in CUDA and vise verse from float to bytes after the rotation?

Thanks in advance.

AK

Hi,
You’ll need to know how many bytes there is per pixel, or even per pixel channel (R, G, B at least). You’ll also need to know how they are ordered within a pixel, in other words are they RGB, BGR or GBR etc. This stuff You’ll know form TIFF format specification.

CUDA code making the conversion is henceforth simple - take the appropiate number of bytes that is per pixel channel (usually a sizeof(unsigned char) == 1 byte per channel), devide it as float by the max number that there can be stored with the number of bytes plus 1 (1 byte means the max number is 255, +1 equals 256) and finally store such number in an appropiate float4 (or float3 provided there is no alpha channel) vector (R goes to X, G goes to Y, B goes to Z and A goes to W).

The other-way-conversion differs only with the fact that instead a float division You perform a multiplication.

A hopefully helpful pseudo-code below:

// Byte to float
byte2float(b,f) {
  f[X] = ((float)b[R] / 256.0f);
  f[Y] = ((float)b[G] / 256.0f);
  f[Z] = ((float)b[B] / 256.0f);
  f[W] = ((float)b[A] / 256.0f);
}

// Float to byte
float2byte(f,b) {
  b[R] = (byte)(f[R] * 256.0f);
  b[G] = (byte)(f[G] * 256.0f);
  b[B] = (byte)(f[B] * 256.0f);
  b[A] = (byte)(f[A] * 256.0f);
}

Cheers,
MK

Hi MK,

Sorry for the late response. Thank you very much! I will try this out as soon as I can and advise.

Thanks,

AK

If you just want to read tiff files,i’d like to suggest you create a tiff viewer
,which can read tiff and process tiff files.