Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convolution2d seems to be not correct. #722

Closed
cgringmuth opened this issue Jan 31, 2023 · 1 comment
Closed

Convolution2d seems to be not correct. #722

cgringmuth opened this issue Jan 31, 2023 · 1 comment

Comments

@cgringmuth
Copy link
Contributor

cgringmuth commented Jan 31, 2023

Actual behavior

If i provide the example sobel_scharr.cpp with following image: small_box2
I get (for sobel filter)

Grad X Grad Y
output2-x output2-y

Which is not correct in my opinion.

Expected behavior

I have written a unit test which explains what I would expect from a 2 d convolution with sobel filter for the x direction.

void test_convolve_2d_with_sobel_x_filter()
{
  const gil::uint8_t img[] =
      {
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
          0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
          0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
          0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
          0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0
      };

  const gil::int16_t exp_output[] =
      {
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 255, 255, 0, 0, -255, -255, 0, 0, 0,
          0, 765, 765, 0, 0, -765, -765, 0, 0, 0,
          0, 1020, 1020, 0, 0, -1020, -1020, 0, 0, 0,
          0, 1020, 1020, 0, 0, -1020, -1020, 0, 0, 0,
          0, 1020, 1020, 0, 0, -1020, -1020, 0, 0, 0,
          0, 765, 765, 0, 0, -765, -765, 0, 0, 0,
          0, 255, 255, 0, 0, -255, -255, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0
      };

  gil::gray16s_image_t img_gray_out(10, 13);
  auto src_view =
      gil::interleaved_view(10, 13, reinterpret_cast<const gil::gray8_pixel_t*>(img), 10);
  auto exp_out_view =
      gil::interleaved_view(10, 13, reinterpret_cast<const gil::gray16s_pixel_t*>(exp_output), 20);
  gil::detail::convolve_2d(src_view, gil::generate_dx_sobel(1), view(img_gray_out));
  
  BOOST_TEST(gil::equal_pixels(exp_out_view, view(img_gray_out)));
}

C++ Minimal Working Example

See unit test in Expected behavior.

Environment

Should be independent of environment. I didn't have any crash or something.

PS: I also don't know how to properly debug code in GIL properly. How I can see the content of an image in the debugger?

@cgringmuth
Copy link
Contributor Author

cgringmuth commented Jan 31, 2023

I think I fixed the issue already. Will create PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant