<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>Hi Bill,</div><div><br></div>I have tried viewing them with gimp Image editor and the default Image Viewer on Ubuntu 11.10.&nbsp;<div><br></div><div>However, vtkPNG writer is able to print binary images in another part of my code .<div><br></div><div>As shown below the following code does produce a binary mask that I can view using my default&nbsp;viewers. &nbsp;So I don't think the viewers are the problem.&nbsp;</div><div><br></div><div>In the code below, whiteImage is a just a vtkImage data with all scalar values set to 255.<br><div><br></div><div>
<pre style="margin-top: 0px; margin-bottom: 0px; "><!--StartFragment--><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">// cut corresponding white image</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkSmartPointer</span>&lt;<span style=" color:#800080;">vtkImageStencil</span>&gt;<span style=" color:#c0c0c0;"> </span>stencil<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">vtkSmartPointer</span>&lt;<span style=" color:#800080;">vtkImageStencil</span>&gt;::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>stencil-&gt;SetInput(whiteImage);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>stencil-&gt;<span style="font-style: italic; ">SetStencil</span>(pol2stenc-&gt;GetOutput());</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>stencil-&gt;<span style="font-style: italic; ">ReverseStencilOff</span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>stencil-&gt;SetBackgroundValue(<span style=" color:#000080;">0</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>stencil-&gt;<span style="font-style: italic; ">Update</span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#000080;">//!</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">For</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">debugging</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">purposes</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">to</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">check</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">output</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">of</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">create</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">a</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">mask</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">algorithm</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkSmartPointer</span>&lt;<span style=" color:#800080;">vtkImageCast</span>&gt;<span style=" color:#c0c0c0;"> </span>castFilter<span style=" color:#c0c0c0;"> </span>=</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">        </span><span style=" color:#800080;">vtkSmartPointer</span>&lt;<span style=" color:#800080;">vtkImageCast</span>&gt;::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">      </span>castFilter-&gt;SetOutputScalarTypeToUnsignedChar<span style=" color:#c0c0c0;"> </span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">      </span>castFilter-&gt;<span style="font-style: italic; ">SetInputConnection</span>(stencil-&gt;GetOutputPort());</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">      </span>castFilter-&gt;<span style="font-style: italic; ">Update</span>();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QString</span><span style=" color:#c0c0c0;"> </span>filename;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span>filename<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"StencilMask_"</span><span style=" color:#c0c0c0;"> </span>+<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QString</span>(<span style=" color:#008000;">"%1"</span>).arg(contourDataObject-&gt;getId());</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#008000;">//filename = filename.arg(m_sliceIndex + 1);</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">vtkSmartPointer</span>&lt;<span style=" color:#800080;">vtkPNGWriter</span>&gt;<span style=" color:#c0c0c0;"> </span>writer<span style=" color:#c0c0c0;"> </span>=</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">        </span><span style=" color:#800080;">vtkSmartPointer</span>&lt;<span style=" color:#800080;">vtkPNGWriter</span>&gt;::New();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">      </span>writer-&gt;<span style="font-style: italic; ">SetFileName</span>(filename.toStdString().c_str());</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">      </span>writer-&gt;<span style="font-style: italic; ">SetInputConnection</span>(castFilter-&gt;GetOutputPort());</pre>
<pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#c0c0c0;">      </span>writer-&gt;<span style="font-style: italic; ">Write</span>();<!--EndFragment--></pre><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">Date: Wed, 27 Mar 2013 13:20:43 -0700<br>Subject: Re: [vtkusers] VTKPNGWriter printing out black images?<br>From: bill.lorensen@gmail.com<br>To: rafayk_@hotmail.com<br>CC: vtkusers@vtk.org<br><br>How are you viewing the png image? Many png viewers cannot view 16 bit images.<div><br><br><div class="ecxgmail_quote">On Wed, Mar 27, 2013 at 1:02 PM, Rafay Khan <span dir="ltr">&lt;<a href="mailto:rafayk_@hotmail.com" target="_blank">rafayk_@hotmail.com</a>&gt;</span> wrote:<br>
<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">


