From 4a98bfc2acb4239cec50f846c18ce0680dba538c Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Tue, 12 Nov 2019 20:13:36 +0200 Subject: [PATCH] Minor corrections --- components/operators/src/mls.cu | 71 +++++++++++++------------- components/operators/src/smoothing.cpp | 6 +-- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/components/operators/src/mls.cu b/components/operators/src/mls.cu index 70d801f2f..64fb921df 100644 --- a/components/operators/src/mls.cu +++ b/components/operators/src/mls.cu @@ -273,54 +273,55 @@ __device__ inline int segmentID(int u, int v) { for (int u=-baseY.x; u<=baseY.y; ++u) { const float d = depth_in.tex2D(x+u, y+v); - if (d < camera.minDepth || d > camera.maxDepth) continue; + if (d > camera.minDepth && d < camera.maxDepth) { - // Point and normal of neighbour - const float3 Xi = camera.screenToCam((int)(x)+u,(int)(y)+v,d); - const float3 Ni = make_float3(normals_in.tex2D((int)(x)+u, (int)(y)+v)); + // Point and normal of neighbour + const float3 Xi = camera.screenToCam((int)(x)+u,(int)(y)+v,d); + const float3 Ni = make_float3(normals_in.tex2D((int)(x)+u, (int)(y)+v)); - if (Ni.x+Ni.y+Ni.z == 0.0f) continue; + if (Ni.x+Ni.y+Ni.z == 0.0f) continue; - const float4 c = colour_in.tex2D(float(x+u) + 0.5f, float(y+v) + 0.5f); - const float cw = ftl::cuda::colourWeighting(c0,c,colour_smoothing); + const float4 c = colour_in.tex2D(float(x+u) + 0.5f, float(y+v) + 0.5f); + const float cw = ftl::cuda::colourWeighting(c0,c,colour_smoothing); - // Allow missing point to borrow z value - // TODO: This is a bad choice of Z! Perhaps try histogram vote approach - if (FILLING && d0 == 0.0f) X = camera.screenToCam((int)(x),(int)(y),Xi.z); + // Allow missing point to borrow z value + // TODO: This is a bad choice of Z! Perhaps try histogram vote approach + if (FILLING && d0 == 0.0f) X = camera.screenToCam((int)(x),(int)(y),Xi.z); - // Gauss approx weighting function using point distance - const float w = ftl::cuda::spatialWeighting(X,Xi,smoothing*cw); + // Gauss approx weighting function using point distance + const float w = ftl::cuda::spatialWeighting(X,Xi,smoothing*cw); - aX += Xi*w; - nX += Ni*w; - contrib += w; - if (FILLING && w > 0.0f && v > -base.z+1 && v < base.w-1 && u > -baseY.x+1 && u < baseY.y-1) segment_check |= segmentID(u,v); + aX += Xi*w; + nX += Ni*w; + contrib += w; + if (FILLING && w > 0.0f && v > -base.z+1 && v < base.w-1 && u > -baseY.x+1 && u < baseY.y-1) segment_check |= segmentID(u,v); + } } } - if (contrib == 0.0f) return; - - nX /= contrib; // Weighted average normal - aX /= contrib; // Weighted average point (centroid) + if (contrib > 0.0f) { + nX /= contrib; // Weighted average normal + aX /= contrib; // Weighted average point (centroid) - if (FILLING && d0 == 0.0f) { - if (__popc(segment_check) < 3) return; - X = camera.screenToCam((int)(x),(int)(y),aX.z); - } + if (FILLING && d0 == 0.0f) { + if (__popc(segment_check) < 3) return; + X = camera.screenToCam((int)(x),(int)(y),aX.z); + } - // Signed-Distance Field function - float fX = nX.x * (X.x - aX.x) + nX.y * (X.y - aX.y) + nX.z * (X.z - aX.z); + // Signed-Distance Field function + float fX = nX.x * (X.x - aX.x) + nX.y * (X.y - aX.y) + nX.z * (X.z - aX.z); - // Calculate new point using SDF function to adjust depth (and position) - X = X - nX * fX; - - //uint2 screen = camera.camToScreen<uint2>(X); + // Calculate new point using SDF function to adjust depth (and position) + X = X - nX * fX; + + //uint2 screen = camera.camToScreen<uint2>(X); - //if (screen.x < depth_out.width() && screen.y < depth_out.height()) { - // depth_out(screen.x,screen.y) = X.z; - //} - depth_out(x,y) = X.z; - normals_out(x,y) = make_float4(nX / length(nX), 0.0f); + //if (screen.x < depth_out.width() && screen.y < depth_out.height()) { + // depth_out(screen.x,screen.y) = X.z; + //} + depth_out(x,y) = X.z; + normals_out(x,y) = make_float4(nX / length(nX), 0.0f); + } } void ftl::cuda::colour_mls_smooth_csr( diff --git a/components/operators/src/smoothing.cpp b/components/operators/src/smoothing.cpp index 359b17714..8b49b9676 100644 --- a/components/operators/src/smoothing.cpp +++ b/components/operators/src/smoothing.cpp @@ -179,11 +179,11 @@ ColourMLS::~ColourMLS() { } bool ColourMLS::apply(ftl::rgbd::Frame &in, ftl::rgbd::Frame &out, ftl::rgbd::Source *s, cudaStream_t stream) { - float thresh = config()->value("mls_threshold", 0.04f); + float thresh = config()->value("mls_threshold", 0.4f); float col_smooth = config()->value("mls_colour_smoothing", 30.0f); - int iters = config()->value("mls_iterations", 10); + int iters = config()->value("mls_iterations", 3); int radius = config()->value("mls_radius",3); - bool crosssup = config()->value("cross_support", false); + bool crosssup = config()->value("cross_support", true); bool filling = config()->value("filling", false); if (!in.hasChannel(Channel::Normals)) { -- GitLab