<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="h5">Dear David, <br></div></div></blockquote><div><br>

thank you for the example, there were some things that were different:  <br>this bit in the code I certainly coded differently than in the example:<br><br>  histogram-&gt;SetComponentExtent(0, 4000, 0, 0, 0, 0);<br><div id=":1av" class="ii gt">

  histogram-&gt;SetComponentOrigin(0, 0, 0);<br>  histogram-&gt;SetComponentSpacing(0.16, 0.16, 3.26); // component spacing: depends on spacing of input volume<br><br>I&#39;m still a bit confused about the componentspacing.. as described above, I assumed it to be dependent on the input volume,<br>

but it is not???<br><br>Anyway, I&#39;ve extended your example a bit with writing the corresponding intensity levels to a file, for opening in a spreadsheet program.<br>I&#39;m not sure if it&#39;s too basic to put in the Examples section, but it helped me and maybe someone else could benefit from it too.<br>

<br><br>Michael<br><br><br>#include &lt;vtkActor.h&gt;<br>#include &lt;vtkImageAccumulate.h&gt;<br>#include &lt;vtkImageData.h&gt;<br>#include &lt;vtkImageExtractComponents.h&gt;<br>#include &lt;vtkJPEGReader.h&gt;<br>#include &lt;vtkRenderer.h&gt;<br>

