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

Replace usage of std::vector as storage of pixel data with image::Image #1282

Merged
merged 30 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
527ef39
[image] Add resizeImage() for Image<float>
p12tic Oct 11, 2022
2c41b3b
[mesh] Replace std::vector<T> with Image<T> where possible
p12tic Oct 11, 2022
6fe86f8
[depthMap] Replace std::vector<T> with Image<T> where possible
p12tic Oct 11, 2022
941510c
[fuseCut] Replace std::vector<T> with Image<T> where possible
p12tic Oct 11, 2022
0ff1ebe
[mesh] Replace std::vector<T> with Image<T> where possible
p12tic Oct 11, 2022
7f8a833
[image] Replace OutputFileColorSpace with ImageWriteOptions
p12tic Oct 11, 2022
0831c25
[image] Prefer writeImage() overloads that options instead of colorspace
p12tic Oct 11, 2022
94f98f6
[image] Convert remaining writeImage overloads to use ImageWriteOptions
p12tic Oct 11, 2022
be9a2f9
[image] Move ImageReadOptions and ImageWriteOptions lower in the file
p12tic Oct 11, 2022
f47db51
[image] Add a way to set storage data type to ImageWriteOptions
p12tic Oct 11, 2022
edebb9f
Prefer storing storage datatype to ImageWriteOptions instead of metadata
p12tic Oct 11, 2022
c156077
[image] Use EStorageDataType instead of EImageQuality in writeImage()
p12tic Oct 11, 2022
64cf40d
[image] Add functions to write integer images with float conversion
p12tic Oct 11, 2022
204a2c6
[depthMap] Prefer std::vector to StaticVector when working with images
p12tic Oct 11, 2022
487252b
[fuseCut] Prefer std::vector to StaticVector when working with images
p12tic Oct 11, 2022
9497532
[fuseCut] Prefer image::Image for image data that is later written out
p12tic Oct 11, 2022
e681d23
[depthMap] Prefer image::Image for image data that is later written out
p12tic Oct 11, 2022
7fb2b3f
[image] Make implementation of convolveImage() more flexible
p12tic Oct 11, 2022
086b528
[image] Implement convolveImage() for image::Image data storage format
p12tic Oct 11, 2022
6d624a9
[depthMap] Prefer image::Image for image data that is read in
p12tic Oct 11, 2022
7a7f82c
[fuseCut] Prefer image::Image for image data that is read in
p12tic Oct 11, 2022
afecb0f
[image] Remove unused readImage() and writeImage() for std::vector
p12tic Oct 11, 2022
ad81c4d
[image] Remove no longer used transposeImage
p12tic Oct 11, 2022
7f56f4c
[image] Remove no longer used resizeImage(std::vector)
p12tic Oct 11, 2022
424a2b1
[image] Remove no longer used convolveImage(std::vector)
p12tic Oct 11, 2022
76e6679
[image] Remove no longer used fillHoles(std::vector)
p12tic Oct 11, 2022
e5b63c7
[depthMap] Use 2D image pixel data accessors
p12tic Oct 11, 2022
b313aba
[image] Use separate EStorageDataType to specify not set value
p12tic Oct 11, 2022
93c9122
[fuseCut] Fuser: Use 2d image pixel data accessors
gregoire-dl Nov 10, 2022
b866c95
[fuseCut] Fuser: Fix incorrect depth/sim map size check
gregoire-dl Nov 10, 2022
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
2 changes: 1 addition & 1 deletion src/aliceVision/calibration/exportData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void exportImages(aliceVision::dataio::FeedProvider& feed,

aliceVision::camera::UndistortImage(inputImage, &camera, outputImage, static_cast<unsigned char>(0));
const boost::filesystem::path imagePath = boost::filesystem::path(debugFolder) / (std::to_string(currentFrame) + suffix);
aliceVision::image::writeImage(imagePath.string(), outputImage, image::EImageColorSpace::AUTO);
aliceVision::image::writeImage(imagePath.string(), outputImage, image::ImageWriteOptions());
}
ALICEVISION_LOG_DEBUG("... finished");
}
Expand Down
75 changes: 36 additions & 39 deletions src/aliceVision/depthMap/DepthSimMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ float DepthSimMap::getPercentileDepth(float perc) const
* @brief Get depth map at the size of our input image (with _scale applied)
* from an internal buffer only computed for a subpart (based on the step).
*/
void DepthSimMap::getDepthMapStep1(StaticVector<float>& out_depthMap) const
void DepthSimMap::getDepthMapStep1(image::Image<float>& out_depthMap) const
{
// Size of our input image (with _scale applied)
const int wdm = _mp.getWidth(_rc) / _scale;
const int hdm = _mp.getHeight(_rc) / _scale;

// Create a depth map at the size of our input image
out_depthMap.resize(wdm * hdm);
out_depthMap.resize(wdm, hdm);

const double ratio = 1.0 / double(_step);

Expand All @@ -215,19 +215,19 @@ void DepthSimMap::getDepthMapStep1(StaticVector<float>& out_depthMap) const
{
const double ox = (double(x) - 0.5) * ratio;
const float depth = getPixelValueInterpolated(_dsm, ox, oy, _w, _h).depth;
out_depthMap[y * wdm + x] = depth;
out_depthMap(y, x) = depth;
}
}
}

