本文整理汇总了C++中ImageType::end方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageType::end方法的具体用法?C++ ImageType::end怎么用?C++ ImageType::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageType
的用法示例。
在下文中一共展示了ImageType::end方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: otsu_threshold
float otsu_threshold(const ImageType& src)
{
std::pair<typename ImageType::value_type,typename ImageType::value_type>
min_max = min_max_value(src.begin(),src.end());
std::vector<unsigned int> hist;
histogram(src,hist,min_max.first,min_max.second);
if(hist.empty())
return min_max.first;
std::vector<unsigned int> w(hist.size());
std::vector<float> sum(hist.size());
w[0] = hist[0];
sum[0] = 0.0;
for (unsigned int index = 1,last_w = hist[0],last_sum = 0.0; index < hist.size(); ++index)
{
w[index] = last_w + hist[index];
sum[index] = last_sum + hist[index]*index;
last_w = w[index];
last_sum = sum[index];
}
float total_sum = sum.back();
float total_w = w.back();
float max_sig_b = 0.0;
unsigned int optimal_threshold = 0;
for (unsigned int index = 0; index < hist.size()-1; ++index)
{
if (!w[index])
continue;
unsigned int w2 = (total_w-w[index]);
if (!w2)
continue;
float d = sum[index]*(float)total_w;
d -= total_sum*(float)w[index];
d *= d;
d /= w[index];
d /= w2;
if (d > max_sig_b)
{
max_sig_b = d;
optimal_threshold = index;
}
}
float optimal_threshold_value = optimal_threshold;
optimal_threshold_value /= hist.size();
optimal_threshold_value *= min_max.second - min_max.first;
optimal_threshold_value += min_max.first;
return optimal_threshold_value;
}
示例2: otsu_count
unsigned int otsu_count(const ImageType& src,float level = 0.6f)
{
float threshold = otsu_threshold(src)*level;
return std::count_if(src.begin(),src.end(),[threshold](float v){return v > threshold;});
}