| 540 | typename out_image_type |
| 541 | > |
| 542 | void binary_difference ( |
| 543 | const in_image_type1& in_img1_, |
| 544 | const in_image_type2& in_img2_, |
| 545 | out_image_type& out_img_ |
| 546 | ) |
| 547 | { |
| 548 | typedef typename image_traits<in_image_type1>::pixel_type in_pixel_type1; |
| 549 | typedef typename image_traits<in_image_type2>::pixel_type in_pixel_type2; |
| 550 | typedef typename image_traits<out_image_type>::pixel_type out_pixel_type; |
| 551 | COMPILE_TIME_ASSERT( pixel_traits<in_pixel_type1>::has_alpha == false ); |
| 552 | COMPILE_TIME_ASSERT( pixel_traits<in_pixel_type2>::has_alpha == false ); |
| 553 | COMPILE_TIME_ASSERT( pixel_traits<out_pixel_type>::has_alpha == false ); |
| 554 | |
| 555 | using namespace morphological_operations_helpers; |
| 556 | COMPILE_TIME_ASSERT(pixel_traits<in_pixel_type1>::grayscale); |
| 557 | COMPILE_TIME_ASSERT(pixel_traits<in_pixel_type2>::grayscale); |
| 558 | DLIB_ASSERT(is_binary_image(in_img1_) , |
| 559 | "\tvoid binary_difference()" |
| 560 | << "\n\tin_img1 must be a binary image" |
| 561 | ); |
| 562 | DLIB_ASSERT(is_binary_image(in_img2_) , |
| 563 | "\tvoid binary_difference()" |
| 564 | << "\n\tin_img2 must be a binary image" |
| 565 | ); |
| 566 | |
| 567 | const_image_view<in_image_type1> in_img1(in_img1_); |
| 568 | const_image_view<in_image_type2> in_img2(in_img2_); |
| 569 | image_view<out_image_type> out_img(out_img_); |
| 570 | |
| 571 | DLIB_ASSERT(in_img1.nc() == in_img2.nc(), |
| 572 | "\tvoid binary_difference()" |
| 573 | << "\n\tin_img1 and in_img2 must have the same ncs." |
| 574 | << "\n\tin_img1.nc(): " << in_img1.nc() |
| 575 | << "\n\tin_img2.nc(): " << in_img2.nc() |
| 576 | ); |
| 577 | DLIB_ASSERT(in_img1.nr() == in_img2.nr(), |
| 578 | "\tvoid binary_difference()" |
| 579 | << "\n\tin_img1 and in_img2 must have the same nrs." |
| 580 | << "\n\tin_img1.nr(): " << in_img1.nr() |
| 581 | << "\n\tin_img2.nr(): " << in_img2.nr() |
| 582 | ); |
| 583 | |
| 584 | |
| 585 | |
| 586 | // if there isn't any input image then don't do anything |
| 587 | if (in_img1.size() == 0) |
| 588 | { |
| 589 | out_img.clear(); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | out_img.set_size(in_img1.nr(),in_img1.nc()); |
| 594 | |
| 595 | for (long r = 0; r < in_img1.nr(); ++r) |
| 596 | { |
| 597 | for (long c = 0; c < in_img1.nc(); ++c) |
| 598 | { |
| 599 | if (in_img1[r][c] == on_pixel && in_img2[r][c] == off_pixel) |
nothing calls this directly
no test coverage detected