Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Java - showBitPlanes

// the input it must be a b/w image

   1  
   2  public BufferedImage showBitPlanes(BufferedImage bi, int lv)
   3  	{
   4  		int level = 0;
   5  		
   6  		switch(level)
   7  		{
   8  			case 0:
   9  				level = 128;
  10  				break;
  11  			case 1:
  12  				level = 64;
  13  				break;
  14  			case 2:
  15  				level = 32;
  16  				break;
  17  			case 3:
  18  				level = 16;
  19  				break;
  20  			case 4:
  21  				level = 8;
  22  				break;
  23  			case 5:
  24  				level = 4;
  25  				break;
  26  			case 6:
  27  				level = 2;
  28  				break;
  29  			case 7:
  30  				level = 1;
  31  				break;
  32  			default:
  33  					return null;
  34  		}
  35  		
  36  		int width = bi.getWidth();
  37  		int height = bi.getHeight();
  38  		
  39  		BufferedImage img = new BufferedImage(width, height, bi.getType());
  40  		
  41  		for(int x=0; x<width; x++)
  42  			for(int y=0; y<height; y++)
  43  				img.setRGB(x, y, ((bi.getRGB(x, y) & level)/level)*255);
  44  		
  45  		return img;
  46  	}

Matlab - showBitPlanes

   1  
   2  % Ritorna i Bit Plabes dell'immagine a toni di grigio
   3  
   4  function showBitPlanes(img)
   5  
   6      imgGray = double( rgb2gray(img) );
   7      titleString = 'bit planes ';
   8      
   9      % MSB ... LSB
  10      k = 128;
  11      
  12      for b=1:8
  13          
  14          subplot(2, 4, b);
  15          imshow( (bitand(imgGray, k) / k) * 255 ); % Fa un and dei bit
  16          title([titleString int2str(b-1)]);
  17          k = k/2; % Shifta di 2 i bit
  18          
  19      end;
  20      
  21  return;
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS