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