void DepthSimMap::getSimMapStep1(StaticVector<float>& out_simMap) const
void DepthSimMap::getSimMapStep1(image::Image<float>& out_simMap) const
{
// Size of our input image (with _scale applied)
const int wdm = _mp.getWidth(_rc) / _scale;
const int hdm = _mp.getHeight(_rc) / _scale;

// Create a depth map at the size of our input image
out_simMap.resize(wdm * hdm);
out_simMap.resize(wdm, hdm);

const double ratio = 1.0 / double(_step);

Expand All @@ -239,7 +239,7 @@ void DepthSimMap::getSimMapStep1(StaticVector<float>& out_simMap) const
{
const double ox = (double(x) - 0.5) * ratio;
const float sim = getPixelValueInterpolated(_dsm, ox, oy, _w, _h).sim;
out_simMap[y * wdm + x] = sim;
out_simMap(y, x) = sim;
}
}
}
Expand Down Expand Up @@ -318,7 +318,8 @@ void DepthSimMap::initJustFromDepthMap(const DepthSimMap& depthSimMap, float def
}
}

void DepthSimMap::initFromDepthMapAndSimMap(StaticVector<float>* depthMapT, StaticVector<float>* simMapT,
void DepthSimMap::initFromDepthMapAndSimMap(const image::Image<float>& depthMapT,
const image::Image<float>& simMapT,
int depthSimMapsScale)
{
int wdm = _mp.getWidth(_rc) / depthSimMapsScale;
Expand All @@ -331,34 +332,34 @@ void DepthSimMap::initFromDepthMapAndSimMap(StaticVector<float>* depthMapT, Stat
if ((x < wdm) && (y < hdm))
{
int index = y * wdm + x;
_dsm[i].depth = (*depthMapT)[index];
_dsm[i].sim = (*simMapT)[index];
_dsm[i].depth = depthMapT(index);
_dsm[i].sim = simMapT(index);
}
}
}

void DepthSimMap::getDepthMap(StaticVector<float>& out_depthMap) const
void DepthSimMap::getDepthMap(image::Image<float>& out_depthMap) const
{
out_depthMap.resize(_dsm.size());
out_depthMap.resize(_w, _h);
for (int i = 0; i < _dsm.size(); i++)
{
out_depthMap[i] = _dsm[i].depth;
out_depthMap(i) = _dsm[i].depth;
}
}

void DepthSimMap::getSimMap(StaticVector<float>& out_simMap) const
void DepthSimMap::getSimMap(image::Image<float>& out_simMap) const
{
out_simMap.resize(_dsm.size());
out_simMap.resize(_w, _h);
for (int i = 0; i < _dsm.size(); i++)
{
out_simMap[i] = _dsm[i].sim;
out_simMap(i) = _dsm[i].sim;
}
}

void DepthSimMap::saveToImage(const std::string& filename, float simThr) const
{
const int bufferWidth = 2 * _w;
std::vector<image::RGBfColor> colorBuffer(bufferWidth * _h);
image::Image<image::RGBfColor> colorBuffer(bufferWidth, _h);

try
{
Expand All @@ -384,16 +385,15 @@ void DepthSimMap::saveToImage(const std::string& filename, float simThr) const
{
const DepthSim& depthSim = _dsm[y * _w + x];
float depth = (depthSim.depth - maxMinDepth.y) / (maxMinDepth.x - maxMinDepth.y);
colorBuffer.at(y * bufferWidth + x) = getColorFromJetColorMap(depth);
colorBuffer(y, x) = getColorFromJetColorMap(depth);

float sim = (depthSim.sim - maxMinSim.y) / (maxMinSim.x - maxMinSim.y);
colorBuffer.at(y * bufferWidth + _w + x) = getColorFromJetColorMap(sim);
colorBuffer(y, _w + x) = getColorFromJetColorMap(sim);
}
}

oiio::ParamValueList metadata;
image::writeImage(filename, bufferWidth, _h, colorBuffer, image::EImageQuality::LOSSLESS,
image::OutputFileColorSpace(image::EImageColorSpace::NO_CONVERSION), metadata);
image::writeImage(filename, colorBuffer,
image::ImageWriteOptions().toColorSpace(image::EImageColorSpace::LINEAR)
.storageDataType(image::EStorageDataType::Float));
p12tic marked this conversation as resolved.
Show resolved Hide resolved
}
catch (...)
{
Expand All @@ -403,8 +403,8 @@ void DepthSimMap::saveToImage(const std::string& filename, float simThr) const

void DepthSimMap::save(const std::string& customSuffix, bool useStep1) const
{
StaticVector<float> depthMap;
StaticVector<float> simMap;
image::Image<float> depthMap;
image::Image<float> simMap;
if (useStep1)
{
getDepthMapStep1(depthMap);
Expand All @@ -419,9 +419,6 @@ void DepthSimMap::save(const std::string& customSuffix, bool useStep1) const
const int step = (useStep1 ? 1 : _step);
const int scaleStep = _scale * step;

const int width = _mp.getWidth(_rc) / scaleStep;
const int height = _mp.getHeight(_rc) / scaleStep;

auto metadata = image::getMetadataFromMap(_mp.getMetadata(_rc));
metadata.push_back(oiio::ParamValue("AliceVision:downscale", _mp.getDownscaleFactor(_rc) * scaleStep));

Expand Down Expand Up @@ -456,30 +453,30 @@ void DepthSimMap::save(const std::string& customSuffix, bool useStep1) const
metadata.push_back(oiio::ParamValue("AliceVision:P", oiio::TypeDesc(oiio::TypeDesc::DOUBLE, oiio::TypeDesc::MATRIX44), 1, matrixP.data()));
}

const int nbDepthValues = std::count_if(depthMap.begin(), depthMap.end(), [](float v) { return v > 0.0f; });
const int nbDepthValues = std::count_if(depthMap.data(), depthMap.data() + depthMap.size(), [](float v) { return v > 0.0f; });
metadata.push_back(oiio::ParamValue("AliceVision:nbDepthValues", oiio::TypeDesc::INT32, 1, &nbDepthValues));

image::writeImage(getFileNameFromIndex(_mp, _rc, mvsUtils::EFileType::depthMap, _scale, customSuffix),
width, height, depthMap.getDataWritable(), image::EImageQuality::LOSSLESS,
image::OutputFileColorSpace(image::EImageColorSpace::NO_CONVERSION), metadata);
depthMap,
image::ImageWriteOptions().toColorSpace(image::EImageColorSpace::LINEAR)
.storageDataType(image::EStorageDataType::Float), metadata);
image::writeImage(getFileNameFromIndex(_mp, _rc, mvsUtils::EFileType::simMap, _scale, customSuffix),
width, height, simMap.getDataWritable(), image::EImageQuality::OPTIMIZED,
image::OutputFileColorSpace(image::EImageColorSpace::NO_CONVERSION), metadata);
simMap,
image::ImageWriteOptions().toColorSpace(image::EImageColorSpace::LINEAR)
.storageDataType(image::EStorageDataType::Half), metadata);
}