#include &lt;vtkRenderWindow.h&gt;<br>#include &lt;vtkRenderWindowInteractor.h&gt;<br>#include &lt;vtkSmartPointer.h&gt;<br>#include &lt;vtkStdString.h&gt;<br>#include &lt;vtkXYPlotActor.h&gt;<br>#include &lt;vtkPointData.h&gt;<br>

 <br>int main( int argc, char *argv[] )<br>{<br>  // Handle the arguments<br>  if( argc &lt; 2 )<br>    {<br>    vtkstd::cout &lt;&lt; &quot;Required arguments: filename.jpg, [optional ignore zero:] &lt;y/n&gt;&quot; &lt;&lt; vtkstd::endl;<br>

    return EXIT_FAILURE;<br>    }<br> <br>  int ignoreZero = 0;<br>  if( argc == 3 )<br>    {<br>    vtkStdString ignore = argv[2];<br>    cout &lt;&lt; ignore &lt;&lt; endl;<br>    if( ignore == &quot;y&quot; || ignore == &quot;Y&quot; )<br>

      {<br>      ignoreZero = 1;<br>      }<br>    }<br> <br>  // Read a jpeg image<br>  //<br>  vtkSmartPointer&lt;vtkJPEGReader&gt; reader = vtkSmartPointer&lt;vtkJPEGReader&gt;::New();<br>  if( !reader-&gt;CanReadFile( argv[1] ) )<br>

    {<br>    vtkstd::cout &lt;&lt; &quot;Error: cannot read &quot; &lt;&lt; argv[1] &lt;&lt; vtkstd::endl;<br>    return EXIT_FAILURE;<br>    }<br>  reader-&gt;SetFileName( argv[1] );<br>  reader-&gt;Update();<br> <br>  int numComponents = reader-&gt;GetOutput()-&gt;GetNumberOfScalarComponents();<br>

  if( numComponents &gt; 3 )<br>    {<br>    vtkstd::cout &lt;&lt; &quot;Error: cannot process an image with &quot; &lt;&lt; numComponents &lt;&lt; &quot; components!&quot; &lt;&lt; vtkstd::endl;<br>    return EXIT_FAILURE;<br>

    }<br> <br>  // Create a vtkXYPlotActor<br>  //<br>  vtkSmartPointer&lt;vtkXYPlotActor&gt; plot = vtkSmartPointer&lt;vtkXYPlotActor&gt;::New();<br>  plot-&gt;ExchangeAxesOff();<br>  plot-&gt;SetLabelFormat( &quot;%g&quot; );<br>

  plot-&gt;SetXTitle( &quot;Level&quot; );<br>  plot-&gt;SetYTitle( &quot;Frequency&quot; );<br>  plot-&gt;SetXValuesToValue();<br> <br>  double xmax = 0.;<br>  double ymax = 0.;<br> <br>  double colors[3][3] = {<br>    { 1, 0, 0 },<br>

    { 0, 1, 0 },<br>    { 0, 0, 1 } };<br> <br>    const char* labels[3] = {<br>      &quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot; };<br> <br>  // Process the image, extracting and plotting a histogram for each component<br>

  //<br>  //<br>  <br>    ofstream myfile;<br>    myfile.open (&quot;histogram.txt&quot;);<br>    myfile &lt;&lt; &quot;Pixel intensities and their counts.\n&quot;;<br><br>  for( int i = 0; i &lt; numComponents; ++i )<br>

  {<br>    vtkSmartPointer&lt;vtkImageExtractComponents&gt; extract = vtkSmartPointer&lt;vtkImageExtractComponents&gt;::New();<br>    extract-&gt;SetInputConnection( reader-&gt;GetOutputPort() );<br>    extract-&gt;SetComponents( i );<br>

    extract-&gt;Update();<br> <br>    double range[2];<br>    extract-&gt;GetOutput()-&gt;GetScalarRange( range );<br>    vtkSmartPointer&lt;vtkImageAccumulate&gt; histogram = vtkSmartPointer&lt;vtkImageAccumulate&gt;::New();<br>

    histogram-&gt;SetInputConnection( extract-&gt;GetOutputPort() );<br>    histogram-&gt;SetComponentExtent( 0,static_cast&lt;int&gt;(range[1])-static_cast&lt;int&gt;(range[0])-1,0,0,0,0 );<br>    histogram-&gt;SetComponentOrigin( range[0],0,0 );<br>

    histogram-&gt;SetComponentSpacing( 1,0,0 );<br>    histogram-&gt;SetIgnoreZero( ignoreZero );<br>    histogram-&gt;Update();<br> <br>    if( range[1] &gt; xmax ) xmax = range[1];<br>    if( histogram-&gt;GetOutput()-&gt;GetScalarRange()[1] &gt; ymax ) ymax = histogram-&gt;GetOutput()-&gt;GetScalarRange()[1];<br>

<br>    plot-&gt;AddInput( histogram-&gt;GetOutput() );<br> <br>    if( numComponents &gt; 1 )<br>      {<br>      plot-&gt;SetPlotColor(i,colors[i]);<br>      plot-&gt;SetPlotLabel(i,labels[i]);<br>      plot-&gt;LegendOn();<br>

<br>      myfile &lt;&lt; &quot;\n&quot; &lt;&lt; labels[i] &lt;&lt; &quot;\n\n&quot;;<br>      }<br><br>    unsigned int temp = (range[1]-1);<br>    unsigned int frequency[numLevels];<br><br>    std::cout&lt;&lt; &quot;range: &quot; &lt;&lt; range[0] &lt;&lt; &quot; &quot; &lt;&lt; range[1] &lt;&lt;std::endl;<br>

<br>    unsigned int j;<br><br>    for(j=0;j&lt;temp;j++){<br>       frequency[j]=0;<br>              frequency[j] = histogram-&gt;GetOutput()-&gt;GetPointData()-&gt;GetScalars()-&gt;GetTuple1(j);<br>           myfile &lt;&lt; j &lt;&lt; &quot;\t&quot; &lt;&lt; frequency[j] &lt;&lt; &quot;\n&quot;;<br>

    }<br>  }<br><br>  myfile.close();<br> <br>  plot-&gt;SetXRange( 0, xmax );<br>  plot-&gt;SetYRange( 0, ymax );<br> <br>  // Visualize the histogram(s)<br>  vtkSmartPointer&lt;vtkRenderer&gt; renderer = vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>

  renderer-&gt;AddActor(plot);<br> <br>  vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow = vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>  renderWindow-&gt;AddRenderer( renderer );<br>  renderWindow-&gt;SetSize(640, 480);<br>

 <br>  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; interactor =<br>      vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>  interactor-&gt;SetRenderWindow( renderWindow );<br> <br>  // Initialize the event loop and then start it<br>

  interactor-&gt;Initialize();<br>  interactor-&gt;Start(); <br> <br><br>  return  EXIT_SUCCESS;<br>}<br><br><br></div><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div class="h5">
<br>
</div></div>I reorganized the code a little bit, changed the input to a jpeg, and<br>
posted an example in the &quot;broken&quot; section:<br>
<a href="http://www.cmake.org/Wiki/VTK/Examples/Histogram" target="_blank">http://www.cmake.org/Wiki/VTK/Examples/Histogram</a><br>
<br>
Maybe this will double your chances of someone seeing it and figuring<br>
out what is wrong :)<br>
<br>
Thanks,<br>
<br>
David<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br>