0

Firstly, I should say that I am not familiar with C++. My purpose is that. There is a function at Matlab imagesc. With a given input of 2d matrix that has double values of RGB it shows a RGB image. I want same at C++ and found that: Imagesc equivalent in C? it says that I can use CImg.

However I couldn't do it at CImg (I couldn't find anything at documentation and google)

My question: How can I show a RGB image with a given 2D matrix at CImg?

PS: Other libraries that CImg is welcome. I just need a simple and basic solution for my purpose.

EDIT 1: I have a Win7 Operating System and I use Visual Studio 2010.

EDIT 2: Solutions with other libraries is welcome.

Community
  • 1
  • 1
kamaci
  • 72,915
  • 69
  • 228
  • 366
  • 1
    It would help if you indicated what platform this is for. Or do you need it to be cross-platform? – paddy Sep 23 '12 at 21:45

2 Answers2

1

Why not using the CImg::display(); method ? It just display your image in an interactive viewer, just as Matlab does with imagesc.

CImg<double> matrix(200,200);  // Assume this is your matrix data.
matrix.display("My Matrix");
cjuliard
  • 154
  • 2
  • Should I construct my matrix as CImg type and can how can I convert my 2D double matrix to CImg type matrix? – kamaci Sep 24 '12 at 08:00
  • Depending on how your matrix data are stored. If you want to export it from Matlab, you may use the [dlmwrite](http://www.mathworks.fr/fr/help/matlab/ref/dlmwrite.html) command, then import it to CImg (CImg knows how to read .dlm files). – cjuliard Sep 24 '12 at 09:55
  • İt is a matrix at m C++ code and its type is not CImg as well. If you help about it it will be good. – kamaci Sep 24 '12 at 10:40
0

One of the methods for constructing a Cimg is from a memory buffer of values, where the value type is templated.

stark
  • 12,615
  • 3
  • 33
  • 50
  • I have edited my question. Can you explain more what you mean with that link? Let's assume that I have a variable named myMatrix (is a two dimensional matrix) and I filled it with double valuables. Can you write a piece of code how can I show it as an image as like Matlab? – kamaci Sep 24 '12 at 05:33
  • Basically, you can do : CImg<> mat(100,100); cimg_forXY(mat,x,y) mat(x,y) = myMatrix[y][x]; – cjuliard Sep 24 '12 at 09:58