1

I'm using the Boost-GIL library for some image-processing tasks. First, I color separate the image into RGB channels and perform operations on each channel. Something odd came to my notice in terms of the reversibility of the operation. The principle of reversibility would imply if we re-combine the channels to re-construct the original image we should get back the original image without any difference from the original. Unfortunately, I do not see that behavior. I've attached the image pair as an illustration of the problem. The left one is the original and the right one is a re-combined image. There is higher precedence of blue color. I used the Mathematica ColorCombine function for the re-combination operation and as a cross-check I used Mathematica ColorSeparate function to perform the same color separation operation. After applying ColorCombine on the ColorSeparated channels, I get back the original image without a single pixel of difference. Also, I verified this on two separate images and observed that only the blue channel mismatches with the Mathematica implementation. Since color-separation is a very fundamental operation it should be fixed immediately if there are issues in the library. My code to color separate from a raw ".jpg" image is given below.

boost::gil::rgb8_image_t img;
std::string image_path="Eiffel_towner.jpg";
boost::gil::read_image(image_path.c_str(), img, boost::gil::jpeg_tag());
auto pixel = std::move(img_view(x,y));
boost::gil::rgb32f_pixel_t pixel_f(pixel);
float pixel_red = boost::gil::at_c<0>(pixel_f);
float pixel_green = boost::gil::at_c<1>(pixel_f);
float pixel_blue = boost::gil::at_c<2>(pixel_f);

Eiffel Tower

The channels were saved as data matrices (e.g. "Eiffel_red.dat", "Eiffel_green.dat", "Eiffel_blue.dat") and imported to Mathematica as a color table for each channel.

red_channel = Import["Eiffel_red.dat","Table"];
green_channel = Import["Eiffel_green.dat","Table"];
blue_channel = Import["Eiffel_blue.dat","Table"];
composedImage=ColorCombine[{red_channel//Image, green_channel//Image, blue_channel//Image},"RGB"]//ImageAdjust;
jtbandes
  • 115,675
  • 35
  • 233
  • 266
Pal
  • 989
  • 10
  • 23
  • You didn’t include the code to put the channels back into an RGB image. – Cris Luengo Nov 20 '21 at 23:29
  • Please see the re-combination code – Pal Nov 21 '21 at 22:29
  • Well, if you apply `ImageAdjust`, of course the image will look different. You are explicitly modifying it! – Cris Luengo Nov 21 '21 at 22:36
  • Agreed but ImageAdjust only changes the global normalization, not a particular channel. And I did the same with the original image as well as the ColorSepated channels using Mathematica. I explicitly compared each channel between Mathematica and boost::gil. **Red** & **Green** channel matrix values are identical and only the **Blue** channels are different. The same image re-combination code using Mathematica separated channels produces the original image ditto and verified this for two images including the one given above. – Pal Nov 21 '21 at 22:42

0 Answers0