All pastes #573126 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-18 00:29 UTC
rendered paste body
  // sal's altered method
  public int [] apply_sobel(int [] src_1d, int width, int height, double sobscale, float offsetval) {
    
    int i_w = width;
    int i_h = height;
    d_w = width;
    d_h = height;
    dest_1d = new int[d_w * d_h];
    
    for(int i=0;i<src_1d.length;i++){
      try {
        // SAL -- do pixels below align like this? ... will test it out
        // a d f
        // b   g
        // c e h
  
        int a = src_1d[i] & 0x000000ff;
        int b = src_1d[i+ 1] & 0x000000ff;
        int c = src_1d[i+ 2] & 0x000000ff;
        int d = src_1d[i + i_w] & 0x000000ff;
        int e = src_1d[i + i_w + 2] & 0x000000ff;
        int f = src_1d[i + 2*i_w ] & 0x000000ff;
        int g = src_1d[i + 2*i_w + 1] & 0x000000ff;
        int h = src_1d[i + 2*i_w + 2] & 0x000000ff;
        
        int hor = (a+d+f) - (c+e+h); // SAL -- top row - bottom row
        
        int vert = (a+b+c) - (f+g+h); // SAL --  left col - right col
 
        
        // SAL -- this will tell us if the pixel is a corner pixel and make it red.  
        if ( (hor!=0) & (vert!= 0)){
          dest_1d[i] = 0xff000000 | 255><<16 | 0<<8 | 0;
        }
 
        //reached borders of image so goto next row
        //(see Convolution.java)
        if (((i+3)%i_w)==0)  {
          dest_1d[i] = 0;
          dest_1d[i+1] = 0;
          dest_1d[i+2] = 0;
          i+=3;
        }
      } catch (ArrayIndexOutOfBoundsException e) {
        //if reached row boudary of image return.
        i = src_1d.length;
      }
    }
    return dest_1d;
  }