コード例 #1
0
TEST_F(TestCFG, BNF) {
    auto test = CFG::create(BNF());
    ASSERT_NO_THROW(test << "<S> ::= 'a'<A>'b' | ''");
    ASSERT_NO_THROW(test << "<A> ::= 'a'<A> | 'b'<A> | ''");
    EXPECT_EQ(set({"a", "b"}), test.getTerminals());
    EXPECT_EQ(set({"<S>", "<A>"}), test.getNonTerminals());

    test.clear();
    test << "<S> ::= <S>'s' | <B><C><D>";
    test << "<A> ::= <S><A>'a' | ''";
    test << "<B> ::= <C>'c'";
    test << "<C> ::= <B>'b' | <S>'s' | <A>";
    test << "<D> ::= <D>'d' | <D><B> | ''";
    ASSERT_EQ(set({"c"}), test.first("<S>"));
    ASSERT_EQ(set({"c"}), test.first("<A>"));
    ASSERT_EQ(set({"c"}), test.first("<B>"));
    ASSERT_EQ(set({"c"}), test.first("<C>"));
    ASSERT_EQ(set({"c", "d"}), test.first("<D>"));
    ASSERT_FALSE(test.nullable("<S>"));
    ASSERT_TRUE(test.nullable("<A>"));
    ASSERT_FALSE(test.nullable("<B>"));
    ASSERT_TRUE(test.nullable("<C>"));
    ASSERT_TRUE(test.nullable("<D>"));
}
コード例 #2
0
ファイル: image4_1.cpp プロジェクト: mhessels/ROVI_Project
int main()
{
  // A gray image
  cv::Mat_<float> img = cv::imread("Image4_1.png", CV_LOAD_IMAGE_GRAYSCALE);
  // Load image
  //     cv::Mat_<float> img = cv::imread(argv[1], cv::IMREAD_GRAYSCALE);
  
  // Get original size
  int wxOrig = img.cols;
  int wyOrig = img.rows;
  
  
  int m = cv::getOptimalDFTSize( 2*wyOrig );
  int n = cv::getOptimalDFTSize( 2*wxOrig );
  
  copyMakeBorder(img, img, 0, m - wyOrig, 0, n - wxOrig, cv::BORDER_CONSTANT, cv::Scalar::all(0));
  
  // Get padded image size
  const int wx = img.cols, wy = img.rows;
  const int cx = wx/2, cy = wy/2;
  
  std::cout << wxOrig << " " << wyOrig << std::endl;
  std::cout << wx << " " << wy << std::endl;
  std::cout << cx << " " << cy << std::endl;
  
  // Compute DFT of image
  cv::Mat_<float> imgs[] = {img.clone(), cv::Mat_<float>::zeros(wy, wx)};
  cv::Mat_<cv::Vec2f> img_dft;
  cv::merge(imgs, 2, img_dft);
  cv::dft(img_dft, img_dft);
  
  // Shift to center
  dftshift(img_dft);
  
  // Used for visualization only
  cv::Mat_<float> magnitude, phase;
  cv::split(img_dft, imgs);
  cv::cartToPolar(imgs[0], imgs[1], magnitude, phase);
  magnitude = magnitude + 1.0f;
  cv::log(magnitude, magnitude);
  cv::normalize(magnitude, magnitude, 0, 1, CV_MINMAX);
  cv::imwrite("img_dft.png", magnitude * 255);
  //             cv::imshow("img_dft", magnitude);
  
  // Create a Butterworth low-pass filter of order n and diameter d0 in the frequency domain
  cv::Mat lpf = BLPF(100, 2, wy, wx, cx, cy);
  cv::Mat bsf = BBSF(2, wy, wx, cx, cy);
  cv::Mat nf = BNF(2, wy, wx, cx, cy);
  // Multiply and shift back
  cv::mulSpectrums(nf, img_dft, img_dft, cv::DFT_ROWS);

  dftshift(img_dft);
  
  //Display high pass filter
  cv::Mat realImg[2];
  cv::split(nf,realImg);
  cv::Mat realNF = realImg[0];
  cv::normalize(realNF, realNF, 0.0, 1.0, CV_MINMAX);
  // 	namedWindow("", cv::WINDOW_NORMAL);
  cv::imwrite("NF.png", realNF);
  
  
  
  //----- Compute IDFT of HPF filtered image
  
  //you can do this
  //cv::idft(img_dft, img_dft); //the result is a 2 channel image
  //Mat output;
  // therefore you split it and get the real one
  //split(img_dft, imgs);
  //normalize(imgs[0], output, 0, 1, CV_MINMAX);
  
  //or you can do like this, then you dont need to split
  cv::Mat_<float> output;
  cv::dft(img_dft, output, cv::DFT_INVERSE| cv::DFT_REAL_OUTPUT);
  cv::Mat_<float> croppedOutput(output,cv::Rect(0,0,wxOrig,wyOrig));
  
  cv::normalize(output, output, 0, 1, CV_MINMAX);
  cv::normalize(img, img, 0.0, 1.0, CV_MINMAX);
  
  // 	namedWindow("", cv::WINDOW_NORMAL);
  //     cv::imshow("Input", img);
  cv::imwrite("out.png", croppedOutput * 255);
  // 	namedWindow("", cv::WINDOW_NORMAL);
  //     cv::imshow("High-pass filtered input", croppedOutput);
  cv::waitKey();
  return 0;
  return 0;
}