@@ -372,6 +372,9 @@ void convolve_1d(
372
372
convolve_cols<PixelAccum>(dst_view, kernel, dst_view, option);
373
373
}
374
374
375
+ // / \brief Provides functionality for performing correlation between the kernel and buffer.
376
+ // / Kernel size is to be provided through constructor for all instances.
377
+ // / This correlator is specifically used in 2D correlation.
375
378
template <typename PixelAccum>
376
379
class correlator_n_2d
377
380
{
@@ -393,6 +396,9 @@ class correlator_n_2d
393
396
std::size_t _kernel_dimension{0 };
394
397
};
395
398
399
+ // / \brief Provides functionality for performing correlation between the kernel and buffer.
400
+ // / Kernel size is a template parameter and must be compulsorily specified while using.
401
+ // / This correlator is specifically used in 2D correlation.
396
402
template <std::size_t kernel_dimension, typename PixelAccum>
397
403
struct correlator_k_2d
398
404
{
@@ -408,17 +414,33 @@ struct correlator_k_2d
408
414
}
409
415
};
410
416
417
+ // / \brief Computes the cross-correlation of a 2D kernel with an image.
418
+ // / \tparam PixelAccum - Specifies tha data type which will be used for creating buffer container
419
+ // / utilized for holding source image pixels after applying appropriate boundary manipulations.
420
+ // / \tparam SrcView - Specifies the type of gil view of source image which is to be correlated
421
+ // / with the kernel.
422
+ // / \tparam Kernel - Specifies the type of 2D kernel which will be correlated with source image.
423
+ // / \tparam DstView - Specifies the type of gil view which will store the result of
424
+ // / correlation between source image and kernel.
425
+ // / \tparam Correlator - Specifies the type of correlator which should be used for performing
426
+ // / correlation.
427
+ // / \param src_view - Gil view of source image used in correlation.
428
+ // / \param kernel - 2D kernel which will be correlated with source image.
429
+ // / \param dst_view - Gil view which will store the result of correlation between "src_view"
430
+ // / and "kernel".
431
+ // / \param option - Specifies the manner in which boundary pixels of "dst_view" should be computed.
432
+ // / \param correlator - Correlator which will be used for performing correlation.
411
433
template <typename PixelAccum, typename SrcView, typename Kernel, typename DstView, typename Correlator>
412
434
void correlate_2d_impl (SrcView src_view, Kernel kernel, DstView dst_view,
413
435
boundary_option option, Correlator correlator)
414
436
{
415
- std:: size_t const upper_extrapolation_size = kernel.upper_size ();
416
- std:: size_t const lower_extrapolation_size = kernel.lower_size ();
417
- std:: size_t const left_extrapolation_size = kernel.left_size ();
418
- std:: size_t const right_extrapolation_size = kernel.right_size ();
437
+ long unsigned int const upper_extrapolation_size = kernel.upper_size ();
438
+ long unsigned int const lower_extrapolation_size = kernel.lower_size ();
439
+ long unsigned int const left_extrapolation_size = kernel.left_size ();
440
+ long unsigned int const right_extrapolation_size = kernel.right_size ();
419
441
420
442
bool explicit_fill = 1 ;
421
- std:: ptrdiff_t col = 0 , row = 0 ;
443
+ long unsigned int col = 0 , row = 0 ;
422
444
PixelAccum zero_pixel;
423
445
pixel_zeros_t <PixelAccum>()(zero_pixel);
424
446
@@ -492,11 +514,11 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
492
514
std::fill_n (buffer.begin () + buffer.size () - kernel.size () * right_extrapolation_size,
493
515
kernel.size () * right_extrapolation_size, zero_pixel);
494
516
495
- for (std:: ptrdiff_t index = kernel.size () * left_extrapolation_size;
517
+ for (long unsigned int index = kernel.size () * left_extrapolation_size;
496
518
index < buffer.size () - kernel.size () * right_extrapolation_size;
497
519
index += kernel.size ())
498
520
{
499
- for (std:: ptrdiff_t inner_index = 0 ; inner_index < upper_extrapolation_size;
521
+ for (long unsigned int inner_index = 0 ; inner_index < upper_extrapolation_size;
500
522
++inner_index)
501
523
{
502
524
buffer[index + inner_index] = zero_pixel;
@@ -515,7 +537,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
515
537
std::fill_n (intermediate_buffer.begin (), upper_extrapolation_size,
516
538
intermediate_buffer[upper_extrapolation_size]);
517
539
518
- for (std:: ptrdiff_t inner_index = 0 ; inner_index < kernel.size () * left_extrapolation_size;
540
+ for (long unsigned int inner_index = 0 ; inner_index < kernel.size () * left_extrapolation_size;
519
541
inner_index += kernel.size ())
520
542
{
521
543
std::copy (intermediate_buffer.begin (), intermediate_buffer.end (),
@@ -529,18 +551,18 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
529
551
std::fill_n (intermediate_buffer.begin (), upper_extrapolation_size,
530
552
intermediate_buffer[upper_extrapolation_size]);
531
553
532
- for (std:: ptrdiff_t inner_index = buffer.size () - kernel.size () * right_extrapolation_size;
554
+ for (long unsigned int inner_index = buffer.size () - kernel.size () * right_extrapolation_size;
533
555
inner_index < buffer.size (); inner_index += kernel.size ())
534
556
{
535
557
std::copy (intermediate_buffer.begin (), intermediate_buffer.end (),
536
558
buffer.begin () + inner_index);
537
559
}
538
560
539
- for (std:: ptrdiff_t index = kernel.size () * left_extrapolation_size;
561
+ for (long unsigned int index = kernel.size () * left_extrapolation_size;
540
562
index < buffer.size () - kernel.size () * right_extrapolation_size;
541
563
index += kernel.size ())
542
564
{
543
- for (std:: ptrdiff_t inner_index = 0 ; inner_index < upper_extrapolation_size;
565
+ for (long unsigned int inner_index = 0 ; inner_index < upper_extrapolation_size;
544
566
++inner_index)
545
567
{
546
568
// check indices throughout the algorithm.
@@ -552,7 +574,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
552
574
else if (option == boundary_option::extend_reflection)
553
575
{
554
576
explicit_fill = 0 ;
555
- std:: ptrdiff_t row_bound =
577
+ long unsigned int row_bound =
556
578
kernel.size () - upper_extrapolation_size > upper_extrapolation_size ?
557
579
kernel.size () - upper_extrapolation_size : upper_extrapolation_size;
558
580
@@ -661,7 +683,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
661
683
{
662
684
if (row)
663
685
{
664
- for (std:: ptrdiff_t temp_col = 0 ; temp_col < left_extrapolation_size; ++temp_col)
686
+ for (long unsigned int temp_col = 0 ; temp_col < left_extrapolation_size; ++temp_col)
665
687
{
666
688
std::ptrdiff_t left_bound = temp_col * kernel.size ();
667
689
std::rotate (buffer.begin () + left_bound, buffer.begin () + left_bound + 1 ,
@@ -692,7 +714,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
692
714
}
693
715
}
694
716
695
- for (std:: ptrdiff_t temp_col = 0 ; temp_col < right_extrapolation_size; ++temp_col)
717
+ for (long unsigned int temp_col = 0 ; temp_col < right_extrapolation_size; ++temp_col)
696
718
{
697
719
std::ptrdiff_t left_bound = (left_extrapolation_size + src_view.width () +
698
720
temp_col) * kernel.size ();
@@ -722,7 +744,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
722
744
}
723
745
}
724
746
725
- for (std:: ptrdiff_t temp_col = 0 ; temp_col < src_view.width (); ++temp_col)
747
+ for (long int temp_col = 0 ; temp_col < src_view.width (); ++temp_col)
726
748
{
727
749
std::ptrdiff_t left_bound = (left_extrapolation_size + temp_col) * kernel.size ();
728
750
std::rotate (buffer.begin () + left_bound, buffer.begin () + left_bound + 1 ,
@@ -737,7 +759,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
737
759
738
760
for (row = src_view.height () - lower_extrapolation_size; row < src_view.height (); ++row)
739
761
{
740
- for (std:: ptrdiff_t temp_col = 0 ; temp_col < left_extrapolation_size; ++temp_col)
762
+ for (long unsigned int temp_col = 0 ; temp_col < left_extrapolation_size; ++temp_col)
741
763
{
742
764
std::ptrdiff_t left_bound = temp_col * kernel.size ();
743
765
std::rotate (buffer.begin () + left_bound, buffer.begin () + left_bound + 1 ,
@@ -765,7 +787,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
765
787
}
766
788
}
767
789
768
- for (std:: ptrdiff_t temp_col = 0 ; temp_col < right_extrapolation_size; ++temp_col)
790
+ for (long unsigned int temp_col = 0 ; temp_col < right_extrapolation_size; ++temp_col)
769
791
{
770
792
std::ptrdiff_t left_bound = (left_extrapolation_size + src_view.width () + temp_col) *
771
793
kernel.size ();
@@ -796,7 +818,7 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
796
818
}
797
819
}
798
820
799
- for (std:: ptrdiff_t temp_col = 0 ; temp_col < src_view.width (); ++temp_col)
821
+ for (long int temp_col = 0 ; temp_col < src_view.width (); ++temp_col)
800
822
{
801
823
std::ptrdiff_t left_bound = (left_extrapolation_size + temp_col) * kernel.size ();
802
824
std::rotate (buffer.begin () + left_bound, buffer.begin () + left_bound + 1 ,
@@ -828,18 +850,29 @@ void correlate_2d_impl(SrcView src_view, Kernel kernel, DstView dst_view,
828
850
}
829
851
}
830
852
853
+ // / \ingroup ImageAlgorithms
854
+ // / \brief Detects whether a 2D kernel is spatial separable or not and separates it if the kernel
855
+ // / is spatially separable.
856
+ // / \tparam Kernel Specifies the type of 2D kernel which will be considered for separation.
857
+ // / \tparam Container_1d Specifies the type of 1D container which will store the separated components
858
+ // / of input kernel if it is separable.
859
+ // / \param kernel - Kernel which is to be considered for separation.
860
+ // / \param sep_ker_vertical - Container which will store separated vertical component of 2D kernel
861
+ // / if kernel is spatially separable.
862
+ // / \param sep_ker_horizontal - Container which will store separated horizontal component of 2D
863
+ // / kernel if kernel is spatially separable.
831
864
template <typename Kernel, typename Container_1d>
832
865
bool separate (Kernel const kernel, Container_1d& sep_ker_vertical, Container_1d& sep_ker_horizontal)
833
866
{
834
867
bool is_rank_1 = 1 ;
835
868
sep_ker_vertical[0 ] = 1 ;
836
- for (std::ptrdiff_t row = 1 ; row < kernel.size (); ++row)
869
+ for (std::size_t row = 1 ; row < kernel.size (); ++row)
837
870
{
838
871
float mul_factor = 0 ;
839
872
if (kernel.at (0 , 0 ))
840
873
mul_factor = kernel.at (0 , row) / kernel.at (0 , 0 );
841
874
sep_ker_vertical[row] = mul_factor;
842
- for (std::ptrdiff_t col = 0 ; col < kernel.size (); ++col)
875
+ for (std::size_t col = 0 ; col < kernel.size (); ++col)
843
876
{
844
877
auto transformed_elem = mul_factor * kernel.at (col, 0 );
845
878
if (transformed_elem != kernel.at (col, row))
@@ -853,14 +886,26 @@ bool separate(Kernel const kernel, Container_1d& sep_ker_vertical, Container_1d&
853
886
}
854
887
if (is_rank_1)
855
888
{
856
- for (std::ptrdiff_t col = 0 ; col < kernel.size (); ++col)
889
+ for (std::size_t col = 0 ; col < kernel.size (); ++col)
857
890
sep_ker_horizontal[col] = kernel.at (col, 0 );
858
891
}
859
892
return is_rank_1;
860
893
}
861
894
862
895
} // namespace detail
863
896
897
+ // / \ingroup ImageAlgorithms
898
+ // / \brief Correlate 2D variable-size kernel along an image.
899
+ // / \tparam PixelAccum Specifies tha data type which will be used while creating buffer container
900
+ // / which is utilized for holding source image pixels after applying appropriate boundary
901
+ // / manipulations.
902
+ // / \tparam SrcView Models ImageViewConcept.
903
+ // / \tparam Kernel Specifies the type of 2D kernel which will be correlated with source image.
904
+ // / \tparam DstView Models MutableImageViewConcept.
905
+ // / \param src_view - Gil view of source image.
906
+ // / \param kernel - Variable size 2D kernel which will be correlated with src_view.
907
+ // / \param dst_view - Gil view of destination image.
908
+ // / \param option - Specifies the manner in which boundary pixels of dst_view will be computed.
864
909
template <typename PixelAccum, typename SrcView, typename Kernel, typename DstView>
865
910
void correlate_2d (SrcView src_view, Kernel kernel, DstView dst_view,
866
911
boundary_option option = boundary_option::extend_zero)
@@ -898,6 +943,17 @@ void correlate_2d(SrcView src_view, Kernel kernel, DstView dst_view,
898
943
kernel.size ()));
899
944
}
900
945
946
+ // / \ingroup ImageAlgorithms
947
+ // / \brief Correlate 2D fixed-size kernel along an image.
948
+ // / \tparam PixelAccum Specifies tha data type which will be used for creating buffer container
949
+ // / utilized for holding source image pixels after applying appropriate boundary manipulations.
950
+ // / \tparam SrcView Models ImageViewConcept.
951
+ // / \tparam Kernel Specifies the type of 2D kernel which will be correlated with source image.
952
+ // / \tparam DstView Models MutableImageViewConcept.
953
+ // / \param src_view - Gil view of source image.
954
+ // / \param kernel - Fixed size 2D kernel which will be correlated with src_view.
955
+ // / \param dst_view - Gil view of destination image.
956
+ // / \param option - Specifies the manner in which boundary pixels of dst_view will be computed.
901
957
template <typename PixelAccum, typename SrcView, typename Kernel, typename DstView>
902
958
void correlate_2d_fixed (SrcView src_view, Kernel kernel, DstView dst_view,
903
959
boundary_option option = boundary_option::extend_zero)
@@ -933,6 +989,17 @@ void correlate_2d_fixed(SrcView src_view, Kernel kernel, DstView dst_view,
933
989
detail::correlate_2d_impl<PixelAccum>(src_view, kernel, dst_view, option, correlator{});
934
990
}
935
991
992
+ // / \ingroup ImageAlgorithms
993
+ // / \brief Convolves 2D variable-size kernel along an image.
994
+ // / \tparam PixelAccum Specifies tha data type which will be used for creating buffer container
995
+ // / utilized for holding source image pixels after applying appropriate boundary manipulations.
996
+ // / \tparam SrcView Models ImageViewConcept.
997
+ // / \tparam Kernel Specifies the type of 2D kernel which will be convoluted with source image.
998
+ // / \tparam DstView Models MutableImageViewConcept.
999
+ // / \param src_view - Gil view of source image.
1000
+ // / \param kernel - Variable size 2D kernel which will be convolved with src_view.
1001
+ // / \param dst_view - Gil view of destination image.
1002
+ // / \param option - Specifies the manner in which boundary pixels of dst_view will be computed.
936
1003
template <typename PixelAccum, typename SrcView, typename Kernel, typename DstView>
937
1004
void convolve_2d (SrcView src_view, Kernel kernel, DstView dst_view,
938
1005
boundary_option option = boundary_option::extend_zero)
@@ -952,6 +1019,17 @@ void convolve_2d(SrcView src_view, Kernel kernel, DstView dst_view,
952
1019
// check reverse kernel.
953
1020
}
954
1021
1022
+ // / \ingroup ImageAlgorithms
1023
+ // / \brief Convolve 2D fixed-size kernel along an image
1024
+ // / \tparam PixelAccum Specifies tha data type which will be used for creating buffer container
1025
+ // / utilized for holding source image pixels after applying appropriate boundary manipulations.
1026
+ // / \tparam SrcView Models ImageViewConcept.
1027
+ // / \tparam Kernel Specifies the type of 2D kernel which will be convolved with source image.
1028
+ // / \tparam DstView Models MutableImageViewConcept.
1029
+ // / \param src_view - Gil view of source image.
1030
+ // / \param kernel - Fixed size 2D kernel which will be convolved with src_view.
1031
+ // / \param dst_view - Gil view of destination image.
1032
+ // / \param option - Specifies the manner in which boundary pixels of dst_view will be computed.
955
1033
template <typename PixelAccum, typename SrcView, typename Kernel, typename DstView>
956
1034
void convolve_2d_fixed (SrcView src_view, Kernel kernel, DstView dst_view,
957
1035
boundary_option option = boundary_option::extend_zero)
0 commit comments