1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "pheap.h"
float& max(float &a,float &b);
float& min(float &a,float &b);
int findSource(int p, float* geodesic,int xsize,vector<int> &minimalPath);
int signedDistanceTransform2D(float *in,float *out,float *euc_out,int xsize,int ysize,float *phi,int &heapSize,long *boundaryPoints, int &source, vector<int> &minimalPath);
float euclideanDistanceCheck2D(float *in,float *out,float *euc_out,int xsize,int ysize,float* Intensity,int &heapSize,long *BoundaryPoints,int previous);
using namespace std;
int main()
{ //int XSize = 457,YSize = 1027;
//int XSize=782, YSize=737;
//int XSize=281, YSize=219;
int XSize=256, YSize=256;
long gridSize=XSize*YSize;
float *input=new float[gridSize];
float *output=new float[gridSize];
float *euc_output=new float[gridSize];
long *boundaryPoints=new long[gridSize/10];
int heapSize=0;
float *Intensity=new float[gridSize];
//Number of Source Points
const int SPCOUNT=gridSize/1000;
bool stopDetection = false;
int keyPointIterations = 1;
int keyPointSource = 0;
const float lambda = 30.000f;
const float errorTolerance = 0.1f * lambda;
// Vector for Fast March Source Points
map<int,int> sourcePoints;
// Vector for the Curve Location
vector<int> detectedCurve;
//Vector for the last minimal path
vector<int> minimalPath;
//reserve space for source points
// sourcePoints.reserve(SPCOUNT);
//reserve space for a detected Curve
detectedCurve.reserve(gridSize/10);
// Initial Source Point
//const int initialpoint= 21370;
//const int initialpoint= 111240;
const int initialPoint= 26479;
//Initializing Source Points
//sourcePoints.push_back(initialpoint);
for(int i=0;i<(XSize*YSize);i++){
input[i]=1000000.0f;
}
//setting distance at initial crack point to zero 26479
input[initialPoint]=0.0f;
// Reading the Potential function values on the Image ( in this case Intensity values)
FILE *file;
file = fopen("OpenCurvenb.txt", "r");
if(file==NULL) {
printf("Error: can't open file.\n");
return 1;
}
else {
printf("File opened successfully.\n");
int i = 0 ;
while(!feof(file)) {
//loop through and store the numbers into the array
fscanf(file, "%f", &Intensity[i]);
i++;
}
printf("Number of numbers read: %d\n\n", i);
printf("The numbers are:\n");
fclose(file);
}
int firstKeyPoint= signedDistanceTransform2D(input, output, euc_output, XSize, YSize, Intensity, heapSize, boundaryPoints, keyPointSource, minimalPath);
//Append minimalPath to curveDetected
detectedCurve.insert(detectedCurve.end(), minimalPath.begin(), minimalPath.end());
//Add first Key Point and its Source(initial point) and the initial point and the first key Point as the key, values pairs in the map
sourcePoints[firstKeyPoint]=initialPoint;
sourcePoints[initialPoint]=firstKeyPoint;
map<int,int>::iterator it;
while ( stopDetection == false ) {
for(int i=0;i<(XSize*YSize);i++){
input[i]=1000000.0f;
}
for(it=sourcePoints.begin() ; it < sourcePoints.end();it++){
input[*it->first]=0.0f;
}
int secondKeyPoint= signedDistanceTransform2D(input, output, euc_output, XSize, YSize, Intensity, heapSize, boundaryPoints, keyPointSource, minimalPath);
cout<<"KeyPointSource"<<keyPointSource << endl;
//sourcePoints[secondKeyPoint]= keyPointSource;
for (i=0;i<(XSize*YSize);i++){
input[i]=1000000.0f;
}
// Select the source point of the keyPointSource as the initial point
for (i=0;i<sourcePoints.size();i++){
input[sourcePoints[keyPointSource]]=0.0f;
}
// Take out the Source Point that was closest to SecondKeypoint from the sourcePoints set
//input[keyPointSource]= 1000000.0f;
float keyPointDistance = euclideanDistanceCheck2D(input,output,euc_output,XSize,YSize,Intensity,heapSize,boundaryPoints,secondKeyPoint);
cout<<"Test 3"<<endl;
if ( keyPointDistance > (2.0f*lambda - errorTolerance) && keyPointDistance < (2.0f*lambda + errorTolerance) ) {
// Add the secondKeyPoint to the sourcePoints map
sourcePoints[secondKeyPoint]= keyPointSource;
cout<<"Iterations"<<endl;
// Append minimalPath to CurveDetected
detectedCurve.insert(detectedCurve.end(), minimalPath.begin(), minimalPath.end());
// Make the secondKeyPoint the firstKeyPoint now
//firstKeyPoint = secondKeyPoint ;
keyPointIterations++;
}
else {
stopDetection = true ;
if ( keyPointIterations == 1) {
// Empty Detected Curve
detectedCurve.clear();
cout<< "No curve detected" << endl;
}
}
}
for(i=0;i<sourcePoints.size();i++){
cout<<sourcePoints[i]<<endl;
}
delete [] input;
delete [] output;
delete [] euc_output;
delete [] Intensity;
delete [] boundaryPoints;
return 0;
}
|