Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface ImageProcessor {
- public Image processImage(Image image);
- }
- import org.opencv.core.Mat;
- import org.opencv.imgproc.Imgproc;
- public class GrayScaleImg implements ImageProcessor{
- public Image processImage(Image imageToProcess){
- Mat grayImageMat = new Mat(imageToProcess.getSourceImage().getHeight(),
- imageToProcess.getSourceImage().getWidth(), Image.GRAY);
- Imgproc.cvtColor(imageToProcess.getImageDataMat(), grayImageMat, Imgproc.COLOR_RGB2GRAY);
- return imageToProcess.getImageFromMat(grayImageMat);
- }
- }
- import org.opencv.core.Core;
- import org.opencv.core.Mat;
- public class NormalizedImg implements ImageProcessor {
- public Image processImage(Image imageToProcess){
- Mat normalizedImageMat = new Mat(imageToProcess.getSourceImage().getHeight(),
- imageToProcess.getSourceImage().getWidth(), Image.GRAY);
- Core.normalize(imageToProcess.getImageDataMat(), normalizedImageMat, 0,
- 255, Core.NORM_MINMAX, Image.GRAY);
- return imageToProcess.getImageFromMat(normalizedImageMat);
- }
- }
- import org.opencv.core.Mat;
- import org.opencv.imgproc.Imgproc;
- public class BinaryImg implements ImageProcessor{
- private static final int PIXEL_NEIGHBOURHOOD = 21;
- private static final int SUBTRACTED_FROM_MEAN = 3;
- public Image processImage(Image imageToProcess){
- Mat binaryImageMat = new Mat(imageToProcess.getSourceImage().getHeight(),
- imageToProcess.getSourceImage().getWidth(), Image.GRAY);
- Imgproc.adaptiveThreshold(imageToProcess.getImageDataMat(), binaryImageMat,
- 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY,
- PIXEL_NEIGHBOURHOOD, SUBTRACTED_FROM_MEAN);//21 3
- return imageToProcess.getImageFromMat(binaryImageMat);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement