how to display only red channel QImage using a QPixmap formed using RGB8 QImage?
I have RBG image frames coming form the camera. I have formed the RGB8 QImage and QPixmap from the QImage. I have to display only the Red channel image from this QPixmap. How can I do that?
@hardikgarg19 presently, I am doing it like below:
for ( int row = 0; row <widthImg; ++row )
for ( int col = 0; col < heightImg; ++col )
QColor clrCurrent( imgEdge.pixel( row, col ) );
Is there any other way to do it that saves some computation?
If RGB8 is indexed then you could modify the color map instead. Go and set all the G B values of colormap to 0. If its not indexed then doing each pixel is the best you can do I think.
There might be a quicker way doing some kind of memory lookup and modifying 2 bytes our of every three. This would reduce function calls. However, you will need to determine how the memory is structured.
@fcarney thank you for your reply. Can you please tell me how can I set the B and G to 0 for the color map without the for loop?
Is the image indexed? What is the format?
@fcarney Please tell me what is "indexing" here?
The format is RGB8 (QImage::Format_RGB888)
It is not indexed:
So you are stuck with looping through the data like you already figured out. The indexed format would have been: QImage::Format_Indexed8
If you can get access to the memory itself (not sure how do to that) you could set the bytes in a loop that has less function calls. It would require pointer math.
You can compose a new QImage using the
Create a fully red QImage of the same size of the frames you are getting, then compose it with your red frame and show the result. You should get what you want.
@fcarney pixel by pixel processing is bringing time lag in the video. So, I have included opecv library in the project and used the opencv function to extract the red channel.
Thank you for your reply. I will try this method.