<div dir="ltr">Hi Jason,<div><br></div><div>Here are two things that might be causing problems:</div><div><br></div><div>1) You should cast the image to "double" before applying vtkImageGradient.</div><div><br></div><div>2) When casting to "unsigned char" (see caster3) you have no guarantees</div><div>that the result values are in the range [0,255]. Instead, you should be using</div><div>vtkImageShiftScale to cast the data, with an appropriate "scale" factor to</div><div>scale the data up (or down) to the allowed range.</div><div><br></div><div> - David</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 25, 2015 at 12:06 PM, jmerkow <span dir="ltr"><<a href="mailto:jmerkow@gmail.com" target="_blank">jmerkow@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am trying out vtk's non-maximum suppression in python. I am running into<br>
issues. I followed the vtk example [1], using python, however I get junk as<br>
the output. And the result changes between trials as well...<br>
<br>
Everything up to the NMS filter look fine, only this filter returns junk.<br>
I am using vtk 6.1.0.<br>
<br>
Here is my code:<br>
<br>
from vtk import *<br>
print vtkVersion().GetVTKVersion()<br>
<br>
sinsrc = vtkImageSinusoidSource()<br>
sinsrc.SetWholeExtent(0, 255, 0, 255, 0, 0)<br>
sinsrc.Update()<br>
<br>
caster = vtkImageCast()<br>
caster.SetInputData(sinsrc.GetOutput())<br>
caster.SetOutputScalarTypeToUnsignedChar()<br>
caster.Update()<br>
<br>
writer = vtkJPEGWriter()<br>
writer.SetInputData(caster.GetOutput())<br>
writer.SetFileName("source.jpg")<br>
writer.Write()<br>
<br>
gradmag = vtkImageGradientMagnitude()<br>
gradmag.SetInputData(caster.GetOutput())<br>
gradmag.Update()<br>
<br>
grad = vtkImageGradient()<br>
grad.SetInputData(caster2.GetOutput())<br>
grad.Update()<br>
<br>
nms = vtkImageNonMaximumSuppression()<br>
nms.SetInputData(0,gradmag.GetOutput())<br>
nms.SetInputData(1,grad.GetOutput())<br>
nms.SetDimensionality(2)<br>
nms.Update()<br>
<br>
caster3 = vtkImageCast()<br>
caster3.SetInputData(nms.GetOutput())<br>
caster3.SetOutputScalarTypeToUnsignedChar()<br>
caster3.Update()<br>
<br>
writer2 = vtkJPEGWriter()<br>
writer2.SetInputData(caster3.GetOutput())<br>
writer2.SetFileName("nms.jpg")<br>
writer2.Write()<br>
<br>
Links to output images:<br>
source: <a href="http://imgur.com/KqsweLC" target="_blank">http://imgur.com/KqsweLC</a><br>
nms: <a href="http://imgur.com/SuTf00Q" target="_blank">http://imgur.com/SuTf00Q</a><br>
<br>
Am I missing something?<br>
<br>
[1]<br>
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageNonMaximumSuppression" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageNonMaximumSuppression</a><br></blockquote></div></div></div></div>