Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Image Operations

Image Operations

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 2 Posters 0 Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Tran Hoang Chuong
    wrote on last edited by
    #1

    Hi all, In my application, I develop a class CDIB for displaying the image. And now, I'd like to add some method such as: Brightness, Contrast, Colorize. But I don't know. Can you help me? Thanks in advance for your reading. Ngo Khai Hoa

    C 1 Reply Last reply
    0
    • T Tran Hoang Chuong

      Hi all, In my application, I develop a class CDIB for displaying the image. And now, I'd like to add some method such as: Brightness, Contrast, Colorize. But I don't know. Can you help me? Thanks in advance for your reading. Ngo Khai Hoa

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      To do this you need direct pixel access, which I assume your class has, i.e. I assume your DIB is a CDIBSection. Brightness is easy, just add an amount to each of the RGB values for each pixel. Contrast involves trending high values up and low values down. What does colorise mean ? The pointer to the pixel data is passed into the call that creates the DIBSection. If you want more info on different filters, I'd be happy to dig up something. If you're remotely serious you should buy Windows Graphics Programming by Feng Yuan, which contains heaps of info on filters ( it's where I initially learned about them ). There are also some newsgroups worth reading. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

      T 1 Reply Last reply
      0
      • C Christian Graus

        To do this you need direct pixel access, which I assume your class has, i.e. I assume your DIB is a CDIBSection. Brightness is easy, just add an amount to each of the RGB values for each pixel. Contrast involves trending high values up and low values down. What does colorise mean ? The pointer to the pixel data is passed into the call that creates the DIBSection. If you want more info on different filters, I'd be happy to dig up something. If you're remotely serious you should buy Windows Graphics Programming by Feng Yuan, which contains heaps of info on filters ( it's where I initially learned about them ). There are also some newsgroups worth reading. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

        T Offline
        T Offline
        Tran Hoang Chuong
        wrote on last edited by
        #3

        Hi Christain, First at all, thanks for your answer. Colorize means the image is drawed by one color. It is same as Colorize Function in ACDSee. And my mind that I'd like do something same as image processing functions of WinWord. Thanks in advance. Ngo Khai Hoa

        C 1 Reply Last reply
        0
        • T Tran Hoang Chuong

          Hi Christain, First at all, thanks for your answer. Colorize means the image is drawed by one color. It is same as Colorize Function in ACDSee. And my mind that I'd like do something same as image processing functions of WinWord. Thanks in advance. Ngo Khai Hoa

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Oh, you mean make it all red, green OR blue ? That's easy. Step through the pixels and turn the two colours you don't want to 0. It's useful to actually have a filter that allows you to set a boost or cut to each colour channel. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

          T 1 Reply Last reply
          0
          • C Christian Graus

            Oh, you mean make it all red, green OR blue ? That's easy. Step through the pixels and turn the two colours you don't want to 0. It's useful to actually have a filter that allows you to set a boost or cut to each colour channel. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

            T Offline
            T Offline
            Tran Hoang Chuong
            wrote on last edited by
            #5

            Hi Christian Can you show me more detail for Brightness, Contrast. Thank you very much. Ngo Khai Hoa

            C 1 Reply Last reply
            0
            • T Tran Hoang Chuong

              Hi Christian Can you show me more detail for Brightness, Contrast. Thank you very much. Ngo Khai Hoa

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              If you're stepping through a 24 bit image, then it's like this

              unsigned char * pPixel = pMyArray;

              for (int y = 0; y < m_Height; y++)
              for (int x = 0; x < m_Width; x++)
              {
              pPixel[0] += m_Brightness;
              pPixel[1] += m_Brightness;
              pPixel[2] += m_Brightness;

                  pPixel += 3;
              

              }

              Basically unsigned char runs from 0-255, so you don't need bounds checking. We step through all the bits and add the brightness value, which can be negative. The only thing that is worth mentioning, although it doesn't matter in this case, is that Windows bitmaps are stored as BGR, not RGB. Here is a contrast filter: register double red, green, blue; register double csupp = contrast * (m_offset - 125.0) + 125.0; for (int y = 0; y < pBmpDest->GetHeight(); ++y) { // For each line register BYTE * pSrcPixel = pSrcLines[y]; register BYTE * pDstPixel = pDstLines[y]; for (register int x = 0; x < destWidth; ++x) { // Formel für Kontrastberechnung: // v = (contrast * (v - 125.0 + m_offset) + 125.0); red = contrast * ((double) (pSrcPixel[RGBA_RED])) + csupp; green = contrast * ((double) (pSrcPixel[RGBA_GREEN])) + csupp; blue = contrast * ((double) (pSrcPixel[RGBA_BLUE])) + csupp; if(red >= 255.0) pDstPixel[RGBA_RED] = (BYTE) 255; else if (red < 0.0) pDstPixel[RGBA_RED] = (BYTE) 0; else pDstPixel[RGBA_RED] = (BYTE) red; if(green >= 255.0) pDstPixel[RGBA_GREEN] = (BYTE) 255; else if (green < 0.0) pDstPixel[RGBA_GREEN] = (BYTE) 0; else pDstPixel[RGBA_GREEN] = (BYTE) green; if(blue >= 255.0) pDstPixel[RGBA_BLUE] = (BYTE) 255; else if (blue < 0.0) pDstPixel[RGBA_BLUE] = (BYTE) 0; else pDstPixel[RGBA_BLUE] = (BYTE) blue; pSrcPixel += inc; pDstPixel += inc; } } All the bounds checking is superfluous as I mentioned before. I got this from paintlib, which is available from www.paintlib.de, and has a lot of filter code in it. I'd be happy to send you other filters I have written, including smooth, sharpen, emboss, etc. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

              T 1 Reply Last reply
              0
              • C Christian Graus

                If you're stepping through a 24 bit image, then it's like this

                unsigned char * pPixel = pMyArray;

                for (int y = 0; y < m_Height; y++)
                for (int x = 0; x < m_Width; x++)
                {
                pPixel[0] += m_Brightness;
                pPixel[1] += m_Brightness;
                pPixel[2] += m_Brightness;

                    pPixel += 3;
                

                }

                Basically unsigned char runs from 0-255, so you don't need bounds checking. We step through all the bits and add the brightness value, which can be negative. The only thing that is worth mentioning, although it doesn't matter in this case, is that Windows bitmaps are stored as BGR, not RGB. Here is a contrast filter: register double red, green, blue; register double csupp = contrast * (m_offset - 125.0) + 125.0; for (int y = 0; y < pBmpDest->GetHeight(); ++y) { // For each line register BYTE * pSrcPixel = pSrcLines[y]; register BYTE * pDstPixel = pDstLines[y]; for (register int x = 0; x < destWidth; ++x) { // Formel für Kontrastberechnung: // v = (contrast * (v - 125.0 + m_offset) + 125.0); red = contrast * ((double) (pSrcPixel[RGBA_RED])) + csupp; green = contrast * ((double) (pSrcPixel[RGBA_GREEN])) + csupp; blue = contrast * ((double) (pSrcPixel[RGBA_BLUE])) + csupp; if(red >= 255.0) pDstPixel[RGBA_RED] = (BYTE) 255; else if (red < 0.0) pDstPixel[RGBA_RED] = (BYTE) 0; else pDstPixel[RGBA_RED] = (BYTE) red; if(green >= 255.0) pDstPixel[RGBA_GREEN] = (BYTE) 255; else if (green < 0.0) pDstPixel[RGBA_GREEN] = (BYTE) 0; else pDstPixel[RGBA_GREEN] = (BYTE) green; if(blue >= 255.0) pDstPixel[RGBA_BLUE] = (BYTE) 255; else if (blue < 0.0) pDstPixel[RGBA_BLUE] = (BYTE) 0; else pDstPixel[RGBA_BLUE] = (BYTE) blue; pSrcPixel += inc; pDstPixel += inc; } } All the bounds checking is superfluous as I mentioned before. I got this from paintlib, which is available from www.paintlib.de, and has a lot of filter code in it. I'd be happy to send you other filters I have written, including smooth, sharpen, emboss, etc. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

                T Offline
                T Offline
                Tran Hoang Chuong
                wrote on last edited by
                #7

                Thank you very much. But If I have some problems, I will ask you again (~_*) Ngo Khai Hoa

                C 1 Reply Last reply
                0
                • T Tran Hoang Chuong

                  Thank you very much. But If I have some problems, I will ask you again (~_*) Ngo Khai Hoa

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  By all means :) Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups