Skip to content

Commit

Permalink
First_cleaning_attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
meshtag committed Aug 14, 2021
1 parent fe1621e commit bd01761
Show file tree
Hide file tree
Showing 15 changed files with 1,475 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on:
on:
pull_request:
push:
branches:
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ message(STATUS "Boost.GIL: Using Boost_LIBRARY_DIRS=${Boost_LIBRARY_DIRS}")

target_link_libraries(gil_dependencies INTERFACE Boost::filesystem)

if (BOOST_GIL_ENABLE_OPENCV)
find_package (OpenCV 4.0.0 REQUIRED)
target_include_directories(gil_dependencies INTERFACE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(gil_dependencies INTERFACE ${OpenCV_LIBS})
endif()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_link_libraries(gil_dependencies INTERFACE Boost::disable_autolinking)
endif()
Expand Down
2 changes: 1 addition & 1 deletion example/convolve2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int main()

std::vector<float> v(9, 1.0f / 9.0f);
detail::kernel_2d<float> kernel(v.begin(), v.size(), 1, 1);
detail::convolve_2d(view(img), kernel, view(img_out1));
convolve_2d<gray8_pixel_t>(view(img), kernel, view(img_out1));

//write_view("out-convolve2d.png", view(img_out), png_tag{});
write_view("out-convolve2d.png", view(img_out1), jpeg_tag{});
Expand Down
4 changes: 2 additions & 2 deletions example/harris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ int main(int argc, char* argv[])
auto x_gradient = gil::view(x_gradient_image);
auto y_gradient = gil::view(y_gradient_image);
auto scharr_x = gil::generate_dx_scharr();
gil::detail::convolve_2d(smoothed, scharr_x, x_gradient);
gil::convolve_2d<gil::gray8_pixel_t>(smoothed, scharr_x, x_gradient);
auto scharr_y = gil::generate_dy_scharr();
gil::detail::convolve_2d(smoothed, scharr_y, y_gradient);
gil::convolve_2d<gil::gray8_pixel_t>(smoothed, scharr_y, y_gradient);

gil::gray32f_image_t m11(x_gradient.dimensions());
gil::gray32f_image_t m12_21(x_gradient.dimensions());
Expand Down
18 changes: 9 additions & 9 deletions example/hessian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,20 @@ int main(int argc, char* argv[]) {
auto x_gradient = gil::view(x_gradient_image);
auto y_gradient = gil::view(y_gradient_image);
auto scharr_x = gil::generate_dx_scharr();
gil::detail::convolve_2d(smoothed, scharr_x, x_gradient);
gil::convolve_2d<gil::gray16s_pixel_t>(smoothed, scharr_x, x_gradient);
auto scharr_y = gil::generate_dy_scharr();
gil::detail::convolve_2d(smoothed, scharr_y, y_gradient);
gil::convolve_2d<gil::gray16s_pixel_t>(smoothed, scharr_y, y_gradient);

gil::gray32f_image_t m11(x_gradient.dimensions());
gil::gray32f_image_t m12_21(x_gradient.dimensions());
gil::gray32f_image_t m22(x_gradient.dimensions());
gil::compute_hessian_entries(
x_gradient,
y_gradient,
gil::view(m11),
gil::view(m12_21),
gil::view(m22)
);
// gil::compute_hessian_entries(
// gil::view(x_gradient_image),
// gil::view(y_gradient_image),
// gil::view(m11),
// gil::view(m12_21),
// gil::view(m22)
// );

gil::gray32f_image_t hessian_response(x_gradient.dimensions());
auto gaussian_kernel = gil::generate_gaussian_kernel(window_size, 0.84089642);
Expand Down
8 changes: 4 additions & 4 deletions example/sobel_scharr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ int main(int argc, char* argv[])
auto dy = gil::view(dy_image);
if (filter_type == "sobel")
{
gil::detail::convolve_2d(input, gil::generate_dx_sobel(1), dx);
gil::detail::convolve_2d(input, gil::generate_dy_sobel(1), dy);
gil::convolve_2d<gil::gray8_pixel_t>(input, gil::generate_dx_sobel(1), dx);
gil::convolve_2d<gil::gray8_pixel_t>(input, gil::generate_dy_sobel(1), dy);
}
else if (filter_type == "scharr")
{
gil::detail::convolve_2d(input, gil::generate_dx_scharr(1), dx);
gil::detail::convolve_2d(input, gil::generate_dy_scharr(1), dy);
gil::convolve_2d<gil::gray8_pixel_t>(input, gil::generate_dx_scharr(1), dx);
gil::convolve_2d<gil::gray8_pixel_t>(input, gil::generate_dy_scharr(1), dy);
}
else
{
Expand Down
109 changes: 104 additions & 5 deletions include/boost/gil/extension/numeric/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,104 @@ auto correlate_pixels_k(
return dst_begin;
}

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);
std::ptrdiff_t index = 0;
std::ptrdiff_t const kernel_size = kernel_dimension * kernel_dimension;

// try eliminating "index" variable.
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;
}

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);
std::ptrdiff_t 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 @@ -255,11 +353,12 @@ void view_multiplies_scalar(SrcView const& src_view, Scalar const& scalar, DstVi
/// \brief Boundary options for image boundary extension
enum class boundary_option
{
output_ignore, /// do nothing to the output
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
output_ignore, /// do nothing to the output
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_reflection /// assumes boundary values as reflection of source row/column pixels
};

namespace detail
Expand Down
Loading

0 comments on commit bd01761

Please sign in to comment.