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

[depthMap] [fuseCut] remove image transposition #653

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions src/aliceVision/depthMap/DepthSimMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,6 @@ void DepthSimMap::load(int rc, int fromScale)
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, fromScale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, fromScale), width, height, simMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, depthMap.getDataWritable());
imageIO::transposeImage(width, height, simMap.getDataWritable());

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

Expand Down
180 changes: 78 additions & 102 deletions src/aliceVision/fuseCut/Fuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool Fuser::updateInSurr(int pixSizeBall, int pixSizeBallWSP, Point3d& p, int rc

int d = pixSizeBall;

float sim = (*simMap)[cell.x * h + cell.y];
float sim = (*simMap)[cell.y * w + cell.x];
if(sim >= 1.0f)
{
d = pixSizeBallWSP;
Expand All @@ -116,13 +116,13 @@ bool Fuser::updateInSurr(int pixSizeBall, int pixSizeBallWSP, Point3d& p, int rc
for(ncell.y = std::max(0, cell.y - d); ncell.y <= std::min(h - 1, cell.y + d); ncell.y++)
{
// printf("%i %i %i %i %i %i %i %i\n",ncell.x,ncell.y,w,h,w*h,depthMap->size(),cam,scale);
float depth = (*depthMap)[ncell.x * h + ncell.y];
float depth = (*depthMap)[ncell.y * w + ncell.x];
// Point3d p1 = mp->CArr[rc] +
// (mp->iCamArr[rc]*Point2d((float)ncell.x*(float)scale,(float)ncell.y*(float)scale)).normalize()*depth;
// if ( (p1-p).size() < pixSize ) {
if(fabs(pixDepth - depth) < pixSize)
{
(*numOfPtsMap)[ncell.x * h + ncell.y]++;
(*numOfPtsMap)[ncell.y * w + ncell.x]++;
}
}
}
Expand Down Expand Up @@ -165,9 +165,6 @@ bool Fuser::filterGroupsRC(int rc, int pixSizeBall, int pixSizeBallWSP, int nNea

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, 1), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, 1), width, height, simMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, depthMap.getDataWritable());
imageIO::transposeImage(width, height, simMap.getDataWritable());
}

std::vector<unsigned char> numOfModalsMap(w * h, 0);
Expand Down Expand Up @@ -195,26 +192,22 @@ bool Fuser::filterGroupsRC(int rc, int pixSizeBall, int pixSizeBallWSP, int nNea

{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, tc, mvsUtils::EFileType::depthMap, 1), width, height, tcdepthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

// transpose image in-place, width/height are no more valid after this function.
imageIO::transposeImage(width, height, tcdepthMap.getDataWritable());
}

if(!tcdepthMap.empty())
{
for(int i = 0; i < sizeOfStaticVector<float>(&tcdepthMap); i++)
{
int x = i / h;
int y = i % h;
float depth = tcdepthMap[i];
if(depth > 0.0f)
for(int y = 0; y < h; ++y)
for(int x = 0; x < w; ++x)
{
Point3d p = mp->CArr[tc] + (mp->iCamArr[tc] * Point2d((float)x, (float)y)).normalize() * depth;
updateInSurr(pixSizeBall, pixSizeBallWSP, p, rc, tc, numOfPtsMap, &depthMap, &simMap, 1);
float depth = tcdepthMap[y * w + x];
if(depth > 0.0f)
{
Point3d p = mp->CArr[tc] + (mp->iCamArr[tc] * Point2d((float)x, (float)y)).normalize() * depth;
updateInSurr(pixSizeBall, pixSizeBallWSP, p, rc, tc, numOfPtsMap, &depthMap, &simMap, 1);
}
}
}


for(int i = 0; i < w * h; i++)
{
Expand All @@ -226,7 +219,6 @@ bool Fuser::filterGroupsRC(int rc, int pixSizeBall, int pixSizeBallWSP, int nNea
{
using namespace imageIO;
OutputFileColorSpace colorspace(EImageColorSpace::NO_CONVERSION);
transposeImage(h, w, numOfModalsMap);
writeImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::nmodMap), w, h, numOfModalsMap, EImageQuality::LOSSLESS, colorspace);
}

Expand Down Expand Up @@ -273,10 +265,6 @@ bool Fuser::filterDepthMapsRC(int rc, int minNumOfModals, int minNumOfModalsWSP2
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, 1), width, height, depthMap, imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, 1), width, height, simMap, imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::nmodMap), width, height, numOfModalsMap, imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, depthMap);
imageIO::transposeImage(width, height, simMap);
imageIO::transposeImage(width, height, numOfModalsMap);
}

int nbDepthValues = 0;
Expand Down Expand Up @@ -309,9 +297,6 @@ bool Fuser::filterDepthMapsRC(int rc, int minNumOfModals, int minNumOfModalsWSP2
++nbDepthValues;
}

imageIO::transposeImage(h, w, depthMap);
imageIO::transposeImage(h, w, simMap);

