[Insight-users] MinCut on an itkMesh?

David Doria daviddoria+itk at gmail.com
Tue Sep 1 15:27:27 EDT 2009


On Tue, Sep 1, 2009 at 1:56 PM, Nicholas Tustison <ntustison at gmail.com>wrote:

> Hi David,
>
> You are going to have to write a MeshToGraphFilter as I never thought to
> perform graph cuts on a mesh.  Let me know if you have any questions.
>
> Good luck,
> Nick
>
>
Hi Nick,

I've seen graph cuts on a mesh a few times point cloud segmentation - it
will be straight forward to convert a mesh into a graph, as a mesh is
already a graph! I'll post the filter on the IJ when it's working.

I have a question about the usage of your existing tools, though. The
example that shipped with the IJ paper is very involved. I tried to extract
the simplest example possible - I created 2 nodes, put 3 edges between them,
each of weight 2, and I would expect the cut to tell me that node 0 is in
one set and node 1 is in the second set, and the cut weight is 6. How would
I get those pieces of information?

Right now, when I run the cut filter, number of nodes stays at 2, but the
number of edges goes from 3 to 5!?

Here is the example:

#include <iostream>

#include "itkGraph.h"
#include "itkBoykovGraphTraits.h"
#include "itkBoykovMinCutGraphFilter.h"

int main( int argc, char * argv[] )
{
  typedef itk::BoykovGraphTraits<short, 3> GraphTraitsType;

  typedef itk::Graph<GraphTraitsType>           GraphType;
  GraphType::Pointer graph = GraphType::New();
  graph->DebugOn();

  typedef GraphType::NodeType             NodeType;
  typedef GraphType::EdgeType             EdgeType;
  typedef GraphType::NodePointerType      NodePointerType;
  typedef GraphType::EdgePointerType      EdgePointerType;


  // Create graph
  NodePointerType Nodes[2];
  //EdgePointerType Edges[3];

  for( unsigned int i = 0; i < 2; i++ )
    {
    graph->CreateNewNode( 2 );
    }

  for( unsigned int i = 0; i < 2; i++ )
    {
    Nodes[i] = graph->GetNodePointer( i );
    }

     //create three edges between nodes 0 and 1, each with weight 2
  graph->CreateNewEdge( Nodes[0], Nodes[1], 2 );
  graph->CreateNewEdge( Nodes[0], Nodes[1], 2 );
  graph->CreateNewEdge( Nodes[0], Nodes[1], 2 );

  /*
  for( unsigned int i = 0; i < 3; i++ )
    {
    Edges[i] = graph->GetEdgePointer( i );
    }
*/
  /** Set the reverse edges */
  graph->SetAllReverseEdges();

  std::cout << "Input graph" << std::endl << " --------- " << std::endl;
  std::cout << "Total number of nodes: "
    << graph->GetTotalNumberOfNodes() << std::endl;
  std::cout << "Total number of edges: "
    << graph->GetTotalNumberOfEdges() << std::endl;

  typedef itk::BoykovMinCutGraphFilter  <GraphType> FilterType;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(graph);
    filter->Update();


  std::cout << "Output graph" << std::endl << " --------- " << std::endl;
  std::cout << "Total number of nodes: "
          << graph->GetTotalNumberOfNodes() << std::endl;
  std::cout << "Total number of edges: "
          << graph->GetTotalNumberOfEdges() << std::endl;
*
//how would I see which edges are cut? (and hence be able to see the weight
of the cut?)

//how would I see which vertices are in set 0 and set 1?*


  return EXIT_SUCCESS;
}

Any help would be great.

Thanks!

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090901/4bdc21a2/attachment.htm>


More information about the Insight-users mailing list