rendered paste body#include "period_detection.h"
#define OVERLAP 0
#define XORDER 2
#define YORDER 0
PeriodDetection::PeriodDetection() {}
void PeriodDetection::saic(Mat_<Vec3d> &img, Mat_<Vec3d> &ret, int blockSize) {
img.convertTo(img, CV_8UC1);
imshow("img", img);
waitKey();
#if 1
// A. Region of Interest Selection
int p = 0;
for (int y = 0; y < img.rows; y=y+blockSize-OVERLAP) {
for (int x = 0; x < img.cols; x=x+blockSize-OVERLAP) {
p++;
cout << "Block " << p << endl;
int work_x = x; //because we don't want to affect the x and y => if goes into infinite loop
int work_y = y;
if ((y + blockSize) > img.rows) //when it reaches the end it should overlap a little more :-D
work_y = img.rows - blockSize;
if ((x + blockSize) > img.cols)
work_x = img.cols - blockSize;
Rect roi(work_x, work_y, blockSize, blockSize);
Mat bild = img(roi);
// B. Signal Derivative Computation
Sobel(bild, bild, CV_8UC1, XORDER, YORDER, 1, 1, 0, BORDER_TRANSPARENT); // ksize = 1, scale = 1, delta = 0, borderType = ?
imshow("for", img(roi));
waitKey();
// C. Radon Transformation
Mat colSum = Mat::zeros(180, bild.cols, CV_8UC3);
Mat rotDest = bild.clone();
for (double angle = 0.0; angle < 180; angle++) {
cout << "angle: " << angle << endl;
Point2f center(floor(bild.cols / 2), floor(bild.rows / 2));
double scale = 1.0;
const Mat rotation = getRotationMatrix2D(center, (angle), scale);
warpAffine(bild, rotDest, rotation, bild.size(), INTER_LINEAR, BORDER_TRANSPARENT, Scalar::all(0));
// imshow("colSum", colSum);
// waitKey();
for (int dy = 0; dy < bild.cols; dy++) {
// cout << "dy: " << dy << " && bild.cols: " << bild.cols << endl;
colSum.at<double>(angle, dy) = norm(rotDest.col(dy), NORM_L1);
cout << "colSum.at<double>(angle: " << angle << ", dy: " << dy <<"): " << colSum.at<double>(angle, dy) << endl;
}
}
imshow("rotDest", rotDest);
waitKey();
imshow("colSum", colSum);
waitKey();
}
}
#endif
//TEST//
#if 0
Mat colSum(180, img.cols, CV_8UC1);
Mat dest = img.clone();
cout << "img.cols: " << img.cols << endl;
cout << "colSum.cols: " << colSum.cols << endl;
cout << "img.rows: " << img.rows << endl;
cout << "colSum.rows: " << colSum.rows << endl;
for (double angle = 1.0; angle <= 180; angle++) {
cout << "angle: " << angle << endl;
Point2f center(floor(img.cols / 2), floor(img.rows / 2));
double scale = 1.0;
cout << "(" << center.x << "," << center.y << ")" << endl;
const Mat rotation = getRotationMatrix2D(center, (angle - 1.0), scale); //(angle - 1.0) because row range cannot be 0.0
warpAffine(img, dest, rotation, img.size(), INTER_LINEAR, BORDER_TRANSPARENT, Scalar::all(0));
for (int dy = 1; dy < img.cols - 1; dy++) {
cout << "dy: " << dy << " && img.cols: " << img.cols << endl;
colSum.at<double>(angle, dy) = norm(dest.col(dy), NORM_L1);
}
}
imshow("dest", dest);
waitKey();
imshow("colSum", colSum);
#endif
//ENDTEST//
imshow("img", img);
waitKey();
}