void mitk::CLUtil::itkProbabilityMap(const TImageType * sourceImage, double mean, double std_dev, mitk::Image::Pointer& resultImage) { itk::Image<double, 3>::Pointer itk_img = itk::Image<double, 3>::New(); itk_img->SetRegions(sourceImage->GetLargestPossibleRegion()); itk_img->SetOrigin(sourceImage->GetOrigin()); itk_img->SetSpacing(sourceImage->GetSpacing()); itk_img->SetDirection(sourceImage->GetDirection()); itk_img->Allocate(); itk::ImageRegionConstIterator<TImageType> it(sourceImage,sourceImage->GetLargestPossibleRegion()); itk::ImageRegionIterator<itk::Image<double, 3> > outit(itk_img,itk_img->GetLargestPossibleRegion()); while(!it.IsAtEnd()) { double x = it.Value(); double prob = (1.0/(std_dev*std::sqrt(2.0*M_PI))) * std::exp(-(((x-mean)*(x-mean))/(2.0*std_dev*std_dev))); outit.Set(prob); ++it; ++outit; } mitk::CastToMitkImage(itk_img, resultImage); }
int main() { std::vector<boost::uint32_t> data(256); fillMyArray(data); std::ofstream output( "this.raw", std::ios_base::out | std::ios_base::binary | std::ios_base::trunc ); boost::spirit::karma::ostream_iterator<char> outit(output); karma::generate(outit, +karma::big_word, data); karma::generate(outit, +karma::little_word, data); }
inline bool test(std::basic_string<Char> const& expected, Generator const& g) { namespace karma = boost::spirit::karma; typedef std::basic_string<Char> string_type; // we don't care about the result of the "what" function. // we only care that all generators have it: karma::what(g); string_type generated; std::back_insert_iterator<string_type> outit(generated); bool result = karma::generate(outit, g); print_if_failed("test", result, generated, expected); return result && generated == expected; }
inline bool binary_test_delimited(char const *expected, std::size_t size, Generator const& g, Attribute const &attr, Delimiter const& d) { namespace karma = boost::spirit::karma; typedef std::basic_string<char> string_type; // we don't care about the result of the "what" function. // we only care that all generators have it: karma::what(g); string_type generated; std::back_insert_iterator<string_type> outit(generated); bool result = karma::generate_delimited(outit, g, d, attr); return result && !std::memcmp(generated.c_str(), expected, size); }