Re: Converting Color to B&W



On Mon, 17 Jul 2006 11:31:02 +0200, Petr Hracek <petr hracek siemens com> wrote:

Hi,

0.3*cPixelOriginal[y*width+x]+0.59*cPixelOriginal[y*width+x]+0.11*cPixelOriginal[y*width+x]
          cPixelNew[y*width+x]=bw;

You aren't indexing your colour channels correctly. It should be

bw = 0.3*cPixelOriginal[(y*width+x) * 3]+0.59*cPixelOriginal[(y*width+x) * 3 + 1]+0.11*cPixelOriginal[(y*width+x) * 3 + 2];

you should also store it in all 3 channels

cPixelNew[(y*width+x) * 3]=bw;
cPixelNew[(y*width+x) * 3 + 1]=bw;
cPixelNew[*y*width+x) * 3 + 2]=bw;

Greets,

Lieven van der Heide

For converting from Color to B&W I used folowing technics, but
unfortunatelly it does not work.

//                           PixBuf
cPixelOriginal = pbPixbufOriginal->get_Pixels();
cPixelNew = (unsigned char *) malloc (width*height*sizeof(unsigned char));
rowstride = width *1; //for BW
int bw;

for(int y=0;y<height;y++)
{
    for(int x=0;x<width;x++)
    {
          ///                  red
   green                                                blue
          bw =
0.3*cPixelOriginal[y*width+x]+0.59*cPixelOriginal[y*width+x]+0.11*cPixelOriginal[y*width+x]
          cPixelNew[y*width+x]=bw;
    }
}
pbPixelNew=Gdk::Pixbuf::create_from_data(cPixelNew,Gdk::COLORSPACE_RGB,false,8,width,heigh,rowstride);
But unfortunatelly it does not work.

for display image I used method Gtk::Image image2; image2.set(pbPixelNew);

regards




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]