-
Notifications
You must be signed in to change notification settings - Fork 8
/
ImageRenderer3.cpp
86 lines (68 loc) · 2.8 KB
/
ImageRenderer3.cpp
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
84
85
86
#define _USE_MATH_DEFINES // for math constants in C++
#include <iostream> // debug
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include "Util.h"
#include "NormalDistribution.h"
#include "ImageRenderer3.h"
ImageRenderer3::ImageRenderer3(void)
{
}
ImageRenderer3::~ImageRenderer3(void)
{
}
oclMat ImageRenderer3::renderImage() const
{
int x0 = this->getPinholePosition()[0]; // TODO check whether inside the microlens' image
int y0 = this->getPinholePosition()[1];
float standardDeviation1 = this->lightfield.ANGULAR_RESOLUTION.width / 4.0;
float standardDeviation2 = this->lightfield.ANGULAR_RESOLUTION.height / 4.0;
NormalDistribution apertureFunction = NormalDistribution(x0, y0,
standardDeviation1, standardDeviation2);
const Vec2f uvScale = Vec2f(1.0, 1.0 / cos(M_PI / 6.0));
const double weight = 1.0 - 1.0 / alpha;
const Size saSize = Size(this->lightfield.SPARTIAL_RESOLUTION.width,
this->lightfield.SPARTIAL_RESOLUTION.height);
const Size imageSize = Size(saSize.width +
this->lightfield.ANGULAR_RESOLUTION.width * uvScale[0] * weight,
saSize.height + this->lightfield.ANGULAR_RESOLUTION.height * uvScale[1]
* weight);
const int imageType = CV_MAKETYPE(CV_32F,
this->lightfield.getRawImage().channels()/* + 1*/);
Mat image = Mat::zeros(imageSize, imageType);
Mat subapertureImage, compositeImage, dstROI;
Vec2d translation, dstCorner;
const Vec2d angularCorrection = Vec2d(
this->lightfield.ANGULAR_RESOLUTION.width,
this->lightfield.ANGULAR_RESOLUTION.height) * 0.5;
const Vec2d dstCenter = Vec2d(image.size().width, image.size().height) * 0.5;
Rect dstRect;
const Vec2d fromCenterToCorner = Vec2d(
this->lightfield.SPARTIAL_RESOLUTION.width,
this->lightfield.SPARTIAL_RESOLUTION.height) * -0.5;
int u, v;
for(u = 0; u < this->lightfield.ANGULAR_RESOLUTION.width; u++)
{
for(v = 0; v < this->lightfield.ANGULAR_RESOLUTION.height; v++)
{
// TODO use interpolated sub-aperture images
subapertureImage = this->lightfield.getSubapertureImageI(u, v);
subapertureImage *= apertureFunction.f(u * uvScale[0] -
angularCorrection[0], v * uvScale[1] - angularCorrection[1]);
//compositeImage = appendRayCountingChannel(subapertureImage);
translation = (Vec2d(u * uvScale[0], v * uvScale[1]) -
angularCorrection) * weight;
dstCorner = dstCenter + translation + fromCenterToCorner;
dstRect = Rect(Point(round(dstCorner[0]), round(dstCorner[1])),
saSize);
dstROI = Mat(image, dstRect);
add(subapertureImage, dstROI, dstROI, noArray(), imageType);
}
}
// scale luminance/color values to fit inside [0, 1)
// TODO fix normalization
//Mat normalizedImage = normalizeByRayCount(image);
adjustLuminanceSpace(image);
// TODO why not use CV::normalize()? If replaceable, normalizeByRayCount() obsolete
return oclMat(image);
}