画像 j を使用してメディアン フィルタリングを実装しようとしています。ゼロのパディングは、画像の下部と左端に余分なゼロを追加するため、問題があります。
皆さんが私を助けることができれば、これは私がこれまでに行ったことです:
Dialog.create("9x9 median filtering");
Dialog.addMessage("9x9 median filtering");
Dialog.show();
setBatchMode(true);
median_filter_9();
setBatchMode("exit and display");
// Produce the 9x9 median image
function median_filter_9() 
{
 width = getWidth();
 height= getHeight();
 //if you want to apply this median filter to 16bit 
 depth = bitDepth();
 nBin= pow(2, depth);
 //nBin hold max gray intensity value 
 filteHisto = newArray(nBin);
 //filteHisto = newArray(255);
 fiveBYFive = newArray(81);
 //this is what i used for middle position of array to get median
 middlePos = round(81/2);
//-3, -3 will get you position 0,0 of a 9x9 matrix if you start in the middle
 for(j=-2;j<width-2;j++){
  for(i=-2;i<height-2;i++){ 
   z=0;
   for(r=0;r<9;r++){
    for(c=0;c<9;c++){
     //Extend outside image boundaries using zero padding.
    //error here: adds extra to bottom and farleft of picture
     if(j+r<0||j+r>=width||i+c<0||i+c>=height){
      fiveBYFive[z]=0;
      z++;
     }else{  
      v = getPixel(j+r,i+c);
      fiveBYFive[z]= v;
      z++;
     }
    }
   }
   //sort the array to find median
   Array.sort(fiveBYFive);
   median = fiveBYFive[middlePos];
   setPixel(j, i, median);
  } 
  updateDisplay();
 }
}