Skip to content

Commit

Permalink
blend mask feathering by a guided filter
Browse files Browse the repository at this point in the history
Feathering adjusts the blend mask by taking into account the image content
such that edges of the mask match those in the image.
  • Loading branch information
rabauke committed Nov 9, 2018
1 parent 473fe00 commit 20b0b24
Show file tree
Hide file tree
Showing 9 changed files with 728 additions and 48 deletions.
31 changes: 31 additions & 0 deletions data/kernels/blendop.cl
Expand Up @@ -1007,6 +1007,37 @@ blendop_rgb (__read_only image2d_t in_a, __read_only image2d_t in_b, __read_only
write_imagef(out, (int2)(x, y), o);
}

__kernel void
blendop_mask_enhance_contrast(__read_only image2d_t mask_in, __write_only image2d_t mask_out,
const int width, const int height,
const float e, const float brightness)
{
const int x = get_global_id(0);
const int y = get_global_id(1);

if ( x>= width || y >= height) return;

float opacity = read_imagef(mask_in, sampleri, (int2)(x, y)).x;
float scaled_opacity = 2.f * opacity - 1.f;
if (1.f - brightness <= 0.f)
scaled_opacity = opacity <= FLT_EPSILON ? -1.f : 1.f;
else if (1.f + brightness <= 0.f)
scaled_opacity = opacity >= 1.f - FLT_EPSILON ? 1.f : -1.f;
else if (brightness > 0.f)
{
scaled_opacity = (scaled_opacity + brightness) / (1.f - brightness);
scaled_opacity = fmin(scaled_opacity, 1.f);
}
else
{
scaled_opacity = (scaled_opacity + brightness) / (1.f + brightness);
scaled_opacity = fmax(scaled_opacity, -1.f);
}
opacity = (scaled_opacity * e / (1.f + (e - 1.f) * fabs(scaled_opacity))) / 2.f + 0.5f;
write_imagef(mask_out, (int2)(x, y), opacity);
}


__kernel void
blendop_set_mask (__write_only image2d_t mask, const int width, const int height, const float value)
{
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -29,6 +29,7 @@ FILE(GLOB SOURCE_FILES
"common/fswatch.c"
"common/gaussian.c"
"common/grouping.c"
"common/guided_filter.c"
"common/history.c"
"common/gpx.c"
"common/image.c"
Expand Down

0 comments on commit 20b0b24

Please sign in to comment.