Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Qt5 C++ - How to split color image efficiently into 3 channels without using OpenCV

Qt5 C++ - How to split color image efficiently into 3 channels without using OpenCV

Scheduled Pinned Locked Moved Unsolved Game Development
7 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lynn00i
    wrote on last edited by
    #1

    I have successfully extract the 3 channels from a color image by looping each of the pixel. However, this is way too slow and would like to ask for other more efficient and faster way to do it?

    Below are my inefficient way of doing it:

    for (int y = 0; y < HEIGHT; ++y)
    {
    int x_stride = y * WIDTH;
    for (int x = 0; x < WIDTH; ++x)
    {
    int index = x_stride + x;
    QRgb rgb_1 = snap_buf_1.pixel(x, y);

        img_bit_red = qRed(rgb_1);
        img_bit_green = qGreen(rgb_1);
        img_bit_blue = qBlue(rgb_1);
    
        ucSnapBuffer1[0].GetBuffer_UNSAFE().data()[index] = img_bit_red;
        ucSnapBuffer1[1].GetBuffer_UNSAFE().data()[index] = img_bit_green;
        ucSnapBuffer1[2].GetBuffer_UNSAFE().data()[index] = img_bit_blue;
    }
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What data structure do you need to fill with these data ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lynn00i
        wrote on last edited by
        #3

        Hi,

        I would like to fill into an array of unsigned char.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then why not use memcpy ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Lynn00i
            wrote on last edited by
            #5

            Did not use memcpy because I need to take the correct color bit from the color image. I need to split all the 3 channels into 3 mono buffer. Can I use memcpy to achieve this? Sorry if I'm wrong as I'm not expert in image processing and Qt.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              No indeed since there's the split. But you can use pointer arithmetic to move around the data more efficiently.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Kent-DorfmanK Offline
                Kent-DorfmanK Offline
                Kent-Dorfman
                wrote on last edited by Kent-Dorfman
                #7

                op makes no mention of the format of the image data. That will dictate in large part how efficient the process can be made. The most efficient to do what he wants would be if the image is already in planar format, where the memory is a seriies of color planes. memory backed video hardware is often in planar format. If not in planar format then any real optimization will still involve addressing the image directly and bypassing the Qt pixel addressing operations, then using any available processor native multimedia instructions. I hope the op is comfortable with pointers. LOL

                At the very least, op should quit using array indexes and instead use pointer math to access array elements, as it is faster than array indexing.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved