forked from bytedeco/javacv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BioInspiredRetina.java
83 lines (72 loc) · 3.3 KB
/
BioInspiredRetina.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.bytedeco.javacpp.tools.Slf4jLogger;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.bytedeco.javacv.OpenCVFrameConverter;
import org.bytedeco.opencv.opencv_core.*;
import org.bytedeco.opencv.opencv_imgproc.*;
import org.bytedeco.opencv.opencv_bioinspired.*;
import static org.bytedeco.opencv.global.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_bioinspired.*;
/**
* Bioinspired Retina demonstration
* This retina model allows spatio-temporal image processing
* As a summary, these are the retina model properties:
* It applies a spectral whithening (mid-frequency details enhancement)
* high frequency spatio-temporal noise reduction
* low frequency luminance to be reduced (luminance range compression)
* local logarithmic luminance compression allows details to be enhanced in low light conditions
*
* Created by mbetzel on 04.09.2016.
*/
public class BioInspiredRetina {
static {
System.setProperty("org.bytedeco.javacpp.logger", "slf4jlogger");
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
}
private static final Slf4jLogger logger = (Slf4jLogger) org.bytedeco.javacpp.tools.Logger.create(BioInspiredRetina.class);
public static void main(String[] args) {
try {
logger.info(String.valueOf(logger.isDebugEnabled()));
logger.info("Start");
new BioInspiredRetina().execute(args);
logger.info("Stop");
} catch (Exception e) {
e.printStackTrace();
}
}
private void execute(String[] args) throws Exception {
BufferedImage bufferedImage = args.length >= 1 ? ImageIO.read(new File(args[0])) : ImageIO.read(this.getClass().getResourceAsStream("BlackBalls.jpg"));
System.out.println("Image type: " + bufferedImage.getType());
Mat matrix = new OpenCVFrameConverter.ToMat().convert(new Java2DFrameConverter().convert(bufferedImage));
normalize(matrix, matrix, 0, 255, NORM_MINMAX, -1, noArray());
showImage(matrix);
matrix.convertTo(matrix, CV_32F);
Mat gammaTransformedImage = new Mat(matrix.size(), CV_32F);
pow(matrix, 1. / 5, gammaTransformedImage);
Retina retina = Retina.create(gammaTransformedImage.size());
Mat retinaOutput_parvo = new Mat();
Mat retinaOutput_magno = new Mat();
retina.clearBuffers();
retina.run(gammaTransformedImage);
retina.getParvo(retinaOutput_parvo);
retina.getMagno(retinaOutput_magno);
showImage(retinaOutput_parvo);
showImage(retinaOutput_magno);
}
private void showImage(Mat matrix) {
CanvasFrame canvasFrame = new CanvasFrame("Retina demonstration", 1);
canvasFrame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
canvasFrame.setCanvasSize(640, 480);
Canvas canvas = canvasFrame.getCanvas();
canvasFrame.getContentPane().removeAll();
ScrollPane scrollPane = new ScrollPane();
scrollPane.add(canvas);
canvasFrame.add(scrollPane);
canvasFrame.showImage(new OpenCVFrameConverter.ToMat().convert(matrix));
}
}