[vtkusers] pythonic non max suppression returning junk

David Gobbi david.gobbi at gmail.com
Wed Feb 25 14:27:26 EST 2015


Hi Jason,

Here are two things that might be causing problems:

1) You should cast the image to "double" before applying vtkImageGradient.

2) When casting to "unsigned char" (see caster3) you have no guarantees
that the result values are in the range [0,255].  Instead, you should be
using
vtkImageShiftScale to cast the data, with an appropriate "scale" factor to
scale the data up (or down) to the allowed range.

 - David


On Wed, Feb 25, 2015 at 12:06 PM, jmerkow <jmerkow at gmail.com> wrote:

> Hello,
>
> I am trying out vtk's non-maximum suppression in python.  I am running into
> issues.  I followed the vtk example [1], using python, however I get junk
> as
> the output. And the result changes between trials as well...
>
> Everything up to the NMS filter look fine, only this filter returns junk.
> I am using vtk 6.1.0.
>
> Here is my code:
>
> from vtk import *
> print vtkVersion().GetVTKVersion()
>
> sinsrc = vtkImageSinusoidSource()
> sinsrc.SetWholeExtent(0, 255, 0, 255, 0, 0)
> sinsrc.Update()
>
> caster = vtkImageCast()
> caster.SetInputData(sinsrc.GetOutput())
> caster.SetOutputScalarTypeToUnsignedChar()
> caster.Update()
>
> writer = vtkJPEGWriter()
> writer.SetInputData(caster.GetOutput())
> writer.SetFileName("source.jpg")
> writer.Write()
>
> gradmag = vtkImageGradientMagnitude()
> gradmag.SetInputData(caster.GetOutput())
> gradmag.Update()
>
> grad = vtkImageGradient()
> grad.SetInputData(caster2.GetOutput())
> grad.Update()
>
> nms = vtkImageNonMaximumSuppression()
> nms.SetInputData(0,gradmag.GetOutput())
> nms.SetInputData(1,grad.GetOutput())
> nms.SetDimensionality(2)
> nms.Update()
>
> caster3 = vtkImageCast()
> caster3.SetInputData(nms.GetOutput())
> caster3.SetOutputScalarTypeToUnsignedChar()
> caster3.Update()
>
> writer2 = vtkJPEGWriter()
> writer2.SetInputData(caster3.GetOutput())
> writer2.SetFileName("nms.jpg")
> writer2.Write()
>
> Links to output images:
> source: http://imgur.com/KqsweLC
> nms: http://imgur.com/SuTf00Q
>
> Am I missing something?
>
> [1]
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageNonMaximumSuppression
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150225/8402f12e/attachment.html>


More information about the vtkusers mailing list