13 # include <vcl_msvc_warnings.h> 20 #include <vil/vil_config.h> 22 #ifdef VXL_HAS_SSE2_HARDWARE_SUPPORT 38 max_value = min_value;
40 unsigned ni = view.
ni();
41 unsigned nj = view.
nj();
44 for (
unsigned p=0;p<np;++p)
45 for (
unsigned j=0;j<nj;++j)
46 for (
unsigned i=0;i<ni;++i)
48 const T pixel = view(i,j,p);
51 else if (pixel>max_value)
91 const std::vector<double>& fraction,
92 std::vector<T>& value)
101 const std::size_t nfrac = fraction.size();
102 for (std::size_t f=0; f<nfrac; ++f)
104 if (fraction[f]<0.0 || fraction[f]>1.0)
109 unsigned ni = im.
ni();
110 unsigned nj = im.
nj();
112 std::ptrdiff_t istep = im.
istep();
113 std::ptrdiff_t jstep = im.
jstep();
115 std::vector<T> data(ni*nj*np);
117 typename std::vector<T>::iterator it = data.begin();
119 for (
unsigned int p=0; p<np; ++p, plane+=pstep)
121 const T* row = plane;
122 for (
unsigned int j=0; j<nj; ++j, row+=jstep)
124 const T* pixel = row;
125 for (
unsigned int i=0; i<ni; ++i, pixel+=istep)
132 const std::size_t npix = data.size();
136 for (
unsigned f=0; f<nfrac; ++f)
138 unsigned index = static_cast<unsigned>(fraction[f]*npix - 0.5);
139 typename std::vector<T>::iterator index_it = data.begin() + index;
140 std::nth_element(data.begin(), index_it, data.end());
141 value[f] = *index_it;
156 const double fraction,
159 std::vector<double> fractions(1, fraction);
160 std::vector<T> values;
162 if (values.size() > 0)
169 template <
class imT,
class sumT>
174 for (
unsigned p=0;p<imA.
nplanes();++p)
175 for (
unsigned j=0;j<imA.
nj();++j)
176 for (
unsigned i=0;i<imA.
ni();++i)
178 const sumT
v = ((sumT)imA(i,j,p) - (sumT)imB(i,j,p));
186 template <
class imT,
class sumT>
192 assert(imA.ni() == imB.ni() && imB.nj() == imB.nj() && imA.nplanes() == imB.nplanes());
194 for (
unsigned p=0;p<imA.nplanes();++p)
195 for (
unsigned j=0;j<imA.nj();++j)
196 for (
unsigned i=0;i<imA.ni();++i)
198 const std::complex<imT> d = imA(i,j,p) - imB(i,j,p);
199 ssd += sumT( d.real()*d.real() + d.imag()*d.imag() );
206 template<
class aT,
class sumT>
216 for (
unsigned j=0;j<src.
nj();++j)
217 for (
unsigned i=0;i<src.
ni();++i)
220 for (
unsigned p=0;p<src.
nplanes();++p)
221 sum += (sumT) src(i,j,p);
222 dest(i,j) = (sumT)( sum / src.
nplanes() );
228 template<
class inT,
class outT,
class sumT>
234 for (
unsigned j=0;j<src.
nj();++j)
235 for (
unsigned i=0;i<src.
ni();++i)
238 for (
unsigned p=0;p<src.
nplanes();++p)
239 sum += static_cast<sumT>(src(i,j,p));
240 dest(i,j) = static_cast<outT>(sum / src.
nplanes());
246 template<
class imT,
class sumT>
250 std::ptrdiff_t istep = im.
istep(),jstep=im.
jstep();
251 const imT* row_end = row + im.
nj()*jstep;
252 std::ptrdiff_t row_len = im.
ni()*im.
istep();
254 for (;row!=row_end;row+=jstep)
256 const imT* v_end = row + row_len;
257 for (
const imT*
v = row;
v!=v_end;
v+=istep) sum+=(sumT)(*v);
263 template<
class imT,
class sumT>
266 if (im.
size()==0) { mean=0;
return; }
268 mean/=(sumT)(im.
ni()*im.
nj());
296 template<
class imT,
class sumT>
300 std::ptrdiff_t istep = im.
istep(),jstep=im.
jstep();
301 const imT* row_end = row + im.
nj()*jstep;
302 std::ptrdiff_t row_len = im.
ni()*im.
istep();
304 for (;row!=row_end;row+=jstep)
306 const imT* v_end = row + row_len;
307 for (
const imT*
v = row;
v!=v_end;
v+=istep) { sum+=*
v; sum_sq+=sumT(*
v)*sumT(*
v); }
313 template<
class imT,
class sumT>
318 if ( im.
ni() != mask.
ni() || im.
nj() != mask.
nj() || mask.
nplanes() != 1)
323 std::ptrdiff_t istep = im.
istep(),jstep=im.
jstep();
324 const imT* row_end = row + im.
nj()*jstep;
325 std::ptrdiff_t row_len = im.
ni()*im.
istep();
327 std::ptrdiff_t m_istep = mask.
istep(), m_jstep=mask.
jstep();
329 for (;row!=row_end;row+=jstep, m_row+=m_jstep)
331 const imT* v_end = row + row_len;
332 const bool* b = m_row;
333 for (
const imT*
v = row;
v!=v_end;
v+=istep, b+=m_istep )
339 sum_sq+=sumT(*
v)*sumT(*
v);
349 template<
class imT,
class sumT>
352 if (im.
size()==0) { mean=0; var=0;
return; }
355 mean = sum/float(im.
ni()*im.
nj());
356 var = sum_sq/float(im.
ni()*im.
nj()) - mean*mean;
361 template<
class imT,
class sumT>
365 if (im.
size()==0) { mean=0; var=0;
return true; }
367 unsigned int count = 0;
372 mean = sum/float(count);
373 var = sum_sq/float(count) - mean*mean;
379 template<
class sumT >
383 if(im ==
nullptr || im->get_view() ==
nullptr)
387 switch (im->pixel_format())
389 #define macro( F , T ) \ 391 return vil_math_mean_and_variance(mean, var, \ 392 static_cast<vil_image_view<T >&>(*(im->get_view())), \ 416 vxl_byte
operator()(vxl_byte x)
const {
return static_cast<vxl_byte>(0.5+std::sqrt(
double(x))); }
417 unsigned operator()(
unsigned x)
const {
return static_cast<unsigned int>(0.5+std::sqrt(
double(x))); }
418 int operator()(
int x)
const {
return x>0?static_cast<int>(0.5+std::sqrt(
double(x))):0; }
419 short operator()(
short x)
const {
return x>0?static_cast<short>(0.5+std::sqrt(
double(x))):0; }
420 float operator()(
float x)
const {
return x>0?std::sqrt(x):0.0f; }
421 double operator()(
double x)
const {
return x>0?std::sqrt(x):0.0; }
440 unsigned ni = image.
ni(),nj = image.
nj(),np = image.
nplanes();
443 for (
unsigned p=0;p<np;++p,plane += pstep)
446 for (
unsigned j=0;j<nj;++j,row += jstep)
449 for (
unsigned i=0;i<ni;++i,pixel+=istep)
451 if (*pixel<min_v) *pixel=min_v;
452 else if (*pixel>max_v) *pixel=max_v;
466 short operator()(
short x)
const {
double r=
s_*x;
return short(r<0?r-0.5:r+0.5); }
467 int operator()(
int x)
const {
double r=
s_*x;
return int(r<0?r-0.5:r+0.5); }
470 std::complex<double>
operator()(std::complex<double> x)
const {
return s_*x; }
488 short operator()(
short x)
const {
double r=
s_*x+
t_;
return short(r<0?r-0.5:r+0.5); }
492 std::complex<double>
operator()(std::complex<double> x)
const {
return s_*x+
t_; }
504 vxl_byte
operator()(vxl_byte x)
const {
return static_cast<vxl_byte>(0.5+std::log(
double(x))); }
505 unsigned operator()(
unsigned x)
const {
return static_cast<unsigned int>(0.5+std::log(
double(x))); }
506 int operator()(
int x)
const {
return x>0?static_cast<int>(0.5+std::log(
double(x))):0; }
507 short operator()(
short x)
const {
return x>0?static_cast<short>(0.5+std::log(
double(x))):0; }
508 float operator()(
float x)
const {
return x>0?std::log(x):0.0f; }
509 double operator()(
double x)
const {
return x>0?std::log(x):0.0; }
523 template<
class imT,
class offsetT>
526 unsigned ni = image.
ni(),nj = image.
nj(),np = image.
nplanes();
529 for (
unsigned p=0;p<np;++p,plane += pstep)
532 for (
unsigned j=0;j<nj;++j,row += jstep)
535 for (
unsigned i=0;i<ni;++i,pixel+=istep) *pixel = imT(scale*(*pixel)+offset);
549 if (var>0) s = 1.0/std::sqrt(var);
556 template<
class srcT,
class destT>
561 unsigned ni = src.
ni(),nj = src.
nj(),np = src.
nplanes();
565 std::ptrdiff_t istepB=dest.
istep(),jstepB=dest.
jstep();
568 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB)
570 const srcT* pixelA = rowA;
571 const srcT* end_pixelA = rowA+ni*istepA;
572 destT* pixelB = rowB;
576 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
577 *pixelB = std::fabs(destT(*pixelA));
581 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
583 destT sum2 = destT(*pixelA)*(*pixelA)
584 + destT(pixelA[pstepA])*(pixelA[pstepA]);
585 *pixelB = destT(std::sqrt(sum2/2));
590 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
592 *pixelB = destT(*pixelA)*destT(*pixelA);
593 const srcT* p=pixelA+pstepA;
594 const srcT* end_p=pixelA+np*pstepA;
595 for (;p!=end_p;p+=pstepA) *pixelB += destT(*p)*destT(*p);
596 *pixelB = destT(std::sqrt(*pixelB/np));
606 template<
class srcT,
class destT>
611 unsigned ni = src.
ni(),nj = src.
nj(),np = src.
nplanes();
615 std::ptrdiff_t istepB=dest.
istep(),jstepB=dest.
jstep();
618 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB)
620 const srcT* pixelA = rowA;
621 const srcT* end_pixelA = rowA+ni*istepA;
622 destT* pixelB = rowB;
626 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
627 *pixelB = std::fabs(destT(*pixelA));
631 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
633 destT sum2 = destT(*pixelA)*(*pixelA)
634 + destT(pixelA[pstepA])*(pixelA[pstepA]);
635 *pixelB = destT(std::sqrt(sum2));
640 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
642 *pixelB = destT(*pixelA)*destT(*pixelA);
643 const srcT* p=pixelA+pstepA;
644 const srcT* end_p=pixelA+np*pstepA;
645 for (;p!=end_p;p+=pstepA) *pixelB += destT(*p)*destT(*p);
646 *pixelB = destT(std::sqrt(*pixelB));
656 template<
class srcT,
class destT>
661 unsigned ni = src.
ni(),nj = src.
nj(),np = src.
nplanes();
665 std::ptrdiff_t istepB=dest.
istep(),jstepB=dest.
jstep();
668 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB)
670 const srcT* pixelA = rowA;
671 const srcT* end_pixelA = rowA+ni*istepA;
672 destT* pixelB = rowB;
675 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
676 *pixelB = destT(*pixelA)*(*pixelA);
680 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
681 *pixelB = destT(*pixelA)*(*pixelA)
682 + destT(pixelA[pstepA])*(pixelA[pstepA]);
686 for (;pixelA!=end_pixelA; pixelA+=istepA,pixelB+=istepB)
688 *pixelB = destT(*pixelA)*destT(*pixelA);
689 const srcT* p=pixelA+pstepA;
690 const srcT* end_p=pixelA+np*pstepA;
691 for (;p!=end_p;p+=pstepA) *pixelB += destT(*p)*destT(*p);
699 template<
class aT,
class bT,
class sumT>
704 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
705 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
714 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeS += pstepS)
716 const aT* rowA = planeA;
717 const bT* rowB = planeB;
719 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowS += jstepS)
721 const aT* pixelA = rowA;
722 const bT* pixelB = rowB;
724 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelS+=istepS)
725 *pixelS = sumT(*pixelA)+sumT(*pixelB);
735 template<
class aT,
class bT,
class sumT>
740 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
741 assert(imB.
ni()==ni && imB.
nj()==nj);
747 std::ptrdiff_t istepP=im_product.
istep(),jstepP=im_product.
jstep(),
751 if (imB.
nplanes()==1) pstepB=0;
756 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeP += pstepP)
758 const aT* rowA = planeA;
759 const bT* rowB = planeB;
761 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowP += jstepP)
763 const aT* pixelA = rowA;
764 const bT* pixelB = rowB;
766 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelP+=istepP)
767 *pixelP = sumT(*pixelA)*sumT(*pixelB);
774 template<
class aT,
class bT,
class maxT>
779 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
780 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
789 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeS += pstepS)
791 const aT* rowA = planeA;
792 const bT* rowB = planeB;
794 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowS += jstepS)
796 const aT* pixelA = rowA;
797 const bT* pixelB = rowB;
799 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelS+=istepS)
800 *pixelS = maxT(std::max(*pixelA, *pixelB));
807 template<
class aT,
class bT,
class minT>
812 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
813 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
822 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeS += pstepS)
824 const aT* rowA = planeA;
825 const bT* rowB = planeB;
827 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowS += jstepS)
829 const aT* pixelA = rowA;
830 const bT* pixelB = rowB;
832 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelS+=istepS)
833 *pixelS = minT(std::min(*pixelA, *pixelB));
846 template<
class aT,
class bT,
class sumT>
851 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
852 assert(imB.
ni()==ni && imB.
nj()==nj);
853 assert(imB.
ni()==ni && imB.
nj()==nj);
859 std::ptrdiff_t istepR=im_ratio.
istep(),jstepR=im_ratio.
jstep(),
863 if (imB.
nplanes()==1) pstepB=0;
868 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeR += pstepR)
870 const aT* rowA = planeA;
871 const bT* rowB = planeB;
873 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowR += jstepR)
875 const aT* pixelA = rowA;
876 const bT* pixelB = rowB;
878 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelR+=istepR)
880 if (*pixelB==0) *pixelR=0;
881 else *pixelR = sumT(*pixelA)/sumT(*pixelB);
889 template<
class aT,
class bT,
class sumT>
894 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
895 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
904 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeS += pstepS)
906 const aT* rowA = planeA;
907 const bT* rowB = planeB;
909 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowS += jstepS)
911 const aT* pixelA = rowA;
912 const bT* pixelB = rowB;
914 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelS+=istepS)
915 *pixelS = sumT(*pixelA)-sumT(*pixelB);
923 template<
class aT,
class bT,
class dT>
925 const aT* pxA, std::ptrdiff_t isA,
926 const bT* pxB, std::ptrdiff_t isB,
927 dT* pxD, std::ptrdiff_t isD,
930 for (
unsigned i =0; i < len; ++i, pxA += isA, pxB += isB, pxD += isD)
933 *pxD = (*pxA > *pxB) ? (dT)(*pxA - *pxB) : (dT)(*pxB - *pxA);
940 template<
class aT,
class bT,
class dT>
942 const aT* pxA, std::ptrdiff_t isA,
943 const bT* pxB, std::ptrdiff_t isB,
944 dT* pxD, std::ptrdiff_t isD,
947 vil_math_image_abs_difference_1d_generic<aT, bT, dT>(
948 pxA, isA, pxB, isB, pxD, isD, len);
954 template<
class aT,
class bT,
class dT>
959 unsigned ni = imA.
ni(), nj = imA.
nj(), np = imA.
nplanes();
960 assert(imB.
ni() == ni && imB.
nj() == nj && imB.
nplanes() == np);
970 for (
unsigned p = 0; p < np ;++p, planeA += psA, planeB += psB, planeD += psD)
972 const aT* rowA = planeA;
973 const bT* rowB = planeB;
976 for (
unsigned j = 0; j < nj; ++j, rowA += jsA, rowB += jsB, rowD += jsD)
978 vil_math_image_abs_difference_1d<aT,bT,dT>(
979 rowA, isA, rowB, isB, rowD, isD, ni);
987 template<
class aT,
class bT>
992 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
993 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
999 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB)
1001 const aT* rowA = planeA;
1002 const bT* rowB = planeB;
1003 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB)
1005 const aT* pixelA = rowA;
1006 const bT* pixelB = rowB;
1007 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB)
1010 sum += (*pixelA>*pixelB?(*pixelA-*pixelB):(*pixelB-*pixelA));
1019 template<
class aT,
class bT,
class magT>
1024 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
1025 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
1034 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB,planeM += pstepM)
1036 const aT* rowA = planeA;
1037 const bT* rowB = planeB;
1038 magT* rowM = planeM;
1039 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB,rowM += jstepM)
1041 const aT* pixelA = rowA;
1042 const bT* pixelB = rowB;
1043 magT* pixelM = rowM;
1044 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB,pixelM+=istepM)
1047 magT mag_sqr = static_cast<magT>((*pixelA)*(*pixelA) + (*pixelB)*(*pixelB));
1059 template<
class aT,
class bT,
class scaleT>
1063 unsigned ni = imA.
ni(),nj = imA.
nj(),np = imA.
nplanes();
1064 assert(imB.
ni()==ni && imB.
nj()==nj && imB.
nplanes()==np);
1070 for (
unsigned p=0;p<np;++p,planeA += pstepA,planeB += pstepB)
1073 const bT* rowB = planeB;
1074 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowB += jstepB)
1077 const bT* pixelB = rowB;
1078 for (
unsigned i=0;i<ni;++i,pixelA+=istepA,pixelB+=istepB)
1079 *pixelA = aT(fa*(*pixelA)+fb*(*pixelB));
1090 template<
class aT,
class sumT>
1095 unsigned ni = imA.
ni(),nj = imA.
nj();
1101 std::ptrdiff_t istepS=im_sum.
istep(),jstepS=im_sum.
jstep();
1103 sumT* pixelS = rowS;
1104 for (
unsigned i=0;i<ni1;++i,pixelS+=istepS)
1108 std::ptrdiff_t istepA=imA.
istep(),jstepA=imA.
jstep();
1112 std::ptrdiff_t prev_j = -jstepS;
1115 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowS += jstepS)
1117 const aT* pixelA = rowA;
1123 for (
unsigned i=1;i<ni1;++i,pixelA+=istepA,pixelS+=istepS)
1124 { sum+= (sumT)(*pixelA); *pixelS=sum + pixelS[prev_j];}
1139 template<
class aT,
class sumT>
1145 unsigned ni = imA.
ni(),nj = imA.
nj();
1152 std::ptrdiff_t istepS=im_sum.
istep(),jstepS=im_sum.
jstep();
1153 std::ptrdiff_t istepS2=im_sum_sq.
istep(),jstepS2=im_sum_sq.
jstep();
1157 sumT* pixelS = rowS;
1158 for (
unsigned i=0;i<ni1;++i,pixelS+=istepS)
1162 sumT* pixelS2 = rowS2;
1163 for (
unsigned i=0;i<ni1;++i,pixelS2+=istepS2)
1167 std::ptrdiff_t istepA=imA.
istep(),jstepA=imA.
jstep();
1171 std::ptrdiff_t prev_j = -jstepS;
1172 std::ptrdiff_t prev_j2 = -jstepS2;
1176 for (
unsigned j=0;j<nj;++j,rowA += jstepA,rowS += jstepS,rowS2 += jstepS2)
1178 const aT* pixelA = rowA;
1188 for (
unsigned i=1;i<ni1;++i,pixelA+=istepA,pixelS+=istepS,pixelS2+=istepS2)
1190 sum+= (sumT)(*pixelA);
1191 *pixelS=sum + pixelS[prev_j];
1192 sum2+=sumT(*pixelA)*sumT(*pixelA);
1193 *pixelS2 = sum2 + pixelS2[prev_j2];
1199 #ifdef VXL_HAS_SSE2_HARDWARE_SUPPORT 1203 #endif // vil_math_h_ unsigned operator()(unsigned x) const
Various mathematical manipulations of 2D images implemented with SSE intrinsic functions.
void vil_math_integral_image(const vil_image_view< aT > &imA, vil_image_view< sumT > &im_sum)
Compute integral image im_sum(i+1,j+1) = sum (x<=i,y<=j) imA(x,y).
std::complex< double > operator()(std::complex< double > x) const
float operator()(float x) const
void vil_math_mean(sumT &mean, const vil_image_view< imT > &im, unsigned p)
Mean of elements in plane p of image.
float operator()(float x) const
short operator()(short x) const
double operator()(double x) const
short operator()(short x) const
double operator()(double x) const
void vil_math_image_min(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< minT > &im_min)
Compute the min of two images (im_min = min(imA, imB)).
void vil_transform(vil_image_view< T > &image, F functor)
Apply a unary operation to each pixel in image.
void vil_math_image_max(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< maxT > &im_max)
Compute the max of two images (im_max = max(imA, imB)).
Concrete view of image data of type T held in memory.
void vil_math_sqrt(vil_image_view< T > &image)
Compute square-root of each pixel element (or zero if negative).
void vil_math_image_product(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< sumT > &im_product)
Compute pixel-wise product of two images (im_prod(i,j) = imA(i,j)*imB(i,j).
void vil_math_sum(sumT &sum, const vil_image_view< imT > &im, unsigned p)
Sum of elements in plane p of image.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
unsigned operator()(unsigned x) const
vxl_byte operator()(vxl_byte x) const
void vil_math_value_range_percentile(const vil_image_view< T > &im, const double fraction, T &value)
Compute the value corresponding to a percentile of the range of im.
Functor class to compute square roots (returns zero if x<0).
Various view conversion functions.
unsigned operator()(unsigned x) const
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
std::complex< double > operator()(std::complex< double > x) const
void vil_math_median_unimplemented()
void vil_math_mean_over_planes(const vil_image_view< aT > &src, vil_image_view< sumT > &dest)
Calc the mean of each pixel over all the planes.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
void vil_math_integral_sqr_image(const vil_image_view< aT > &imA, vil_image_view< sumT > &im_sum, vil_image_view< sumT > &im_sum_sq)
Compute integral image im_sum_sq(i+1,j+1) = sum (x<=i,y<=j) imA(x,y)^2.
void vil_math_image_vector_mag(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< magT > &im_mag)
Compute magnitude of two images taken as vector components, sqrt(A^2 + B^2).
Various mathematical manipulations of 2D images implemented with SSE intrinsic functions.
vxl_byte operator()(vxl_byte x) const
void vil_math_truncate_range(vil_image_view< T > &image, T min_v, T max_v)
Truncate each pixel value so it fits into range [min_v,max_v].
vxl_byte operator()(vxl_byte x) const
void deep_copy(const vil_image_view< T > &src)
Make a copy of the data in src and set this to view it.
void vil_math_image_sum(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< sumT > &im_sum)
Compute sum of two images (im_sum = imA+imB).
void vil_math_scale_and_offset_values(vil_image_view< imT > &image, double scale, offsetT offset)
Multiply values in-place in image view by scale and add offset.
float operator()(float x) const
void vil_math_image_abs_difference_1d_generic(const aT *pxA, std::ptrdiff_t isA, const bT *pxB, std::ptrdiff_t isB, dT *pxD, std::ptrdiff_t isD, unsigned len)
Compute absolute difference of two 1D images (im_sum = |imA-imB|).
void vil_math_image_abs_difference(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< dT > &imD)
Compute absolute difference of two images (im_sum = |imA-imB|).
A base class reference-counting view of some image data.
void vil_math_scale_values(vil_image_view< T > &image, double scale)
Multiply values in-place in image view by scale.
vil_image_view< typename T::value_type > vil_view_as_planes(const vil_image_view< T > &v)
Return a 3-plane view of an RGB image, or a 4-plane view of an RGBA, or a 2-plane view of a complex i...
void vil_math_image_ratio(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< sumT > &im_ratio)
Compute pixel-wise ratio of two images : im_ratio(i,j) = imA(i,j)/imB(i,j).
int operator()(int x) const
unsigned long size() const
The number of pixels.
void vil_math_image_abs_difference_1d(const aT *pxA, std::ptrdiff_t isA, const bT *pxB, std::ptrdiff_t isB, dT *pxD, std::ptrdiff_t isD, unsigned len)
Compute absolute difference of two 1D images (im_sum = |imA-imB|).
std::string is_a() const override
Return class name.
Functor class to scale by s.
sumT vil_math_ssd_complex(const vil_image_view< std::complex< imT > > &imA, const vil_image_view< std::complex< imT > > &imB, sumT)
Sum squared magnitude differences between two complex images.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
vil_image_view< T > vil_plane(const vil_image_view< T > &im, unsigned p)
Return a view of im's plane p.
Functor class to compute logarithms (returns zero if x<=0).
int operator()(int x) const
void vil_math_normalise(vil_image_view< imT > &image)
Scale and offset values so their mean is zero and their variance is one.
short operator()(short x) const
float operator()(float x) const
unsigned nplanes() const
Number of planes.
int operator()(int x) const
void vil_math_value_range_percentiles(const vil_image_view< T > &im, const std::vector< double > &fraction, std::vector< T > &value)
Compute the values corresponding to several percentiles of the range of im.
sumT vil_math_ssd(const vil_image_view< imT > &imA, const vil_image_view< imT > &imB, sumT)
Sum of squared differences between two images.
void vil_math_rms(const vil_image_view< srcT > &src, vil_image_view< destT > &dest)
Computes RMS of each pixel over the planes of src image.
vxl_byte operator()(vxl_byte x) const
void vil_math_add_image_fraction(vil_image_view< aT > &imA, scaleT fa, const vil_image_view< bT > &imB, scaleT fb)
imA = fa*imA + fb*imB (Useful for moving averages!).
Functor class to scale by s and translate (offset) by t.
Representation of a generic image source or destination.
void vil_math_median(imT &median, const vil_image_view< imT > &im, unsigned p)
Median of elements in plane p of an image.
double operator()(double x) const
vil_math_scale_functor(double s)
int operator()(int x) const
unsigned operator()(unsigned x) const
double operator()(double x) const
void vil_math_sum_sqr(const vil_image_view< srcT > &src, vil_image_view< destT > &dest)
Computes sum of squares of each pixel over the planes of src image.
void vil_math_image_difference(const vil_image_view< aT > &imA, const vil_image_view< bT > &imB, vil_image_view< sumT > &im_sum)
Compute difference of two images (im_sum = imA-imB).
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
void vil_math_value_range(const vil_image_view< T > &view, T &min_value, T &max_value)
Compute minimum and maximum values over view.
short operator()(short x) const
void vil_math_rss(const vil_image_view< srcT > &src, vil_image_view< destT > &dest)
Computes Root Sum of Squares of each pixel over the planes of src image.
This is the appropriate pixel type for 24-bit colour images.
vil_math_scale_and_translate_functor(const double s, const double t)
Constructor.
void vil_math_mean_and_variance(sumT &mean, sumT &var, const vil_image_view< imT > &im, unsigned p)
Mean and variance of elements in plane p of image.
void vil_math_sum_squares(sumT &sum, sumT &sum_sq, const vil_image_view< imT > &im, unsigned p)
Sum of squares of elements in plane p of image.