next up previous contents
Next: Brightening: Up: Image Processing using GTK. Previous: Grey Scaling.   Contents

Bitplaning:

Every pixel is make up of 3 bytes which contribute various values to the picture, which can be ascertained from the weight of their pixels. As we can guess the MSB has the greatest weight and the others carry lesser weight, in the binary sequence.

By finding the image formed by the LSB bit to the MSB bit we can appreciate the levels of importance of a picture in its bytes.

Figure: Kathakali, on the MSB bit 7
Image kathakali_colorplane

	mask=(0xff & (1<<plane));

        pixel.red   &=mask;
        pixel.green &=mask;
        pixel.blue  &=mask;

Calling the function colorbitplanize_picture(pb,7); with the bit plane yields the results as shown. The plane 7 [MSB] is the highest while plane 0 is the lowest [LSB].

#include<gtk/gtk.h>

void colorbitplanize_picture(GdkPixbuf *pb,guchar plane)
{ 
  int ht,wt;
  int i=0,j=0;
  int rowstride=0;  
  int bpp=0;
  guchar mask=0;
  gchar *pixel;


  if(gdk_pixbuf_get_bits_per_sample(pb)!=8)   //we handle only 24 bit images.
  	return;                               //look at 3 bytes per pixel.

  bpp=3;	         	  //getting attributes of height,
  ht=gdk_pixbuf_get_height(pb);   //width, and bpp.Also get pointer
  wt=gdk_pixbuf_get_width(pb);	  //to pixels.
  pixel=gdk_pixbuf_get_pixels(pb);
  rowstride=wt*bpp;

  mask=(0xff&(1<<plane));

  for(i=0;i<ht;i++)		//iterate over the height of image.
    for(j=0;j<rowstride;j+=bpp)   //read every pixel in the row.skip
				//bpp bytes 
      {	      
	//find avg of the pixel to grey it.

	pixel[i*rowstride + j+0]&=mask;
	pixel[i*rowstride + j+1]&=mask;
	pixel[i*rowstride + j+2]&=mask;
      }  
  return;
}

% <!-- provide link here-->
% complete working example with glue code in example_colorplane.c



Muthiah 2004-06-04