Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor lightfields bezier #200

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cd2591a
The simplest grayscale and stupendously slow use of bspline as a type…
martin-pr Dec 22, 2020
d09f519
BSpline coords to float; RGB support
martin-pr Dec 23, 2020
8f779e0
BSpline - separate subdiv levels for each dim
martin-pr Dec 23, 2020
4855440
Fixing incorrect edge handling of BSplines
martin-pr Dec 23, 2020
fb8f278
Improving B-Spline performance - precomputing coefficients and using …
martin-pr Dec 24, 2020
8e80e52
Removing the use of std::pair - it is not trivially copyable, which m…
martin-pr Dec 24, 2020
70eb30e
BSpline - corrected control point ranges to avoid the necessity for i…
martin-pr Dec 25, 2020
90f64db
BSpline - fn() now called from within the IndexMaker class
martin-pr Dec 25, 2020
99689c7
BSpline visit pattern implemented using explicit classes to allow inl…
martin-pr Dec 26, 2020
59534fc
Nearest and mosaic integration - a change in parallel_for loop to mak…
martin-pr Dec 27, 2020
3816fce
Added mosaic_to_samples node and a temporary demo
martin-pr Dec 27, 2020
bc2d473
Fixing BSpline implementation to compile with GCC
martin-pr Dec 28, 2020
0c36f77
Removed lightfield vignetting type + related nodes (no longer needed)
martin-pr Dec 28, 2020
d5678be
Refactored BSpline to hold coordinates in form of unscaled indices
martin-pr Dec 28, 2020
4e278b3
A simple parallelization of the BSpline processing by image rows
martin-pr Dec 29, 2020
8a7a181
Replaced bspline_to_frame with bspline_to_sequence
martin-pr Dec 30, 2020
5a04ba0
Fixing bezier spline hierarchy refocusing to work with the new codebase
martin-pr Dec 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"files.associations": {
"*.inl": "cpp",
"functional": "cpp",
"hash_map": "cpp",
"unordered_map": "cpp",
Expand Down Expand Up @@ -71,6 +72,8 @@
"typeinfo": "cpp",
"variant": "cpp",
"bit": "cpp",
"compare": "cpp"
"compare": "cpp",
"*.ipp": "cpp",
"valarray": "cpp"
}
}
Binary file added examples/lytro/calibration_long.lfr
Binary file not shown.
46 changes: 23 additions & 23 deletions src/libs/lightfields/nearest_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ IntegrationResult integrate(const lightfields::Samples& samples, const Imath::Ve
const float widthf = width;
const float heightf = height;

tbb::parallel_for(
tbb::blocked_range<lightfields::Samples::const_iterator>(samples.begin(), samples.end()),
[&](const tbb::blocked_range<lightfields::Samples::const_iterator> range) {
for(const lightfields::Samples::Sample& sample : range) {
const float target_x = (sample.xy[0] + offset * sample.uv[0]) * x_scale;
const float target_y = (sample.xy[1] + offset * sample.uv[1]) * y_scale;

if((target_x >= 0.0f) && (target_y >= 0.0f) && (target_x < widthf) && (target_y < heightf)) {
float* color = average.ptr<float>(floor(target_y), floor(target_x));
uint16_t* n = norm.ptr<uint16_t>(floor(target_y), floor(target_x));

if(sample.color == lightfields::Samples::kRGB)
for(int a = 0; a < 3; ++a) {
color[a] += sample.value[a];
++n[a];
}
else {
color[sample.color] += sample.value[sample.color];
++n[sample.color];
}
}
}
});
const tbb::blocked_range<lightfields::Samples::const_iterator> range(samples.begin(), samples.end());

tbb::parallel_for(range, [&](const tbb::blocked_range<lightfields::Samples::const_iterator> range) {
for(const lightfields::Samples::Sample& sample : range) {
const float target_x = (sample.xy[0] + offset * sample.uv[0]) * x_scale;
const float target_y = (sample.xy[1] + offset * sample.uv[1]) * y_scale;

if((target_x >= 0.0f) && (target_y >= 0.0f) && (target_x < widthf) && (target_y < heightf)) {
float* color = average.ptr<float>(floor(target_y), floor(target_x));
uint16_t* n = norm.ptr<uint16_t>(floor(target_y), floor(target_x));

if(sample.color == lightfields::Samples::kRGB)
for(int a = 0; a < 3; ++a) {
color[a] += sample.value[a];
++n[a];
}
else {
color[sample.color] += sample.value[sample.color];
++n[sample.color];
}
}
}
});

tbb::parallel_for(0, average.rows, [&](int y) {
for(int x = 0; x < average.cols; ++x)
Expand Down
24 changes: 23 additions & 1 deletion src/libs/lightfields/samples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace lightfields {

Samples::Samples() {
Samples::Samples(const Imath::V2i& sensor) : m_size(sensor) {
}

Samples::~Samples() {
Expand Down Expand Up @@ -65,6 +65,14 @@ Samples::const_iterator Samples::end() const {
return m_samples.end();
}

Samples::iterator Samples::begin() {
return m_samples.begin();
}

Samples::iterator Samples::end() {
return m_samples.end();
}

std::size_t Samples::size() const {
return m_samples.size();
}
Expand Down Expand Up @@ -160,6 +168,20 @@ Samples Samples::fromPattern(const Pattern& pattern, const cv::Mat& m) {
return result;
}

void Samples::resize(std::size_t size) {
m_samples.resize(size);
}

Samples::Sample& Samples::operator[](std::size_t index) {
assert(index < m_samples.size());
return m_samples[index];
}

const Samples::Sample& Samples::operator[](std::size_t index) const {
assert(index < m_samples.size());
return m_samples[index];
}

/////////

std::ostream& operator<<(std::ostream& out, const Samples& f) {
Expand Down
10 changes: 9 additions & 1 deletion src/libs/lightfields/samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Samples {
Imath::V3f value; ///< Sample colour value (only the valid channels are populated)
};

Samples();
Samples(const Imath::V2i& sensorSize = Imath::V2i(0, 0));
~Samples();

Samples(const Samples&) = default;
Expand All @@ -33,10 +33,14 @@ class Samples {
Samples& operator=(Samples&&) = default;

using const_iterator = std::vector<Sample>::const_iterator;
using iterator = std::vector<Sample>::iterator;

const_iterator begin() const;
const_iterator end() const;

iterator begin();
iterator end();

std::size_t size() const;
bool empty() const;

Expand All @@ -49,6 +53,10 @@ class Samples {

static Samples fromPattern(const Pattern& p, const cv::Mat& data);

void resize(std::size_t size);
Sample& operator[](std::size_t index);
const Sample& operator[](std::size_t index) const;

private:
std::vector<Sample> m_samples;
Imath::V2i m_size;
Expand Down
23 changes: 14 additions & 9 deletions src/plugins/opencv/bspline.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ namespace opencv {
template <unsigned DEGREE>
class BSpline {
public:
BSpline(unsigned subdiv, const std::array<double, DEGREE>& min = initArray(0.0),
const std::array<double, DEGREE>& max = initArray(1.0));
explicit BSpline(const std::array<std::size_t, DEGREE>& subdiv = initArray(std::size_t(0)));

void addSample(const std::array<double, DEGREE>& coords, double value);
double sample(const std::array<double, DEGREE>& coords) const;
void addSample(const std::array<float, DEGREE>& coords, float value);
float sample(const std::array<float, DEGREE>& coords) const;

std::size_t size(unsigned dim) const;

bool operator==(const BSpline& b) const;
bool operator!=(const BSpline& b) const;

private:
static double B(double t, unsigned k);
static float B(float t, unsigned k);

template <typename FN>
inline void visit(const std::array<double, DEGREE>& coords, const FN& fn) const;
static std::array<double, DEGREE> initArray(double val);
inline void visit(const std::array<float, DEGREE>& coords, const FN& fn) const;

template <typename T>
static std::array<T, DEGREE> initArray(T val);

std::size_t m_subdiv;
std::array<std::size_t, DEGREE> m_subdiv;
std::vector<std::pair<float, float>> m_controls;
std::array<double, DEGREE> m_min, m_max;
};

template <unsigned DEGREE>
std::ostream& operator<<(std::ostream& out, const BSpline<DEGREE>& spline);

} // namespace opencv
} // namespace possumwood
Loading