<div><div dir="ltr"><p style="border:0px;font-size:14px;vertical-align:baseline;clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;">
I am doing some image processing using ITK and then using VTK to print the results in a .png format however, the output image is always black.</p><p style="border:0px;font-size:14px;vertical-align:baseline;clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;">
Currently, I am converting itk::Image to vtk::vtkImageData using the itk::ImagetoVTKImageFilter(typedeffed to ITKtoVTKFilterType in my code).</p><pre style="padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px;"><code style="padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;"><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">ITKtoVTKFilterType</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">Pointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> itk2vtkGray </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">ITKtoVTKFilterType</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">New</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
itk2vtkGray</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetInput</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">grayBinary</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">);</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">  </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray;">//grayBinary is of type itk::Image&lt;unsigned short, 2&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
itk2vtkGray</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">Update</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">

vtkSmartPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">&lt;vtkImageData&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> grayVTK </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> vtkSmartPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">&lt;vtkImageData&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">New</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetExtent</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">extent</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">);</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetSpacing</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">m_spacing</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">);</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetScalarTypeToUnsignedShort</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetNumberOfScalarComponents</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">1</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">);</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">AllocateScalars</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">DeepCopy</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">static_cast</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">vtkImageData</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">*&gt;(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">itk2vtkGray</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">GetOutput</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">()));</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray;">//grayVTK = itk2vtkGray-&gt;GetOutput();</span></code></pre><p style="border:0px;font-size:14px;vertical-align:baseline;clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;">
I have even confirmed that my VTK ImageData contains values of either 255 or 0 using the following code.</p><pre style="padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px;"><code style="padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;"><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">int</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">*</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">dims </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">GetDimensions</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">

std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">cout </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">"Dims: "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">" x: "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> dims</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">]</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">" y: "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> dims</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">1</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">]</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">" z: "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> dims</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">2</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">]</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">endl</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">cout </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">"Number of points: "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">GetNumberOfPoints</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">()</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">endl</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">cout </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">"Number of cells: "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">GetNumberOfCells</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">()</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">endl</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">

</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">for</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">int</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> y </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> y </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> dims</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">1</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">];</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> y</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">++)</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">{</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">        
     </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">for</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">int</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> x </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> x </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> dims</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">];</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> x</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">++)</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
     </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">{</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
         </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">unsigned</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">short</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">*</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">pixel </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">static_cast</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">unsigned</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139);">short</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">*&gt;(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">GetScalarPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">x</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">,</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">y</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">,</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">));</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
         std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">cout </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">"PIXEL LOC/VAL "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> y</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">*</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">dims</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">]</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">+</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> x </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">" "</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> pixel</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">[</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">0</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">]</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">endl</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
     </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">}</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
     std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">cout </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">&lt;&lt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> std</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">endl</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
 </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">}</span></code></pre><p style="border:0px;font-size:14px;vertical-align:baseline;clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;">
I then go on to do an ImageCast to ensure the type of the data is unsignedShort.</p><pre style="padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px;"><code style="padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;"><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">vtkSmartPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">&lt;vtkImageCast&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> cast2 </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> vtkSmartPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">&lt;vtkImageCast&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">New</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
cast2</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetInput</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">grayVTK</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">);</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
cast2</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetOutputScalarTypeToUnsignedShort</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
cast2</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">ClampOverflowOn</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
cast2</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">Update</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span></code></pre>
<p style="border:0px;font-size:14px;vertical-align:baseline;clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;">Then finally I use vtkPNGwriter to output the .png files. Notice that I have tried to output both the actual vtkImageData as well as output from the ImageCastFilter.</p>
<pre style="padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px;"><code style="padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;"><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">vtkSmartPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">&lt;vtkPNGWriter&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;"> writer </span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">=</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
vtkSmartPointer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0);">&lt;vtkPNGWriter&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">::</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">New</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
writer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetFileName</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">filename</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">.</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">toStdString</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">().</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">c_str</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">());</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
writer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">SetInputConnection</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">(</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">cast2</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">GetOutputPort</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">());</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray;">//writer-&gt;SetInput(grayVTK); I have tried to method as well but to no success</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">
writer</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">-&gt;</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(43,145,175);">Write</span><span style="padding:0px;border:0px;vertical-align:baseline;background-color:transparent;">();</span></code></pre>
<p style="border:0px;font-size:14px;vertical-align:baseline;clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;">However, the .png output is always black. Does anyone know what I am doing wrong.</p>
                                               </div></div>
<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>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Unpaid intern in BillsBasement at noware dot com<br>
</div></div></div></div></div>                                               </div></body>
</html>