Get RGB pixels from input image and reconstruct an output image in opencv

前端 未结 4 2027
灰色年华
灰色年华 2020-12-22 07:04

I want to load the image in opencv and split the image into channels(RGB) and i want to increase any one of the colors and getting that corresponding output image.is there a

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 07:23

    Another option is to manually iterate on the pixels of the image and work on the channel that interests you. This will give you the flexibility to manipulate each channel individually or as a group.

    The following code uses the C interface of OpenCV:

    IplImage* pRGBImg = cvLoadImage("test.png", CV_LOAD_IMAGE_UNCHANGED); 
    int width = pRGBImg->width; 
    int height = pRGBImg->height;
    int bpp = pRGBImg->nChannels; 
    for (int i=0; i < width*height*bpp; i+=bpp) 
    {
      // For educational puporses, here is how to print each R G B channel:
      std::cout << std::dec << "R:" << (int) pRGBImg->imageData[i] <<  
                              " G:" << (int) pRGBImg->imageData[i+1] <<  
                              " B:" << (int) pRGBImg->imageData[i+2] << " "; 
    }
    

    However, if you want to add a fixed value to a certain channel you might want to check @Popovici's answer.

提交回复
热议问题