Sign in

username:

password:



Not a member?

Search imagedsp



Search tips

Subscribe to imagedsp



imagedsp by Keywords

Error Concealment | JPEG | MPEG-4 | Wavelet | YUV

Discussion Groups

Discussion Groups | Image Signal Processing | gabor filter java implementation

Technical Discussions related to Image Processing (image coding, compression, digital effects, mpeg, etc)

  

Post a new Thread

gabor filter java implementation - ghalamiamin - Sep 10 7:35:25 2007



I have Implemented a 2D gabor filter by java
but it does not work properly Please give me notes about my code 
thank you

package fpFrameWork.process.gaborFilter;
import java.awt.*;
import java.awt.image.BufferedImage;

public class Orientation {
    private double deltaX=1.8;
    private double deltaY=0.8;
    private double T1 = 4;
    private double T2 = 28; //[4,12];
    public int[][] pixels;
    public int[][] sobeledX;
    public int[][] sobeledY;
    public BufferedImage bimg;
    public double[][] vX;
    public double[][] vY;
    public double[][] teta;
    public double[][] gabor;
    public Orientation(Image img){
        this.bimg = (BufferedImage)img;
        pixels = new int[this.bimg.getWidth()][this.bimg.getHeight
()];
        sobeledX = new int[this.bimg.getWidth()+1]
[this.bimg.getHeight()+1];
        sobeledY = new int[this.bimg.getWidth()+1]
[this.bimg.getHeight()+1];
        vX = new double[this.bimg.getWidth()][this.bimg.getHeight()];
        vY = new double[this.bimg.getWidth()][this.bimg.getHeight()];
        teta = new double[this.bimg.getWidth()][this.bimg.getHeight
()];
        gabor =new double[this.bimg.getWidth()][this.bimg.getHeight
()];
    }//constructor
    public void fillPixels(){
        for (int i=0 ; i<bimg.getWidth() ; i++)
        {
            for(int j=0 ; j<bimg.getHeight() ; j++){
                Color clr=new Color(bimg.getRGB(i,j));
                  if ((clr.getRed()<=127)&&(clr.getBlue()<=127)&&
(clr.getGreen()<=127)){
                      pixels[i][j]=0;//.00000000000000001;
                  }else{
                      pixels[i][j]=1;
                  }

            }
        }
    }//fill pixels

    public void soobel(){ //applies soobel operator to pixels
        for (int i=1 ; i<bimg.getWidth()-1 ; i++){
            for (int j=1 ; j<bimg.getHeight()-1 ; j++){
                sobeledX[i][j]=(pixels[i-1][j-1]+(2*pixels[i][j-1])
+pixels[i+1][j-1])
                        -(pixels[i-1][j+1]+(2*pixels[i][j+1])+pixels
[i+1][j+1]);
                sobeledY[i][j]=pixels[i-1][j-1]-pixels[i-1][j+1]+(2*
(pixels[i][j-1]-pixels[i][j+1]))
                        +pixels[i+1][j-1]-pixels[i+1][j+1];
            }
        }
    }
    public void computeV(){//computes Vx and Vy
        for (int i=1 ; i<bimg.getWidth()-1 ; i++){
            for (int j=1 ; j<bimg.getHeight() ; j++){
                vX[i][j]=vX(i,j);
                vY[i][j]=vY(i,j);
            }
        }
    }

    private double vX(int i,int j){
        double tmp=0;
        for (int u = i-1; u<= i+1 ; u++){
            for (int v= j-1; v<= j+1 ; v++){
                tmp = tmp + sobeledX[u][v] * sobeledY[u][v] * 2;
//
            }
        }

        return tmp;
    }
    private double vY(int i,int j){
        double tmp=0;
        for (int u = i-1; u<= i+1 ; u++){
            for (int v= j-1; v<= j+1 ; v++){

                tmp = tmp
                        +( (sobeledX[u][v] * sobeledX[u][v]) * 
(sobeledY[u][v] * sobeledY[u][v]));
            }
        }

        return tmp;
    }

    public void tetaCompute(){
        for (int i=1 ; i < bimg.getWidth()-1 ; i++){
            for (int j=1 ; j< bimg.getHeight()-1 ; j++){
                if ((vX[i][j]==0)&&(vY[i][j])==0){
                        teta[i][j]=Math.PI/2;
                }   else  if (vX[i][j]==0){
                  teta[i][j]=0.5 * Math.atan(Math.signum(vY[i][j])
*2000000000);
                }else if (vX[i][j]!=0) {
                  teta[i][j] = 0.5 * Math.atan(vY[i][j]/vX[i][j]);
                }

            }

        }

    }
    public void gabor(){
        for (int i=1 ; i< bimg.getWidth()-1 ; i++){
            for (int j=1 ; j< bimg.getHeight()-1 ; j++){

                gabor [i][j] = Math.exp((-(i*Math.cos(teta[i][j])
+j*Math.sin(teta[i][j])))/(2*deltaX*deltaX));
                gabor [i][j] = gabor[i][j]
                        * Math.exp((-(-i*Math.sin(teta[i][j])
+j*Math.cos(teta[i][j])))/(2*deltaY*deltaY));
                gabor [i][j] = gabor[i][j]
                        * F((i*Math.cos(teta[i][j])+j*Math.sin(teta
[i][j])),T1,T2);
            }
        }
    }
    private double F (double xFi, double T1, double T2){
        return f(xFi-(Math.ceil(xFi/(T1/2+T2/2))*(T1/2+T2/2)));
    }

    private double f(double x){
        double s=0;
         if ((x >= 0)&&(x <= (T1/4))){
            s = Math.cos(( 2 * Math.PI * x)/T1);
        }else if ((x > T1/4)&&(x < (T1/4+T2/2))){
             s = - Math.cos(2 * Math.PI * (x - T1/4 -T2/2)/T2);
         }else if ((x >= (T1/4 + T2/2))&&(x <= (T1/2 + T2/2))){
             s = Math.cos(2 * Math.PI * (x - T1/4 -T2/2)/T2);
         }
        return s;
    }
}



(You need to be a member of imagedsp -- send a blank email to imagedsp-subscribe@yahoogroups.com )