0

Using the CImg image processing library, I am trying to achieve something rather trivial. I want to do some complex modification (including intermediate steps and copies) of only the intensity channel of an HSI image. At the moment my approach is to separate the intensity channel and work on it. However, at the end I would somehow have to feed the result back to the original image - and I don't know how to achieve this.

As you can see in my code example below I tried by converting my modified intensity result back to a single channel unsigned char CImg intensity_result and simply assigning it to the intensity channel of the original image. But when I try to display the result, the program crashes saying:

... CImg::HSItoRGB(): Instance is not a HSI image.

CImg<unsigned char> image = CImg<>("pic_small.jpg").normalize(0,255);
CImg<> HSIimage = image.get_RGBtoHSI();
CImg<> intensity = HSIimage.get_channel(2);

// ... intensity_modified = .... (intensity)

CImg<unsigned char> intensity_result = intensity_modified.get_normalize(0,255);
HSIimage.channel(2) = intensity_result;
HSIimage.get_HSItoRGB().display();
Jakob S.
  • 1,851
  • 2
  • 14
  • 29

1 Answers1

1

Use CImg<T>::draw_image() to draw an image into (the portion) of another one:

CImg<> HSI, I;  // Assuming these are already filled images.
HSI.draw_image(0,0,0,2,I); // Put content of I into HSI (at channel #2).
bvalabas
  • 116
  • 1