void DepthSimMap::load(int fromScale)
{
int width, height;

StaticVector<float> depthMap;
StaticVector<float> simMap;
image::Image<float> depthMap;
image::Image<float> simMap;

image::readImage(getFileNameFromIndex(_mp, _rc, mvsUtils::EFileType::depthMap, fromScale),
width, height, depthMap.getDataWritable(), image::EImageColorSpace::NO_CONVERSION);
depthMap, image::EImageColorSpace::NO_CONVERSION);
image::readImage(getFileNameFromIndex(_mp, _rc, mvsUtils::EFileType::simMap, fromScale),
width, height, simMap.getDataWritable(), image::EImageColorSpace::NO_CONVERSION);
simMap, image::EImageColorSpace::NO_CONVERSION);

initFromDepthMapAndSimMap(&depthMap, &simMap, fromScale);
initFromDepthMapAndSimMap(depthMap, simMap, fromScale);
}

} // namespace depthMap
Expand Down
14 changes: 8 additions & 6 deletions src/aliceVision/depthMap/DepthSimMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include <aliceVision/image/Image.hpp>
#include <aliceVision/mvsData/Universe.hpp>
#include <aliceVision/mvsData/Pixel.hpp>
#include <aliceVision/mvsData/Point2d.hpp>
Expand Down Expand Up @@ -97,8 +98,9 @@ class DepthSimMap

