R, G, B channels from RGB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koliva
    New Member
    • Jan 2009
    • 3

    #1

    R, G, B channels from RGB

    Hello,

    I have a .bmp image sequence. I need to read and convert the R, G, B components of all images in the sequence. I am following the classical way but it is too slow,

    Code:
    Color pixelcolor=mybmp->GetPixel(i,j);
    And also I need to convert bit depth from 24 to 15. I am again following the classical way, in a loop for each pixel, but again it is too slow.

    What is the fastest way to obtain these things?
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    I'd recommend you to do a search for "C++ bmp library" on the web. Things like these have been done before, and the results are usually better (don't let that stop you from trying to find a new way yourself though, there's always room for innovation).

    I've found with a list of libraries related to image processing here.

    Comment

    • RRick
      Recognized Expert Contributor
      • Feb 2007
      • 463

      #3
      If a standalone image processing program will suit your needs, Irfan view for windows is the best. Free, too.

      Image toolkits are good and numerous, but have their own overhead. I wanted to use ImageMagic, but found that I was stuck with their representation. This did not suit my application.

      This conversion/overhead might be the what's causing you trouble. GetPixel might be slowing you down. If you understand the underlying BMP structure, then you can speed things up by dealing with the data structure instead of pixel values. This puts more work on you, but the speed increases can be impressive.

      In the case of BMP images, once you get pass the header, the data is simply a list of color values. I don't believe it uses any compression. All the data can be read into a string array with a single io call. That will speed things up. Once the data is in the array, you just sequentially step through and convert the values. Now its up to you to know how the RGB are stored.

      As for the conversion from 24 bit color, remember that the 24 bit value is based on 3 independent colors (RGB). These 8 bit values can be converted separately. You can pre-compute a table that does this conversion, thus turning all the ugly math into a simple lookup in a table.

      Comment

      Working...