//Made by Bruno Emori (RA 88736) & Christian Nakata (RA90558) //Algoritmos em Grafos - Prof Rodrigo Calvo //Universidade Estadual de Maringá - 2016 int main() { int nVertex, nEdges, graphType, v1, v2, edgeWeight, count; fscanf(stdin, "%i", &nVertex); fscanf(stdin, "%i", &nEdges); fscanf(stdin, "%i", &graphType); if ((graphType != 0) && (graphType != 1)) { printf("Graph type must be (0) - Undirected graph, or (1) - Directed graph.\n"); return 0; } adjListBlock *adjList[nVertex]; createAdjList(adjList, nVertex); while (fscanf(stdin, "%i", &v1) != EOF) { fscanf(stdin, "%i", &v2); fscanf(stdin, "%i", &edgeWeight); insertAdjList(adjList, v1, v2, edgeWeight); if (!graphType) insertAdjList(adjList, v2, v1, edgeWeight); } printf("Number of vertices: %i.\n", nVertex); printf("Number of edges: %i.\n", nEdges); if (!graphType) printf("Graph Type: Undirected Graph\n"); else printf("Graph Type: Directed Graph\n"); printf("\nEdges:\n"); for (count = 0; count < nVertex; count++) { printf("Vertex %i: ", count); printAdjList(adjList, count); printf("\n"); } printf("\n\nDeep First Search:\n"); deepFirstSearch(adjList, nVertex); printf("\n\nBreadth First Search:\n"); breadthFirstSearch(adjList, nVertex, 0); printf("\n\nComponents:\n"); connectedComponent(adjList, nVertex); if (graphType) { printf("\n\nShortest path: (Using Dijkstra's Algorithm)\n"); dijkstra(adjList, nVertex, 0); } printf("End Program.\n"); return 0; }
void SemiSupervisedKernel::processMustLink() { std::vector<std::vector<int> > componentArray; connectedComponent(&componentArray); for (size_t i = 0; i < componentArray.size(); ++i) { std::vector<int>& component = componentArray[i]; std::sort(component.begin(), component.end()); for (size_t j = 0; j < component.size(); ++j) { for (size_t k = j + 1; k < component.size(); ++k) { mMustLinkSet.insert( std::pair<int, int>(component[j], component[k])); } } } }
void EdgeDetector::canny(Mat src,vector<Mat> &dst,vector<double> lower,vector<double> higher,int aperture) { Mat fmag,fori,disp; s=Size(src.cols,src.rows); smoothing(src,src,aperture); if(src.channels()>1) colorGradient(src,fmag,fori,aperture); else { Mat dx,dy; //computing gradients along x and y direction cv::Sobel(src,dx,CV_32F,1,0,aperture,1, 0, cv::BORDER_REPLICATE); cv::Sobel(src,dy,CV_32F,0,1,aperture,1, 0, cv::BORDER_REPLICATE); //compute magnitude and orientation of gradient cv::cartToPolar(dx,dy,fmag,fori,true); } //perform non maxima suppression nonMaxima(fmag,fori); Mat hout; dst.resize(lower.size()); for(int i=0;i<lower.size();i++) { //apply lower and higher gradient thresholds cv::threshold(fmag,hout,lower[i],255,CV_THRESH_BINARY); cv::threshold(fmag,lout,higher[i],255,CV_THRESH_BINARY); connectedComponent(hout); _lable.copyTo(dst[i]); } }