Implemented all assignments
@@ -13,10 +13,41 @@ FloodFill::~FloodFill()
|
||||
|
||||
int FloodFill::enclosedPixels(const vector<Point>& contourVec, vector<Point> & regionPixels)
|
||||
{
|
||||
volatile int pointsx[] = { 0, 1, 0, -1 };
|
||||
volatile int pointsy[] = { -1, 0, 1, 0 };
|
||||
|
||||
stack<Point> st;
|
||||
|
||||
Point p = findStartPoint(contourVec);
|
||||
regionPixels.push_back(p);
|
||||
st.push(p);
|
||||
|
||||
floodfill(contourVec, regionPixels, p);
|
||||
while (st.size() > 0)
|
||||
{
|
||||
Point p = st.top();
|
||||
st.pop();
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Point check = Point(p.x + pointsx[i], p.y + pointsy[i]);
|
||||
|
||||
if (contains(contourVec, check))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (contains(regionPixels, check))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
regionPixels.push_back(check);
|
||||
st.push(check);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//floodfill(contourVec, regionPixels, p);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -24,13 +55,18 @@ int FloodFill::enclosedPixels(const vector<Point>& contourVec, vector<Point> & r
|
||||
int FloodFill::floodfill(const vector<Point> & contourVec, vector<Point> & regionPixels, Point &p)
|
||||
{
|
||||
//Check four-connected
|
||||
int pointsx[] = {0, 1, 0, -1};
|
||||
int pointsy[] = {-1, 0, 1, 0};
|
||||
volatile int pointsx[] = {0, 1, 0, -1};
|
||||
volatile int pointsy[] = {-1, 0, 1, 0};
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Point check = Point(p.x + pointsx[i], p.y + pointsy[i]);
|
||||
|
||||
if (check.y < -200)
|
||||
{
|
||||
cin.get();
|
||||
}
|
||||
|
||||
if (contains(contourVec, check))
|
||||
{
|
||||
continue;
|
||||
@@ -72,19 +108,23 @@ Point FloodFill::findStartPoint(vector<Point> vec)
|
||||
|
||||
int x1 = 0, x2 = 0;
|
||||
|
||||
//Find left point
|
||||
for (int x = minx; x <= maxx; x++)
|
||||
{
|
||||
if (contains(vec, Point(x, centery)))
|
||||
{
|
||||
if (x1 == 0)
|
||||
{
|
||||
x1 = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
x2 = x;
|
||||
break;
|
||||
}
|
||||
x1 = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Find right point
|
||||
for (int x = maxx; x >= minx; x--)
|
||||
{
|
||||
if (contains(vec, Point(x, centery)))
|
||||
{
|
||||
x2 = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,15 +154,14 @@ int FloodFill::split(const vector<vector<Point>> & contours, const Mat &image, s
|
||||
std::string name = base_filename.substr(0, p);
|
||||
|
||||
vector<vector<Point>> regions;
|
||||
regions.resize(contours.size());
|
||||
|
||||
for (int i = 0; i < contours.size(); i++)
|
||||
int i = 0;
|
||||
for (vector<Point> contour : contours)
|
||||
{
|
||||
vector<Point> temp;
|
||||
enclosedPixels(contours[i], temp);
|
||||
regions[i] = temp;
|
||||
enclosedPixels(contour, temp);
|
||||
regions.push_back(temp);
|
||||
}
|
||||
|
||||
|
||||
vector<vector<Point>> bounds;
|
||||
BoundingBox::allBoundingBoxes(contours, bounds);
|
||||
@@ -140,34 +179,33 @@ int FloodFill::split(const vector<vector<Point>> & contours, const Mat &image, s
|
||||
largest.width = width;
|
||||
}
|
||||
|
||||
int nr = 0;
|
||||
|
||||
//Create every image
|
||||
for (int i = 0; i < contours.size(); i++)
|
||||
{
|
||||
|
||||
// Creeer een witte image
|
||||
IplImage* iplimage = cvCreateImage(cvSize(image.cols, image.rows), IPL_DEPTH_8U, 3);
|
||||
IplImage* iplimage = cvCreateImage(cvSize(largest.width, largest.height), IPL_DEPTH_8U, 3);
|
||||
Mat resultImage = cvarrToMat(iplimage);
|
||||
resultImage = Scalar(255, 255, 255);
|
||||
|
||||
Point center = Point((bounds[i][0].x + bounds[i][2].x) / 2, (bounds[i][0].y + bounds[i][2].y) / 2);
|
||||
int topx = center.x - (largest.width / 2);
|
||||
int topy = center.y - (largest.height / 2);
|
||||
|
||||
//Kopieren van pixels
|
||||
for (Point p : regions[i])
|
||||
{
|
||||
resultImage.at<uchar>(p) = image.at<uchar>(p);
|
||||
resultImage.at<Vec3b>(Point(p.x - topx, p.y - topy)) = image.at<Vec3b>(p);
|
||||
}
|
||||
for (Point p : contours[i])
|
||||
{
|
||||
resultImage.at<uchar>(p) = image.at<uchar>(p);
|
||||
resultImage.at<Vec3b>(Point(p.x - topx, p.y - topy)) = image.at<Vec3b>(p);
|
||||
}
|
||||
|
||||
Point center = Point((bounds[i][0].x + bounds[i][2].x) / 2, (bounds[i][0].y + bounds[i][2].y) / 2);
|
||||
imshow("Test", resultImage);
|
||||
waitKey(0);
|
||||
|
||||
Rect r = Rect(center.x - (largest.width / 2), center.y - (largest.height / 2), largest.width, largest.height);
|
||||
Mat roi(resultImage, r);
|
||||
|
||||
imwrite("output/" + name + "_" + to_string(nr) + ".bmp", roi);
|
||||
|
||||
nr++;
|
||||
imwrite("output/" + name + "_" + to_string(i) + ".bmp", resultImage);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <opencv/cv.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stack>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
@@ -94,16 +94,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
cout << "Bounding boxes bepalen..." << endl;
|
||||
vector<vector<Point>> bounds;
|
||||
int aantalB = BoundingBox::allBoundingBoxes(contours, bounds);
|
||||
|
||||
cout << "Aantal gevonden boundaries = " << aantalB << endl;
|
||||
*/
|
||||
|
||||
//Split images
|
||||
FloodFill::split(contours, image, argv[1]);
|
||||
|
||||
|
||||
/*
|
||||
cout << "Fill" << endl;
|
||||
@@ -120,9 +117,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
// teken de contouren op de witte image
|
||||
drawContours(contourImage, contours, -1, CV_RGB(255, 0, 0));
|
||||
/*
|
||||
drawContours(contourImage, bounds, -1, CV_RGB(0, 0, 255));
|
||||
|
||||
/*
|
||||
for (Point p : region)
|
||||
{
|
||||
circle(contourImage, p, 1, CV_RGB(0, 255, 0));
|
||||
@@ -132,6 +129,9 @@ int main(int argc, char *argv[])
|
||||
imshow("Found contours", contourImage);
|
||||
waitKey(0);
|
||||
|
||||
//Split images
|
||||
FloodFill::split(contours, image, argv[1]);
|
||||
|
||||
//haal bending energy waarde op
|
||||
|
||||
cout << "Bending Energy" << endl << "-----------" << endl;
|
||||
|
||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 822 B |
|
After Width: | Height: | Size: 822 B |
|
After Width: | Height: | Size: 822 B |
|
After Width: | Height: | Size: 822 B |
|
After Width: | Height: | Size: 822 B |
|
After Width: | Height: | Size: 822 B |