Displaying Grayscale image using CImg Cimg wih Cuda C

Hi…
I am newbie to cuda …i need to display a grayscale image from a matrix…i successfully formed the image in C++(.cpp file) using CImg(STL header) library…however when i tried to use CImg library in Cuda host code (.cu file) it gives a strange error …i have read somewhere that STL headers cannot be added to cuda code…

The error i am getting is as shown(Using VS 2008 on Win 7)

[ error: identifier “_ZN12cimg_library4cimg9superset2IfffE4typeE” is undefined]

Is there a way i can use CImg library with cuda…else what is the most easiest way to form an image from a 2D matrix in cuda …

Thanks …

Using large libraries in cuda code is a bad idea. Rather, keep the libraries in your C++ files, and copy the raw data (i.e. the float array or w/e type you’re using) to the device memory, process it in your kernel, then copy it back to your host memory, then use it with your library in whatever application you’re doing.

As for the “easiest way to form an image from a 2D matrix in cuda”, I’d advise OpenCV - it’s easy to bind raw data to their image types (Mat if you’re using C++ OpenCV), and displaying the image is much easier than your other alternatives (DirectX or OpenGL). Of course, getting OpenCV setup can take some time, but it’s quite useful once you do. I tried using CImg for a while in the past, and found it to be rather unwieldy.

Hope this helps, ask if you need any clarification

-Al

Thanks for the reply…i initially tried for openCV but having difficulty in its installation…its strange that unless i dont use cv.h it doesnt give any error while compiling its examaples(for the first 2 examples using only highgui.h)…however when i try to use cv,h, it gives numerous errors such as:

[b]

Error 1 error C2146: syntax error : missing ‘;’ before identifier ‘xpv_cur’

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [/b]

please help if u can …

And also when i try to use CImg library using host and device code in different(.cpp and .cu) files…its building successfully however, the line in .cpp file at which it tries to display the image …it doesnt shows the image and waits indefinitely…the program doesnt hang the system…just that i think it is having some issues with cuda build rules though the code for CImg library is in .cpp file and i believe .cpp files are compiled using C/C++ ruless…please enlighten me on this topic as well…

Waiting for reply…

I’m not too sure about the OpenCV errors you’re seeing; did you follow the online documentation for setting it up?
I highly doubt the cuda build rules would be the culprit for your CImg problem, although it’s hard to tell without seeing the actual code. Would it be possible for you to post the relevant portions?

FOR OPENCV problem…i have followed the step as given online also when i perform same steps on my laptop it works…though the problem is i want it to work at the workstation having the GPU so i can use it in my cuda program.0.

FOR CIMG problem…i am attaching .cpp file of code
Bp.cpp (646 Bytes)

Hard to say without knowing what the Backprojection function does; just out of curiosity, if you run this code, does it display an image that’s half black on the left and white on the right half?

#include <stdlib.h>

#include <stdio.h>

#include "CImg.h" 

using namespace cimg_library; 

const int height = 400;

const int width = 400;

int main(void) {

	

 	float *img = (float *)malloc(height * width * sizeof(float));

	for (int i = 0; i < height; i++){

		for (int j = 0; j < width/2; j++){

			img[i*width+j] = 0;

		}

		for (int j = width/2; j < width; j++){

			img[i*width+j] = 1;

		}

	}

	

	CImg<float> outImg(height, width); 

	for (int i = 0; i < height; i++){

		for (int j = 0; j < width; j++){

			outImg[i*width+j] = img[i*width+j];

		}

	}

	outImg.display();

}