void initJustFromDepthMap(const StaticVector<float>& depthMap, float defaultSim);
void initJustFromDepthMap(const DepthSimMap& depthSimMap, float defaultSim);
void initFromDepthMapAndSimMap(StaticVector<float>* depthMapT, StaticVector<float>* simMapT,
int depthSimMapsScale);
void initFromDepthMapAndSimMap(const image::Image<float>& depthMapT,
const image::Image<float>& simMapT,
int depthSimMapsScale);

void initFromSmaller(const DepthSimMap& depthSimMap);
void init(const DepthSimMap& depthSimMap);
Expand All @@ -107,10 +109,10 @@ class DepthSimMap
Point2d getMaxMinSim() const;

float getPercentileDepth(float perc) const;
void getDepthMapStep1(StaticVector<float>& out_depthMap) const;
void getSimMapStep1(StaticVector<float>& out_simMap) const;
void getDepthMap(StaticVector<float>& out_depthMap) const;
void getSimMap(StaticVector<float>& out_simMap) const;
void getDepthMapStep1(image::Image<float>& out_depthMap) const;
void getSimMapStep1(image::Image<float>& out_simMap) const;
void getDepthMap(image::Image<float>& out_depthMap) const;
void getSimMap(image::Image<float>& out_simMap) const;

void getDepthMapStep1XPart(StaticVector<float>& out_depthMap, int xFrom, int partW);
void getSimMapStep1XPart(StaticVector<float>& out_depthMap, int xFrom, int partW);
Expand Down
12 changes: 6 additions & 6 deletions src/aliceVision/depthMap/cuda/PlaneSweepingCuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ void PlaneSweepingCuda::deleteNormalMapping( NormalMapping* m )

