本文整理汇总了C++中boost::multi_array::origin方法的典型用法代码示例。如果您正苦于以下问题:C++ multi_array::origin方法的具体用法?C++ multi_array::origin怎么用?C++ multi_array::origin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::multi_array
的用法示例。
在下文中一共展示了multi_array::origin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: range
/** \brief get the centroid of the neighbourhood of an image pixel given by it's offset */
valarray<double> centroid::operator()(const size_t& l) const
{
const int scope = 1;
//convert the raveled index to 3D indices
size_t
i = l / image.strides()[0],
j = (l % image.strides()[0]) / image.strides()[1],
k = (l % image.strides()[0]) % image.strides()[1];
//cout<<"l="<<l<<" -> i="<<i<<" j="<<j<<" k="<<k<<" ... ";
//the data of the neighbourhood view are copied together for the coder's sanity
boost::multi_array<float,3> ngb =
image[boost::indices
[image.shape()[0]<2*scope+1 ? range() : range(i-scope, i+scope+1)]
[image.shape()[1]<2*scope+1 ? range() : range(j-scope, j+scope+1)]
[image.shape()[2]<2*scope+1 ? range() : range(k-scope, k+scope+1)]
];
//Find the extrema of the neighbourhood.
std::pair<float*, float*> minmax = boost::minmax_element(ngb.origin(), ngb.origin()+ngb.num_elements());
//If the neighbourhood contains a negative pixel, we are at the edge of a Fourier filtering artefact that should not be considered a particle
if(*minmax.first < 0)
return valarray<double>(-1.0, 3);
//marking non local maxima (including diagonals)
if(image.origin()[l] != *minmax.second)
return valarray<double>(-1.0, 3);
//calculation of the intensity centroid
valarray<double> c(0.0,3);
double total_w = 0.0;
float *px = ngb.origin();
for(int x=0; x<ngb.shape()[0];++x)
for(int y=0; y<ngb.shape()[1];++y)
for(int z=0; z<ngb.shape()[2];++z)
{
const double weight = pow((double)(x-scope), 2) + pow((double)(y-scope), 2) + pow((double)(z-scope), 2) * (double)(*px);
c[0] += (x-scope)*weight;
c[1] += (y-scope)*weight;
c[2] += (z-scope)*weight;
total_w += weight ;
px++;
}
//cout<<c[0]<<"\t"<<c[1]<<"\t"<<c[2]<<endl;
//cout<<"divide by a weight of "<<total_w<<endl;
c /= total_w/pow(2.0*scope+1, 2);
//cout<<c[0]<<"\t"<<c[1]<<"\t"<<c[2]<<endl;
//c /= (double)accumulate(ngb.origin(), ngb.origin()+ngb.num_elements(), 0.0);
//double sum = accumulate(ngb.origin(),ngb.origin()+ngb.num_elements(),0.0);
//cout<<"valarrays ... ";
/*valarray<double> c(0.0,3), pos(0.0,3), middle(0.0,3);
for(size_t d=0; d<3;++d)
middle[d] = ngb.shape()[d]/3;
float *v = ngb.origin();
for(pos[0]=0;pos[0]<ngb.shape()[0];++pos[0])
for(pos[1]=0;pos[1]<ngb.shape()[1];++pos[1])
for(pos[2]=0;pos[2]<ngb.shape()[2];++pos[2])
c += (pos-middle) * (*v++);//pow(*v++, 2.0f);
c /= image.origin()[l];//pow(image.origin()[l], 2.0f);
for(size_t d=0;d<3;++d)
c[d] = (c[d]<0?-1:1) * sqrt(abs(c[d]))/4.5;*/
c[0] += i;
c[1] += j;
c[2] += k;
return c;
};