#include #include "amma/Option.hh" #include "amma/ByteImag.hh" #include "amma/RAG/RAG.hh" #include "amma/RAG/RegNode.hh" #include "amma/RAG/RegEdge.hh" #include "amma/RAG/RmSmallMrg.hh" #include "amma/ImagIter.hh" #include "amma/EnImgBnd.hh" #include "amma/BndRegRowIter.hh" #include "amma/DP/FileFormatIO.hh" int main (int argc, char** argv) { OptionC cmd(argc,argv); char * file_in= cmd.CharArr("in", "in.pgm", "Original segmentation map\n"); //char * file_out= cmd.CharArr("out", "out.txt", "Graph\n"); cmd.Check(); ByteImageC imagein; StdIO::Load(file_in, imagein); RAGC graph; graph.ConstructGraph(imagein); RmSmallMrgC mrg_crit(1000); graph.Merge(mrg_crit); ByteImageC(graph.ConstructSegmap(imagein.Rectangle())).SaveAs("segmap0.pgm"); // for all nodes in the graph, construct boundary GraphNodeIterC n_it(graph.Base()); for(n_it.First(); n_it.IsElm(); n_it.Next()){ cout << "Processing node " << n_it.Data().getid() << "\n"; EdgeListC es; GraphAdjIterC adj(n_it.In()); for(adj.First(); adj.IsElm(); adj.Next()){ es += adj.Edge().Data().Edgels().Copy(); } BoundaryC bnd(es, TRUE); bnd.Order(bnd.First()); ImageRectangleC rect(imagein.Rectangle()); rect.Dilate(); ByteImageC bnd_img(rect);bnd_img.Fill(0); ImageBoundaryEngineC eng(bnd_img); eng.LabelOut(bnd, 255); bnd_img.SaveAs("bnd_img.pgm"); system("xv bnd_img.pgm"); } /* testing RemoveRAGBoundary and AddRAGBoundary // get ther outer boundary ImageRectangleC rect(imagein.Rectangle().Origin().UpperLeftN(), imagein.Rectangle().End().LowerRightN()); ByteImageC blob_img(rect); blob_img.Fill(0); ImageIterC img_iter(imagein); for(img_iter.First(); img_iter.IsElm(); img_iter.Next()){ if (imagein[img_iter.Pixel()]!=0) blob_img[img_iter.Pixel()] = 255; } ImageBoundaryEngineC eng(blob_img); DListC bnds = eng.TraceBWBlobs(); blob_img.SaveAs("trace_img"); DLIterC bnds_it(bnds); graph.RemoveRAGBoundary(); for(bnds_it.First(); bnds_it.IsElm(); bnds_it.Next()){ graph.AddRAGBoundary(bnds_it.Data()); ByteImageC(graph.ShowEdgels(rect)).SaveAs("edgels1.pgm"); system("xv edgels1.pgm"); } */ ByteImageC(graph.ConstructSegmap(imagein.Rectangle())).SaveAs("segmap1.pgm"); cout << "End of example\n"; return 0; }