bool PlaneSweepingCuda::computeNormalMap(
NormalMapping* mapping,
const std::vector<float>& depthMap,
std::vector<image::RGBfColor>& normalMap,
const image::Image<float>& depthMap,
image::Image<image::RGBfColor>& normalMap,
int rc, int scale,
float igammaC, float igammaP, int wsh)
{
Expand All @@ -696,7 +696,7 @@ bool PlaneSweepingCuda::computeNormalMap(
cps_host_fillCamera( *mapping->camsBasesHst, rc, _mp, scale );
mapping->loadCameraParameters();
mapping->allocHostMaps( w, h );
mapping->copyDepthMap( depthMap );
mapping->copyDepthMap(depthMap.data(), depthMap.size());

ps_computeNormalMap( mapping,
w, h, scale - 1,
Expand All @@ -714,9 +714,9 @@ bool PlaneSweepingCuda::computeNormalMap(
{
for (int i = 0; i < w * h; i++)
{
normalMap[i].r() = normalMapPtr[i].x;
normalMap[i].g() = normalMapPtr[i].y;
normalMap[i].b() = normalMapPtr[i].z;
normalMap(i).r() = normalMapPtr[i].x;
normalMap(i).g() = normalMapPtr[i].y;
normalMap(i).b() = normalMapPtr[i].z;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/depthMap/cuda/PlaneSweepingCuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class PlaneSweepingCuda
void deleteNormalMapping( NormalMapping* m );

bool computeNormalMap( NormalMapping* mapping,
const std::vector<float>& depthMap,
std::vector<image::RGBfColor>& normalMap,
const image::Image<float>& depthMap,
image::Image<image::RGBfColor>& normalMap,
int rc, int scale,
float igammaC, float igammaP, int wsh);

Expand Down
6 changes: 3 additions & 3 deletions src/aliceVision/depthMap/cuda/normalmap/normal_map.cu
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ void NormalMapping::allocHostMaps( int w, int h )
}
}

void NormalMapping::copyDepthMap( const std::vector<float>& depthMap )
void NormalMapping::copyDepthMap(const float* depthMap , int depthMapSize)
{
if( _allocated_floats > depthMap.size() )
if (_allocated_floats > depthMapSize)
{
std::cerr << "WARNING: " << __FILE__ << ":" << __LINE__
<< ": copying depthMap whose origin is too small" << std::endl;
}
memcpy( _depthMapHst, depthMap.data(), _allocated_floats*sizeof(float) );
memcpy( _depthMapHst, depthMap, _allocated_floats*sizeof(float) );
}

const float* NormalMapping::getDepthMapHst() const
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/depthMap/cuda/normalmap/normal_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NormalMapping

void loadCameraParameters();
void allocHostMaps( int w, int h );
void copyDepthMap( const std::vector<float>& depthMap );
void copyDepthMap(const float* depthMap, int depthMapSize);

const float* getDepthMapHst() const; // an input
float3* getNormalMapHst(); // an output
Expand Down
15 changes: 6 additions & 9 deletions src/aliceVision/depthMap/depthMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,16 @@ void computeNormalMaps(int cudaDeviceIndex, mvsUtils::MultiViewParams& mp, const

if (!fs::exists(normalMapFilepath))
{
std::vector<float> depthMap;
int w = 0;
int h = 0;
readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, 0), w, h, depthMap,
image::Image<float> depthMap;
readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, 0), depthMap,
image::EImageColorSpace::NO_CONVERSION);

std::vector<image::RGBfColor> normalMap;
normalMap.resize(mp.getWidth(rc) * mp.getHeight(rc));
image::Image<image::RGBfColor> normalMap(mp.getWidth(rc), mp.getHeight(rc));

cps.computeNormalMap(mapping, depthMap, normalMap, rc, 1, gammaC, gammaP, wsh);
image::writeImage(normalMapFilepath, mp.getWidth(rc), mp.getHeight(rc), normalMap,
image::EImageQuality::LOSSLESS,
image::OutputFileColorSpace(image::EImageColorSpace::NO_CONVERSION));
image::writeImage(normalMapFilepath, normalMap,
image::ImageWriteOptions().toColorSpace(image::EImageColorSpace::LINEAR)
.storageDataType(image::EStorageDataType::Float));
}
}
cps.deleteNormalMapping(mapping);
Expand Down
Loading