aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2020-02-12 14:52:48 -0500
committerFranklin Wei <franklin@rockbox.org>2020-02-12 14:52:48 -0500
commit09acfb1ff934499e1a40aec6da496836014fe594 (patch)
tree2bdc2936e5ebe56032494936ecf16a07afddbe36
parentf0978d7ad7af3036a479b23ae582a8aafb7587ed (diff)
downloadsloreg-09acfb1ff934499e1a40aec6da496836014fe594.zip
sloreg-09acfb1ff934499e1a40aec6da496836014fe594.tar.gz
sloreg-09acfb1ff934499e1a40aec6da496836014fe594.tar.bz2
sloreg-09acfb1ff934499e1a40aec6da496836014fe594.tar.xz
Mosaicing works
-rw-r--r--gabor.cpp110
1 files changed, 82 insertions, 28 deletions
diff --git a/gabor.cpp b/gabor.cpp
index a8105b9..3c9aa4d 100644
--- a/gabor.cpp
+++ b/gabor.cpp
@@ -122,6 +122,24 @@ int compare_pair(const void *a, const void *b) {
return 0;
}
+#define ABS(x) (((x) < 0) ? (-(x)) : (x))
+
+// sorted_peak_proms is a 512-element int array of (peak, prominence)
+// tuples. This function looks for numerically adjacent
+void dedupe_adjacent(int *sorted_peak_proms) {
+ int out[512];
+ int out_idx = 0;
+ for(int i = 0; i < 512;) {
+ out[out_idx] = sorted_peak_proms[i];
+ out[out_idx + 1] = sorted_peak_proms[i + 1];
+ out_idx += 2;
+ int j;
+ for(j = i + 2; j < 512 && sorted_peak_proms[j + 1] == sorted_peak_proms[i + 1] && ABS(sorted_peak_proms[j] - sorted_peak_proms[i]) == 1; j += 2);
+ i = j;
+ }
+ memcpy(sorted_peak_proms, out, sizeof(out));
+}
+
// get the threshold to filter out the periphial blind spots (will not
// go past maxLum, which is the threshold returned by Otsu's method,
// which is consistently an overestimate).
@@ -158,6 +176,13 @@ int getThreshold(const int *hist) {
getPeakProminences(hist, peak_proms);
qsort(peak_proms, 256, sizeof(int) * 2, compare_pair);
+ cout << "Peaks by prominence (before):" << endl;
+ for(int i = 0; i < 4; i++) {
+ cout << "x=" << peak_proms[2 * i + 0] << "(" << peak_proms[2 * i + 1] << ")" << endl;
+ }
+
+ dedupe_adjacent(peak_proms);
+
cout << "Peaks by prominence:" << endl;
for(int i = 0; i < 4; i++) {
cout << "x=" << peak_proms[2 * i + 0] << "(" << peak_proms[2 * i + 1] << ")" << endl;
@@ -168,6 +193,9 @@ int getThreshold(const int *hist) {
if(!(idx2 < idx1)) {
cout << "WARNING: peak finding failed" << endl;
+ int tmp = idx1;
+ idx1 = idx2;
+ idx2 = tmp;
}
// assert(idx2 < idx1);
@@ -305,6 +333,8 @@ int main()
const int nfilts = 10;
Mat reference, reference_filtered;
+ Mat mosaic;
+
// alignment parameters
//bool
@@ -313,13 +343,16 @@ int main()
double ecc_eps = 1e-5;
int warp_mode = MOTION_TRANSLATION;
- while(1)
+#define NFRAMES 22
+
+ //while(1)
{
// 22 frames
- for(int i = 1; i <= 22; i++)
+ for(int i = 1; i <= NFRAMES; i++)
{
- char buf[64];
+ char buf[128];
snprintf(buf, sizeof(buf), "SLO Data for registration/SLO001/SLO_subject001_frame%d.png", i);
+ cout << "Image: " << buf << endl;
Mat img_c3;
img_c3 = imread(buf);
@@ -398,6 +431,9 @@ int main()
{
reference = masked;
reference_filtered = masked_filter_result;
+
+ mosaic = Mat(reference.rows, reference.cols, CV_32F);
+ mosaic = reference / NFRAMES;
}
else
{
@@ -407,34 +443,52 @@ int main()
else
warp_matrix = Mat::eye(2, 3, CV_32F);
- double coeff = findTransformECC(/*reference,*/ reference_filtered,
- /*masked,*/ masked_filter_result,
- warp_matrix,
- warp_mode,
- TermCriteria (TermCriteria::COUNT+TermCriteria::EPS,
- ecc_iters, ecc_eps),
- mask);
-
- Mat warped_image = Mat(reference.rows, reference.cols, CV_32FC1);
-
- if (warp_mode != MOTION_HOMOGRAPHY)
- warpAffine(masked, warped_image, warp_matrix, warped_image.size(),
- INTER_LINEAR + WARP_INVERSE_MAP);
- else
- warpPerspective(masked, warped_image, warp_matrix, warped_image.size(),
- INTER_LINEAR + WARP_INVERSE_MAP);
-
- imshow("aligned", warped_image);
-
- cout << "ECC coef: " << coeff << endl;
- cout << "Sizes: " << warped_image.size() << ", " << reference.size() << endl;
-
- // create red/green overlay
- Mat overlay = redGreenOverlay(warped_image, reference);
- imshow("overlay", overlay);
+ double coeff;
+
+ try
+ {
+ coeff = findTransformECC(/*reference,*/ reference_filtered,
+ /*masked,*/ masked_filter_result,
+ warp_matrix,
+ warp_mode,
+ TermCriteria (TermCriteria::COUNT+TermCriteria::EPS,
+ ecc_iters, ecc_eps),
+ mask);
+
+ Mat warped_image = Mat(reference.rows, reference.cols, CV_32FC1);
+
+ if (warp_mode != MOTION_HOMOGRAPHY)
+ warpAffine(masked, warped_image, warp_matrix, warped_image.size(),
+ INTER_LINEAR + WARP_INVERSE_MAP);
+ else
+ warpPerspective(masked, warped_image, warp_matrix, warped_image.size(),
+ INTER_LINEAR + WARP_INVERSE_MAP);
+
+ imshow("aligned", warped_image);
+
+ cout << "ECC coef: " << coeff << endl;
+ cout << "Sizes: " << warped_image.size() << ", " << reference.size() << endl;
+
+ // create red/green overlay
+ Mat overlay = redGreenOverlay(warped_image, reference);
+ imshow("overlay", overlay);
+
+ // assemble mosaic
+ mosaic += warped_image / NFRAMES;
+ }
+ catch(cv::Exception e) {
+ cerr << "Alignment failed: " << e.what() << endl;
+ }
}
+ imshow("mosaic", mosaic);
+
waitKey(0);
}
+ reference = mosaic;
+ mosaic = Mat(reference.rows, reference.cols, CV_32F);
+
+ cout << "Registration complete." << endl;
+ waitKey(0);
}
}