Advertisement
Guest User

Gray/Normalized/Binary

a guest
Jan 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1.  
  2.  
  3. public interface ImageProcessor {
  4.     public Image processImage(Image image);
  5. }
  6.  
  7.  
  8. import org.opencv.core.Mat;
  9. import org.opencv.imgproc.Imgproc;
  10.  
  11. public class GrayScaleImg implements ImageProcessor{
  12.  
  13.     public Image processImage(Image imageToProcess){
  14.         Mat grayImageMat = new Mat(imageToProcess.getSourceImage().getHeight(),
  15.                 imageToProcess.getSourceImage().getWidth(), Image.GRAY);
  16.         Imgproc.cvtColor(imageToProcess.getImageDataMat(), grayImageMat, Imgproc.COLOR_RGB2GRAY);
  17.         return imageToProcess.getImageFromMat(grayImageMat);
  18.     }
  19. }
  20.  
  21.  
  22. import org.opencv.core.Core;
  23. import org.opencv.core.Mat;
  24.  
  25. public class NormalizedImg implements ImageProcessor {
  26.  
  27.     public Image processImage(Image imageToProcess){
  28.         Mat normalizedImageMat = new Mat(imageToProcess.getSourceImage().getHeight(),
  29.                 imageToProcess.getSourceImage().getWidth(), Image.GRAY);
  30.         Core.normalize(imageToProcess.getImageDataMat(), normalizedImageMat, 0,
  31.                 255, Core.NORM_MINMAX, Image.GRAY);
  32.         return imageToProcess.getImageFromMat(normalizedImageMat);
  33.  
  34.     }
  35. }
  36.  
  37.  
  38. import org.opencv.core.Mat;
  39. import org.opencv.imgproc.Imgproc;
  40.  
  41. public class BinaryImg implements ImageProcessor{
  42.     private static final int PIXEL_NEIGHBOURHOOD = 21;
  43.     private static final int SUBTRACTED_FROM_MEAN = 3;
  44.  
  45.     public Image processImage(Image imageToProcess){
  46.         Mat binaryImageMat = new Mat(imageToProcess.getSourceImage().getHeight(),
  47.                 imageToProcess.getSourceImage().getWidth(), Image.GRAY);
  48.         Imgproc.adaptiveThreshold(imageToProcess.getImageDataMat(), binaryImageMat,
  49.                 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY,
  50.                 PIXEL_NEIGHBOURHOOD, SUBTRACTED_FROM_MEAN);//21 3
  51.         return imageToProcess.getImageFromMat(binaryImageMat);
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement