Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import org.eclipse.swt.graphics.Image;
  2. import org.eclipse.swt.graphics.ImageData;
  3.  
  4. //The class for carrying out the filtering
  5. public class ImgFil{
  6. // Median filter
  7. public Image filMedian(Image image) {
  8.  
  9. // indice for expressing the x,y differences from the center
  10. int[] iDx = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
  11. int[] iDy = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
  12.  
  13.  
  14. // Getting the pixel array of the original image 3
  15. ImageData imd = image.getImageData();
  16.  
  17. // Setting the pixel array for the new result image
  18. ImageData imd2 =image.getImageData();
  19.  
  20. for (int y = 1; y < (imd.height-1); y++) {
  21. for (int x = 1; x < (imd.width-1); x++) {
  22. int iRsum = 0;
  23. int iGsum = 0;
  24. int iBsum = 0;
  25.  
  26. for (int i = 0; i < 9; i++) {
  27. int iC = imd.getPixel(x+iDx[i], y+iDy[i]);
  28. int iR = iC & 0x00ff;
  29. int iG = (iC >> 8) & 0x00ff;
  30. int iB = (iC >> 16) & 0x00ff;
  31.  
  32. // Adding the RGB values of pixels in the eight neighborhood repeatedly
  33. iRsum += iR;
  34. iGsum += iG;
  35. iBsum += iB;
  36. }
  37. // Getting 5th large number
  38. int iRd = iRsum;
  39. int iGd = iGsum;
  40. int iBd = iBsum;
  41. int iCd = (iBd << 16) + (iGd << 8) + iRd;
  42. imd2.setPixel(x, y, iCd);
  43. }
  44. }
  45. Image newImage = new Image(null, imd2);
  46. return newImage;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement