title: Median filter implementation using java
body: <p>I am implementing a median filter using java, but the output i am getting is not satisfactory . I have done using a 3*3 neighborhood . Here is my code :</p>
  
  <pre><code>for(i=1;i&lt;height-1;i++)
      {
         for(j=1;j&lt;width-1;j++)
         {
              Color c=new Color(img.getRGB(j,i));
              red=c.getRed();
              green=c.getGreen();
              blue=c.getBlue();
              x=j;
              y=i;
              x1=x-1;
              y1=y;
              x2=x+1;
              y2=y;
              x3=x;
              y3=y-1;
              x4=x;
              y4=y+1;
              x5=x+1;
              y5=y+1;
              x6=x-1;
              y6=y-1;
              x7=x-1;
              y7=y+1;
              x8=x+1;
              y8=y-1; 
              Color c1=new Color(img.getRGB(x1,y1));
              red1=c1.getRed();
              green1=c1.getGreen();
              blue1=c1.getBlue();  
              Color c2=new Color(img.getRGB(x2,y2));
              red2=c2.getRed();
              green2=c2.getGreen();
              blue2=c2.getBlue();
              Color c3=new Color(img.getRGB(x3,y3));
              red3=c3.getRed();
              green3=c3.getGreen();
              blue3=c3.getBlue();
              Color c4=new Color(img.getRGB(x4,y4));
              red4=c4.getRed();
              green4=c4.getGreen();
              blue4=c4.getBlue();
              Color c5=new Color(img.getRGB(x5,y5));
              red5=c5.getRed();
              green5=c5.getGreen();
              blue5=c5.getBlue();
              Color c6=new Color(img.getRGB(x6,y6));
              red6=c6.getRed();
              green6=c6.getGreen();
              blue6=c6.getBlue();
              Color c7=new Color(img.getRGB(x7,y7));
              red7=c7.getRed();
              green7=c7.getGreen();
              blue7=c7.getBlue();
              Color c8=new Color(img.getRGB(x8,y8));
              red8=c8.getRed();
              green8=c8.getGreen();
              blue8=c8.getBlue();
              a[0]=red1;
              a[1]=red2;
              a[2]=red3;
              a[3]=red4;
              a[4]=red5;
              a[5]=red6;
              a[6]=red7;
              a[7]=red8;
              a=bubbleSort(a);
              redf=a[2];
              a[0]=green1;
              a[1]=green2;
              a[2]=green3;
              a[3]=green4;
              a[4]=green5;
              a[5]=green6;
              a[6]=green7;
              a[7]=green8;
              a=bubbleSort(a);
              greenf=a[2];
              a[0]=blue1;
              a[1]=blue2;
              a[2]=blue3;
              a[3]=blue4;
              a[4]=blue5;
              a[5]=blue6;
              a[6]=blue7;
              a[7]=blue8;
              a=bubbleSort(a);
              bluef=a[2];
              Color nc=new Color(redf,greenf,bluef);
              img.setRGB(x,y,nc.getRGB());
         }
     }
  </code></pre>
  
  <p>The outer loop is from 1 to height-1 . It's not getting printed </p>