Skip to content
Snippets Groups Projects

Implements #228 adaptive MLS and smoothing channel

Merged Nicolas Pope requested to merge feature/mlssmooth into master
3 files
+ 24
16
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -9,10 +9,10 @@ using ftl::cuda::TextureObject;
template <int RADIUS>
__global__ void smooth_chan_kernel(
ftl::cuda::TextureObject<uchar4> colour_in,
ftl::cuda::TextureObject<float> depth_in,
//ftl::cuda::TextureObject<float> depth_in,
ftl::cuda::TextureObject<float> smoothing_out,
ftl::rgbd::Camera camera,
float alpha) {
float alpha, float scale) {
const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
@@ -24,27 +24,29 @@ __global__ void smooth_chan_kernel(
// A distance has already been found
if (smoothing_out(x,y) < 1.0f) return;
float mindist = 1.0f;
float mindist = 50.0f;
const uchar4 c0 = colour_in.tex2D(ix, iy);
const float d0 = depth_in.tex2D(ix, iy);
if (d0 < camera.minDepth || d0 > camera.maxDepth) return;
//const float d0 = depth_in.tex2D(ix, iy);
//if (d0 < camera.minDepth || d0 > camera.maxDepth) return;
const float3 pos = camera.screenToCam(ix, iy, d0);
//const float3 pos = camera.screenToCam(ix, iy, d0);
for (int v=-RADIUS; v<=RADIUS; ++v) {
#pragma unroll
for (int u=-RADIUS; u<=RADIUS; ++u) {
const uchar4 c = colour_in.tex2D(ix+u, iy+v);
const float d = depth_in.tex2D(ix+u, iy+v);
if (d < camera.minDepth || d > camera.maxDepth) continue;
const float3 posN = camera.screenToCam(ix+u, iy+v, d);
//const float d = depth_in.tex2D(ix+u, iy+v);
//if (d < camera.minDepth || d > camera.maxDepth) continue;
//const float3 posN = camera.screenToCam(ix+u, iy+v, d);
if (ftl::cuda::colourDistance(c, c0) >= alpha) mindist = min(mindist, length(pos - posN));
float d = sqrt((float)u*(float)u + (float)v*(float)v) * scale;
if (ftl::cuda::colourDistance(c, c0) >= alpha) mindist = min(mindist, (float)d);
}
}
smoothing_out(x,y) = min(mindist, 1.0f);
smoothing_out(x,y) = min(mindist / 50.0f, 1.0f);
}
}
@@ -54,6 +56,7 @@ void ftl::cuda::smooth_channel(
ftl::cuda::TextureObject<float> &smoothing_out,
const ftl::rgbd::Camera &camera,
float alpha,
float scale,
int radius,
cudaStream_t stream) {
@@ -62,11 +65,11 @@ void ftl::cuda::smooth_channel(
switch (radius) {
case 5: smooth_chan_kernel<5><<<gridSize, blockSize, 0, stream>>>(colour_in, depth_in, smoothing_out, camera, alpha); break;
case 4: smooth_chan_kernel<4><<<gridSize, blockSize, 0, stream>>>(colour_in, depth_in, smoothing_out, camera, alpha); break;
case 3: smooth_chan_kernel<3><<<gridSize, blockSize, 0, stream>>>(colour_in, depth_in, smoothing_out, camera, alpha); break;
case 2: smooth_chan_kernel<2><<<gridSize, blockSize, 0, stream>>>(colour_in, depth_in, smoothing_out, camera, alpha); break;
case 1: smooth_chan_kernel<1><<<gridSize, blockSize, 0, stream>>>(colour_in, depth_in, smoothing_out, camera, alpha); break;
case 5: smooth_chan_kernel<5><<<gridSize, blockSize, 0, stream>>>(colour_in, smoothing_out, camera, alpha, scale); break;
case 4: smooth_chan_kernel<4><<<gridSize, blockSize, 0, stream>>>(colour_in, smoothing_out, camera, alpha, scale); break;
case 3: smooth_chan_kernel<3><<<gridSize, blockSize, 0, stream>>>(colour_in, smoothing_out, camera, alpha, scale); break;
case 2: smooth_chan_kernel<2><<<gridSize, blockSize, 0, stream>>>(colour_in, smoothing_out, camera, alpha, scale); break;
case 1: smooth_chan_kernel<1><<<gridSize, blockSize, 0, stream>>>(colour_in, smoothing_out, camera, alpha, scale); break;
}
Loading