Bit phase Slicing

edited January 2017 in Questions about Code
        PImage img;
        int[][] msb;
        int[][] lsb; 

        void setup() {
          size(300, 500); // same width, twice the height
          img = loadImage("women.gif");
          println(img.width, img.height);
          msb = new int[img.width][img.height];
          lsb = new int[img.width][img.height];
          noLoop();
        }

        void draw() {
          image(img, 0, 0);
          loadPixels();
          int x=0,y=0;
          img.loadPixels();
          for (int i = 0 ; i < img.width  ; i++) {
            for(int j=0;j<img.height;j++){

              int loc  =  i+j*img.width;
              int Pixels = img.pixels[loc] & 0xff;
              msb[i][j] = (Pixels >> 23) &0x1 ;
              lsb[i][j] = Pixels & 0x1;

              pixels[loc+(img.width * img.height)] = 0xff000000|msb[i][j] << 16 | msb[i][j] << 8|msb[i][j] & 0xff; 


            }
            }
          // debug

           for (int i = 0 ; i < img.width  ; i++) {
            for(int j=0;j<img.height;j++){
            print(msb[i][j]);
            }
        println("\n");  
        }

          updatePixels();
        }

Answers

  • Pls check this code ?

  • Does it work? If not, in which way does it not work?

  • No it is showing the blank image what i am doing is i am getting all the most significant bit and least significant bit and making the matrix of it then i am updating the the pixels with most significant bit And acc. to bit phase slicing if i display the most significant bit it will show the actual image but the image would compress a little bit actually it is showing black image .

  • int Pixels = img.pixels[loc] & 0xff;
    

    the mask here is limiting Pixels to the lower 8 bits. your msb will always be 0

    you will end up, at best, with some blue.

    warning: line 36 might crash processing. it doesn't like lots of output. and that's lots of output

  • How to resolve this problem

  • msb[i][j] = (Pixels >> 7) & 0x1 ;
    

    this change to line 24 should fix that. it's using only the blue channel, assuming it's greyscale again.

    btw, uppercase letters, like Pixels, usually denote class names. calling a member variable Pixels is confusing.

  • Nop its same

  • but right shift by 7 won't give us most significant bit .

  • but only 8 bits are significant because r, g and b are all the same for greyscale.

  • post the image you're using so we're all using the same data

  • that's fine with my last change.

    only what you're doing is setting pixels to either 0 or 1, absolutely black or ever so slightly less than absolutely black, so you can't see a thing

    try this

      pixels[loc + (img.width * img.height)] = 
        0xff000000
        | (msb[i][j] << 22)
        | (msb[i][j] << 14)
        | (msb[i][j] << 6);
    

    which sets things to 0 or 0x404040 depending on the msb of the input

  • it should show us image but their is nothing but shades and in bit phase slicing msb always display the actual image

  • edited January 2017

    do you have a link to somewhere that describes 'bit phase slicing'?

  • http://www.ft.unicamp.br/docentes/magic/khoros/html-dip/c4/s12/front-page.html koogs can u suggest me any book on computer vision related to this plateform only

  • edited January 2017

    ok, think i've got it now...

    int plane = 3; // change this to bit plane number 0 - 7
    
    void draw() {
      image(img, 0, 0);
      loadPixels();
      img.loadPixels();
      int imgSize = img.width * img.height;
      int out = 0;
      int mask = 0x1 << plane;
    
      // all pixels
      for (int i = 0; i < imgSize; i++) {
        if ((img.pixels[i] & mask) != 0) {
          out = 0xffffffff; // white
        } else {
          out = 0xff000000; // black
        }
        pixels[i + imgSize] = out;
      }
      updatePixels();
    }
    

    that woman image is a bit odd, first 3 planes are all the same colour, like the histogram for that image is stretched out somehow (it is, you can see it in a decent graphics program)

    [edit, black and white were inverted, tested with beach photo - http://www.ft.unicamp.br/docentes/magic/khoros/html-dip/c4/s12/ipanema-leblon.gif ]

  • also, Bit Plane Slicing

Sign In or Register to comment.