oiio::ParamValueList metadata = imageIO::getMetadataFromMap(mp->getMetadata(rc));
metadata.push_back(oiio::ParamValue("AliceVision:nbDepthValues", oiio::TypeDesc::INT32, 1, &nbDepthValues));
metadata.push_back(oiio::ParamValue("AliceVision:downscale", mp->getDownscaleFactor(rc)));
Expand Down Expand Up @@ -350,39 +335,37 @@ float Fuser::computeAveragePixelSizeInHexahedron(Point3d* hexah, int step, int s
{
int rc = cams[c];
int h = mp->getHeight(rc) / scaleuse;
int w = mp->getWidth(rc) / scaleuse;
StaticVector<float> rcdepthMap;

{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, rcdepthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, rcdepthMap.getDataWritable());
}

for(int i = 0; i < rcdepthMap.size(); i++)
{
int x = i / h;
int y = i % h;
float depth = rcdepthMap[i];
if(depth > 0.0f)
for(int y = 0; y < h; y++)
for(int x = 0; x < w; ++x)
{
if(j % step == 0)
float depth = rcdepthMap[y * w + x];
if(depth > 0.0f)
{
Point3d p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((float)x * (float)scaleuse, (float)y * (float)scaleuse))
.normalize() *
depth;
if(mvsUtils::isPointInHexahedron(p, hexah))
if(j % step == 0)
{
float v = mp->getCamPixelSize(p, rc);
av += v; // WARNING: the value may be too big for a float
nav += 1.0f;
minv = std::min(minv, v);
Point3d p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((float)x * (float)scaleuse, (float)y * (float)scaleuse))
.normalize() *
depth;
if(mvsUtils::isPointInHexahedron(p, hexah))
{
float v = mp->getCamPixelSize(p, rc);
av += v; // WARNING: the value may be too big for a float
nav += 1.0f;
minv = std::min(minv, v);
}
}
j++;
}
j++;
}
}
//mvsUtils::printfEstimate(c, cams.size(), t1);
}
//mvsUtils::finishEstimate();
Expand Down Expand Up @@ -447,21 +430,19 @@ void Fuser::divideSpaceFromDepthMaps(Point3d* hexah, float& minPixSize)
Stat3d s3d = Stat3d();
for(int rc = 0; rc < mp->ncams; rc++)
{
int h = mp->getHeight(rc);
int w = mp->getWidth(rc);

StaticVector<float> depthMap;
{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, depthMap.getDataWritable());
}

for(int i = 0; i < sizeOfStaticVector<float>(&depthMap); i += stepPts)
{
int x = i / h;
int y = i % h;
int x = i % w;
int y = i / w;
float depth = depthMap[i];
if(depth > 0.0f)
{
Expand Down Expand Up @@ -493,21 +474,19 @@ void Fuser::divideSpaceFromDepthMaps(Point3d* hexah, float& minPixSize)

for(int rc = 0; rc < mp->ncams; ++rc)
{
int h = mp->getHeight(rc);
int w = mp->getWidth(rc);

StaticVector<float> depthMap;
{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, depthMap.getDataWritable());
}

for(int i = 0; i < depthMap.size(); i += stepPts)
{
int x = i / h;
int y = i % h;
int x = i % w;
int y = i / w;
float depth = depthMap[i];
if(depth > 0.0f)
{
Expand Down Expand Up @@ -766,9 +745,6 @@ std::string generateTempPtsSimsFiles(std::string tmpDir, mvsUtils::MultiViewPara

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, scale), width, height, simMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageIO::transposeImage(width, height, depthMap.getDataWritable());
imageIO::transposeImage(width, height, simMap.getDataWritable());
}

if(addRandomNoise)
Expand All @@ -789,54 +765,54 @@ std::string generateTempPtsSimsFiles(std::string tmpDir, mvsUtils::MultiViewPara
srand(time(nullptr));

long t1 = clock();
for(int id = 0; id < idsAlive->size(); id++)
{
int i = (*idsAlive)[(*randIdsAlive)[id]];
int x = i / h;
int y = i % h;
double depth = depthMap[i];

double sim = simMap[i];
if(depth > 0.0f)
for(int y = 0; y < h; ++y)
for(int x = 0; x < w; ++x)
{
Point3d p = mp->CArr[rc] +
int id = y * w + x;
int i = (*idsAlive)[(*randIdsAlive)[id]];
double depth = depthMap[i];

double sim = simMap[i];
if(depth > 0.0f)
{
Point3d p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((double)x * (double)scaleuse, (double)y * (double)scaleuse))
.normalize() *
depth;

if(id < nnoisePts)
{
double pixSize = mp->getCamPixelSize(p, rc);
int rid = rand() % (2 * noisPixSizeDistHalfThr + 1);
rid = rid - noisPixSizeDistHalfThr;
double rdepthAdd = pixSize * (double)rid;
depth = depth + rdepthAdd;
p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((double)x * (double)scaleuse, (double)y * (double)scaleuse))
.normalize() *
depth;
}

if(id < nnoisePts)
{
double pixSize = mp->getCamPixelSize(p, rc);
int rid = rand() % (2 * noisPixSizeDistHalfThr + 1);
rid = rid - noisPixSizeDistHalfThr;
double rdepthAdd = pixSize * (double)rid;
depth = depth + rdepthAdd;
p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((double)x * (double)scaleuse, (double)y * (double)scaleuse))
.normalize() *
depth;
}

pts->push_back(p);
sims->push_back(sim);
if((*minMaxDepths)[rc].x < 0.0f)
{
(*minMaxDepths)[rc].x = depth;
}
else
{
(*minMaxDepths)[rc].x = std::min((*minMaxDepths)[rc].x, depth);
}
if((*minMaxDepths)[rc].y < 0.0f)
{
(*minMaxDepths)[rc].y = depth;
}
else
{
(*minMaxDepths)[rc].y = std::max((*minMaxDepths)[rc].y, depth);
pts->push_back(p);
sims->push_back(sim);
if((*minMaxDepths)[rc].x < 0.0f)
{
(*minMaxDepths)[rc].x = depth;
}
else
{
(*minMaxDepths)[rc].x = std::min((*minMaxDepths)[rc].x, depth);
}
if((*minMaxDepths)[rc].y < 0.0f)
{
(*minMaxDepths)[rc].y = depth;
}
else
{
(*minMaxDepths)[rc].y = std::max((*minMaxDepths)[rc].y, depth);
}
}
}
}
if(mp->verbose)
mvsUtils::printfElapsedTime(t1);

Expand Down