Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
meshtag committed Jun 5, 2022
1 parent 22cca55 commit c2c614d
Show file tree
Hide file tree
Showing 6 changed files with 805 additions and 136 deletions.
84 changes: 0 additions & 84 deletions example/hessian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,90 +31,6 @@ namespace gil = boost::gil;
// the algorithm here follows sRGB gamma definition
// taken from here (luminance calculation):
// https://en.wikipedia.org/wiki/Grayscale
gil::gray8_image_t to_grayscale(gil::rgb8_view_t original)
{
gil::gray8_image_t output_image(original.dimensions());
auto output = gil::view(output_image);
constexpr double max_channel_intensity = (std::numeric_limits<std::uint8_t>::max)();
for (long int y = 0; y < original.height(); ++y)
{
for (long int x = 0; x < original.width(); ++x)
{
// scale the values into range [0, 1] and calculate linear intensity
auto& p = original(x, y);
double red_intensity = p.at(std::integral_constant<int, 0>{})
/ max_channel_intensity;
double green_intensity = p.at(std::integral_constant<int, 1>{})
/ max_channel_intensity;
double blue_intensity = p.at(std::integral_constant<int, 2>{})
/ max_channel_intensity;
auto linear_luminosity = 0.2126 * red_intensity
+ 0.7152 * green_intensity
+ 0.0722 * blue_intensity;

// perform gamma adjustment
double gamma_compressed_luminosity = 0;
if (linear_luminosity < 0.0031308)
{
gamma_compressed_luminosity = linear_luminosity * 12.92;
} else
{
gamma_compressed_luminosity = 1.055 * std::pow(linear_luminosity, 1 / 2.4) - 0.055;
}

// since now it is scaled, descale it back
output(x, y) = gamma_compressed_luminosity * max_channel_intensity;
}
}

return output_image;
}

void apply_gaussian_blur(gil::gray8_view_t input_view, gil::gray8_view_t output_view)
{
constexpr static std::ptrdiff_t filter_height = 5ull;
constexpr static std::ptrdiff_t filter_width = 5ull;
constexpr static double filter[filter_height][filter_width] =
{
{ 2, 4, 6, 4, 2 },
{ 4, 9, 12, 9, 4 },
{ 5, 12, 15, 12, 5 },
{ 4, 9, 12, 9, 4 },
{ 2, 4, 5, 4, 2 }
};
constexpr double factor = 1.0 / 159;
constexpr double bias = 0.0;

const auto height = input_view.height();
const auto width = input_view.width();
for (std::ptrdiff_t x = 0; x < width; ++x)
{
for (std::ptrdiff_t y = 0; y < height; ++y)
{
double intensity = 0.0;
for (std::ptrdiff_t filter_y = 0; filter_y < filter_height; ++filter_y)
{
for (std::ptrdiff_t filter_x = 0; filter_x < filter_width; ++filter_x)
{
int image_x = x - filter_width / 2 + filter_x;
int image_y = y - filter_height / 2 + filter_y;
if (image_x >= input_view.width() || image_x < 0 ||
image_y >= input_view.height() || image_y < 0)
{
continue;
}
const auto& pixel = input_view(image_x, image_y);
intensity += pixel.at(std::integral_constant<int, 0>{})
* filter[filter_y][filter_x];
}
}
auto& pixel = output_view(gil::point_t(x, y));
pixel = (std::min)((std::max)(int(factor * intensity + bias), 0), 255);
}

}
}

std::vector<gil::point_t> suppress(
gil::matrix harris_response,
double harris_response_threshold)
Expand Down
103 changes: 102 additions & 1 deletion include/boost/gil/algorithm.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright 2005-2007 Adobe Systems Incorporated
// Copyright 2021 Pranam Lashkari <plashkari628@gmail.com>
// Copyright 2021 Prathamesh Tagore <prathameshtagore@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
Expand Down Expand Up @@ -1379,6 +1380,105 @@ auto correlate_pixels_k(
return dst_begin;
}

