0

I'm using Libraw to a project which is about manipulating raw image files. I need to implement a feature that from a raw file I need to export an image just with the red pixels (and other 3 images for blue, green and green2 pixels). I've tried the 4channels sample but that just gave me a picture with a black and gray scale. I've tried modifying the code with this before export the image:

for (int c = 0; c < S.iwidth; c++){
    for(int r=0;r<S.iheight;r++){
        printf("Row:%d Column:%d Color:%d Max Rows:%d Max Col:%d\n",r,c,RawProcessor.COLOR(r,c),S.iheight,S.iwidth);
        //check if is a red pixel
        if(RawProcessor.COLOR(r,c)!=0){
            RawProcessor.imgdata.image[r*c][0] = 20000;
            RawProcessor.imgdata.image[r*c][1] = 0;
            RawProcessor.imgdata.image[r*c][2] = 0;
            RawProcessor.imgdata.image[r*c][3] = 0;
    }
}

This just give me a grayscale image with black dots in pixels which are not red. I want an image when you can see clearly the red color.

Can anyone help me with this problem?

Best regards

  • Obviously, your indices are not correct: E. g. both of r=10, c=12 and r=12, c=10 will access the same pixel; what you need instead is `index = r*width + c;` (with typical image layout of complete rows following one another; with such layout, you should consider swapping the loops for efficiency, profiting from data locality). – Aconcagua Jun 25 '18 at 09:33
  • Hey thanks for the help. I've tried what you said with this: – Nuno Tavares Jun 26 '18 at 08:49
  • int index = 0; for (int c = 0; c < S.iwidth; c++){ for(int r=0;r – Nuno Tavares Jun 26 '18 at 08:51
  • Although the image I get is still in grayscale and not in red color. Can someone tell me why? – Nuno Tavares Jun 26 '18 at 08:52
  • Not familiar with libraw - can it be that you defined greyscale already when opening the image? You might check the parameters there. What is the data type of the pixels' colour values? Integral values outside the range of [0;255] look strange to me as well as floating point values outside [0.0; 1.0]... – Aconcagua Jun 26 '18 at 10:00

0 Answers0