<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I would start from a simple image (perhaps one of the included images used for testing) and see if the assumptions hold for a test case that appears to work. &nbsp;<div><br></div><div><br></div><div><br><div><div>On Sep 2, 2009, at 9:54 AM, David Doria wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Tue, Sep 1, 2009 at 11:50 PM, Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com">ntustison@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="word-wrap: break-word;">Hi David,<div><br></div><div>Okay, it's been quite awhile since I've looked at the code but I think I can provide you with a little bit of direction. &nbsp;If you look in the Initialize() function (the lines in question are 198-205 in my copy), you'll see that Boykov's min-cut algorithm adds 2 edges to the output graph, i.e. the "terminal edge" and the "orphan edge". Also, if I remember correctly, what you do is iterate through the nodes in the graph and inspect &nbsp;the boolean variable "IsSink" which will be either true (sink node) or false (source node). &nbsp;Also, the class variable m_MaxFlow should hold the weight of the min cut. &nbsp;Simply call GetMaxFlow().</div>
<div><br></div><div>Nick &nbsp;&nbsp;</div><div></div></div></blockquote><div><br>Nick,<br><br>Thanks for the help so far - however, it doesn't seem to be working as expected.<br><br>IsSink is returning false for both nodes.<br>
GetMaxFlow() is returning 0.<br><br>I added this:<br>&nbsp; this-&gt;m_MaxFlow += bottleneck;<br>std::cout &lt;&lt; "added " &lt;&lt; bottleneck &lt;&lt; " to maxflow." &lt;&lt; std::endl;<br><br>to line 394 of itkBoykovMinCutGraphFilter.txx and nothing is ever output.. so it follows that GetMaxFlow() would return 0 - but why would it never be incremented? Is this too degenerate of a graph for the algorithm to work properly? I wasn't sure if multiple edges were allowed between nodes - so I now only have one edge of weight 2. I also wasn't sure about the behavior of directed graphs, so I removed the call to SetAllReverseEdges. &nbsp; Here is the code:<br>
#include &lt;iostream&gt;<br><br>#include "itkGraph.h"<br>#include "itkBoykovGraphTraits.h"<br>#include "itkBoykovMinCutGraphFilter.h"<br><br>int main( int argc, char * argv[] )<br>{<br>&nbsp;&nbsp;&nbsp; typedef itk::BoykovGraphTraits&lt;short, 3&gt; GraphTraitsType;<br>
<br>&nbsp;&nbsp;&nbsp; typedef itk::Graph&lt;GraphTraitsType&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GraphType;<br>&nbsp;&nbsp;&nbsp; GraphType::Pointer graph = GraphType::New();<br><br>&nbsp;&nbsp;&nbsp; typedef GraphType::NodePointerType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NodePointerType;<br>&nbsp;&nbsp;&nbsp; typedef GraphType::EdgePointerType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EdgePointerType;<br>
&nbsp;<br>&nbsp; &nbsp;&nbsp;&nbsp; // Create graph nodes<br>&nbsp;&nbsp;&nbsp; NodePointerType Nodes[2];<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; for( unsigned int i = 0; i &lt; 2; i++ )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; graph-&gt;CreateNewNode( 2 );<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //get pointers to the newly created nodes<br>
&nbsp;&nbsp;&nbsp; for( unsigned int i = 0; i &lt; 2; i++ )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Nodes[i] = graph-&gt;GetNodePointer( i );<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp; //create three edges between nodes 0 and 1, each with weight 2<br>&nbsp;&nbsp;&nbsp; graph-&gt;CreateNewEdge( Nodes[0], Nodes[1], 2 );<br>
&nbsp;&nbsp;&nbsp; //graph-&gt;CreateNewEdge( Nodes[0], Nodes[1], 2 );<br>&nbsp;&nbsp;&nbsp; //graph-&gt;CreateNewEdge( Nodes[0], Nodes[1], 2 );<br><br>&nbsp;&nbsp;&nbsp; // Set the reverse edges<br>&nbsp;&nbsp;&nbsp; //graph-&gt;SetAllReverseEdges();<br><br>&nbsp;&nbsp;&nbsp; //perform the cut<br>
&nbsp;&nbsp;&nbsp; typedef itk::BoykovMinCutGraphFilter&nbsp; &lt;GraphType&gt; FilterType;<br>&nbsp;&nbsp;&nbsp; FilterType::Pointer filter = FilterType::New();<br>&nbsp;&nbsp;&nbsp; filter-&gt;SetInput(graph);<br>&nbsp;&nbsp;&nbsp; filter-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp; //see which nodes are sinks<br>
&nbsp;&nbsp;&nbsp; typedef GraphType::NodeIterator&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NodeIteratorType;<br>&nbsp;&nbsp;&nbsp; typedef GraphType::NodeIdentifierType&nbsp;&nbsp; NodeIdentifierType;<br>&nbsp;&nbsp;&nbsp; NodeIteratorType nit( graph );<br>&nbsp;&nbsp;&nbsp; for( nit.GoToBegin(); !nit.IsAtEnd(); ++nit )<br>
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NodePointerType node = nit.GetPointer();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NodeIdentifierType Id = graph-&gt;GetNodeIdentifier( node );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; node = graph-&gt;GetNodePointer( Id );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bool IsSink = node-&gt;IsSink;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(IsSink)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Node Id: " &lt;&lt; Id &lt;&lt; " is in group 1." &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Node Id: " &lt;&lt; Id &lt;&lt; " is in group 0." &lt;&lt; std::endl;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //get the cut weight (min cut = max flow)<br>&nbsp;&nbsp;&nbsp; typedef GraphType::NodeWeightType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NodeWeightType;<br>&nbsp;&nbsp;&nbsp; NodeWeightType maxflow = filter-&gt;GetMaxFlow();<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Max Flow: " &lt;&lt; maxflow &lt;&lt; std::endl;<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return EXIT_SUCCESS;<br>&nbsp;&nbsp;&nbsp; <br>}<br><br>The output is:<br>Node Id: 0 is in group 0.<br>Node Id: 1 is in group 0.<br>Max Flow: 0<br><br>The expected output is: (group 1 and 0 could possibly be switched)<br>Node Id: 0 is in group 0.<br>

Node Id: 1 is in group 1.<br>
Max Flow: 2<br>
<br>Any more suggestions?<br><br clear="all">Thanks,<br><br>David<br></div></div>
</blockquote></div><br></div></body></html>