void Region::Propogate(int X, int Y) { if(regionMap[Y][X]==0) { totalSize++; regionMap[Y][X]=1; //and now the horrible part for(int i=-1;i<2;i++) { for(int j=-1;j<2;j++) { if(!(Y+i<0 || X+j<0 || Y+i > maxY || X+j > maxX)) { if(abs(imageMap[Y+i][X+j]-imageMap[Y][X])<propThres && imageMap[Y+i][X+j]==0) { Propogate(X+j,Y+i); }else if(imageMap[Y+i][X+j]==0) { imageMap[Y+i][X+j]=-1; } } } } } }
double FastMarchingMethod(Image<Color> &input, Image<DistancePixel> &distance_image) { // // IMPLEMENT THIS FUNCTION // // (using the advancing front method, and a priority queue) // DistancePixel_PriorityQueue reds; //list of surronding pixels std::vector<DistancePixel*> black_pixels; //list of known distance value pixels int w = input.Width(); int h = input.Height(); double answer = 0; //initialize black pixels to 0, all other to double max value, store black pixel locations for (int i=0;i<w;i++) { for (int n=0;n<h;n++) { if (input.GetPixel(i,n).isBlack()) { DistancePixel* p = &distance_image.GetPixel(i,n); p->setX(i); p->setY(n); p->setValue(0); black_pixels.push_back(p); } else { DistancePixel* p = &distance_image.GetPixel(i,n); p->setX(i); p->setY(n); p->setValue(std::numeric_limits<double>::max()); } } } for (unsigned int i=0;i<black_pixels.size();i++) { //propogate from black pixels Propogate(distance_image,black_pixels[i],reds); } while (reds.size()!=0) { //until queue is empty if (reds.top()->getValue()>answer) { answer = reds.top()->getValue(); } black_pixels.push_back(reds.top()); //add minimum element in queue to known values reds.pop(); //remove from queue Propogate(distance_image,black_pixels[black_pixels.size()-1],reds); //propogate from new location } return answer; }
Region::Region(unsigned char ** inMag,int X, int Y,int inMaxX,int inMaxY, int Threshold) //Not so default constructor. Set Image to this thing, allocate the imagemap { startx=0; starty=0; totalSize=0; regionMap=NULL; imageMap=inMag; propThres=0; SetPropThres(Threshold); SetMaxCoords(inMaxX,inMaxY); regionMap=AllocRegionMapArea(); SetStartCoords(X,Y); Propogate(startx,starty); IsolateTrueStart(); }
void Region::GoProp() // Now assuming you *SET EVERYTHING*.... this will not SegFault the crap out of your computer. Have fun :D { regionMap= AllocRegionMapArea(); Propogate(startx,starty); IsolateTrueStart(); }