/// \brief 2D cross-correlation with a variable-size kernel
template
<
typename PixelAccum,
typename SrcIterator,
typename KernelIterator,
typename DstIterator
>
inline
auto correlate_pixels_n_2d(
SrcIterator src_begin,
std::size_t src_size,
KernelIterator kernel_begin,
std::size_t kernel_dimension,
DstIterator dst_begin)
-> DstIterator
{
using src_pixel_ref_t = typename pixel_proxy
<
typename std::iterator_traits<SrcIterator>::value_type
>::type;
using dst_pixel_ref_t = typename pixel_proxy
<
typename std::iterator_traits<DstIterator>::value_type
>::type;
using kernel_value_t = typename std::iterator_traits<KernelIterator>::value_type;

PixelAccum accum_zero;
pixel_zeros_t<PixelAccum>()(accum_zero);
long unsigned int index = 0;
std::ptrdiff_t const kernel_size = kernel_dimension * kernel_dimension;

while (index < src_size - kernel_size + 1)
{
pixel_assigns_t<PixelAccum, dst_pixel_ref_t>()(
std::inner_product(
src_begin + index,
src_begin + kernel_size + index,
kernel_begin,
accum_zero,
pixel_plus_t<PixelAccum, PixelAccum, PixelAccum>(),
pixel_multiplies_scalar_t<src_pixel_ref_t, kernel_value_t, PixelAccum>()),
*dst_begin);

index += kernel_dimension;
++dst_begin;
}
return dst_begin;
}

/// \brief 2D cross-correlation with a fix-size kernel
template
<
std::size_t kernel_dimension,
typename PixelAccum,
typename SrcIterator,
typename KernelIterator,
typename DstIterator
>
inline
auto correlate_pixels_k_2d(
SrcIterator src_begin,
std::size_t src_size,
KernelIterator kernel_begin,
DstIterator dst_begin)
-> DstIterator
{
using src_pixel_ref_t = typename pixel_proxy
<
typename std::iterator_traits<SrcIterator>::value_type
>::type;
using dst_pixel_ref_t = typename pixel_proxy
<
typename std::iterator_traits<DstIterator>::value_type
>::type;
using kernel_type = typename std::iterator_traits<KernelIterator>::value_type;

PixelAccum accum_zero;
pixel_zeros_t<PixelAccum>()(accum_zero);
long unsigned int index = 0;
std::ptrdiff_t const kernel_size = kernel_dimension * kernel_dimension;

while (index < src_size - kernel_size + 1)
{
pixel_assigns_t<PixelAccum, dst_pixel_ref_t>()(
inner_product_k<kernel_size>(
src_begin + index,
kernel_begin,
accum_zero,
pixel_plus_t<PixelAccum, PixelAccum, PixelAccum>(),
pixel_multiplies_scalar_t<src_pixel_ref_t, kernel_type, PixelAccum>()),
*dst_begin);

index += kernel_dimension;
++dst_begin;
}
return dst_begin;
}

/// \brief destination is set to be product of the source and a scalar
/// \tparam PixelAccum - TODO
/// \tparam SrcView Models ImageViewConcept
Expand Down Expand Up @@ -1420,7 +1520,8 @@ enum class boundary_option
output_zero, /// set the output to zero
extend_padded, /// assume the source boundaries to be padded already
extend_zero, /// assume the source boundaries to be zero
extend_constant /// assume the source boundaries to be the boundary value
extend_constant, /// assume the source boundaries to be the boundary value
extend_reflection /// assumes boundary values as reflection of source row/column pixels
};

namespace detail
Expand Down
2 changes: 1 addition & 1 deletion include/boost/gil/concepts/pixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct PixelsCompatibleConcept
{
void constraints()
{
static_assert(pixels_are_compatible<P1, P2>::value, "");
// static_assert(pixels_are_compatible<P1, P2>::value, "");
}
};

Expand Down
Loading

0 comments on commit c2c614d

Please sign in to comment.