Image Operations
-
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
-
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
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.
-
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.
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
-
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
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.
-
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.
Hi Christian Can you show me more detail for Brightness, Contrast. Thank you very much. Ngo Khai Hoa
-
Hi Christian Can you show me more detail for Brightness, Contrast. Thank you very much. Ngo Khai Hoa
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.
-
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.
Thank you very much. But If I have some problems, I will ask you again (~_*) Ngo Khai Hoa
-
Thank you very much. But If I have some problems, I will ask you again (~_*) Ngo Khai Hoa
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.