aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gabor.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/gabor.cpp b/gabor.cpp
index 05efac4..a8105b9 100644
--- a/gabor.cpp
+++ b/gabor.cpp
@@ -23,11 +23,11 @@ using namespace std;
// parameters were lifted off the internet
Mat maximalGaborFilter(Mat in, int nfilts = 10,
- int ksize = 9,
- double sig = 3,
- double lm = 8,
- double gm = 0.02,
- double ps = 0) {
+ int ksize = 9, // kernel size
+ double sig = 3, // variance -- how wide the filter is
+ double lm = 8, // wavelength ?
+ double gm = 0.02, // aspect ratio (smaller = longer vessels), 1 : square, >1 : bad
+ double ps = 0) { // phase shift -- don't change?
Mat filtered[nfilts];
double dtheta = 2 * M_PI / nfilts;
@@ -236,7 +236,11 @@ void floodFill(int x, int y, Mat map, Mat visited, unsigned char target, unsigne
}
Mat removeSatRegion(Mat mask, Mat orig) {
- Rect roi = selectROI("select saturation region", orig);
+ static bool firstRun = true;
+
+ static Rect roi;
+ if(firstRun)
+ roi = selectROI("select saturation region", orig), firstRun = false;
rectangle(mask, roi, Scalar(0), FILLED);
return mask;
@@ -288,7 +292,7 @@ void dumpHist(int *hist) {
Mat redGreenOverlay(Mat rPlane, Mat gPlane) {
assert(rPlane.size() == gPlane.size());
Mat planes[3] = { Mat::zeros(rPlane.size(), CV_8U),
- gPlane,
+ gPlane * .6,
rPlane };
Mat out;
merge(planes, 3, out);
@@ -299,13 +303,15 @@ int main()
{
// filtering parameters
const int nfilts = 10;
- Mat reference;
+ Mat reference, reference_filtered;
// alignment parameters
+ //bool
+
bool homography = false;
int ecc_iters = 100;
double ecc_eps = 1e-5;
- int warp_mode = MOTION_AFFINE;
+ int warp_mode = MOTION_TRANSLATION;
while(1)
{
@@ -318,11 +324,12 @@ int main()
Mat img_c3;
img_c3 = imread(buf);
- resize(img_c3, img_c3, Size(512, 512));
+ resize(img_c3, img_c3, Size(500, 500));
// grayscale conversion
Mat img;
cvtColor(img_c3, img, COLOR_BGR2GRAY);
+ //GaussianBlur(img, img, Size(15, 15), 0, 0);
imshow("orig", img);
@@ -371,19 +378,27 @@ int main()
imshow("mask", mask);
// if you want a magenta background
- //Mat masked = Mat(mask.size(), CV_8UC3, Scalar(0xff, 0, 0xff));
- Mat masked;
+ Mat masked = Mat(mask.size(), CV_8UC3, Scalar(0xff, 0, 0xff));
+ //Mat masked;
img.copyTo(masked, mask);
imshow("extracted", masked);
+ Mat masked_filter_result = Mat(mask.size(), CV_8UC3, Scalar(0xff, 0, 0xff));
+ //Mat masked_filter_result;
+ result.copyTo(masked_filter_result, mask);
+ imshow("extracted & filtered", masked_filter_result);
+
// plot histogram
Mat histplot = plotHist(hist, ymax, t);
imshow("hist", histplot);
// try alignment
if(reference.empty())
+ {
reference = masked;
+ reference_filtered = masked_filter_result;
+ }
else
{
Mat warp_matrix;
@@ -392,14 +407,16 @@ int main()
else
warp_matrix = Mat::eye(2, 3, CV_32F);
- double coeff = findTransformECC(reference,
- masked,
+ 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);
@@ -409,6 +426,7 @@ int main()
imshow("aligned", warped_image);
+ cout << "ECC coef: " << coeff << endl;
cout << "Sizes: " << warped_image.size() << ", " << reference.size() << endl;
// create red/green overlay