[vtkusers] extracting a subtile from vtkimage

Erich Bremer erich.bremer at stonybrook.edu
Tue Apr 19 15:58:42 EDT 2016


I am trying to extract a subtile from a vtkimage using the following code:

def GetTile(self,image,x1,y1,x2,y2):
    i = vtk.vtkImageData().NewInstance()
    i.SetDimensions(x2-x1+1,y2-y1+1,1)
    i.AllocateScalars(vtk.VTK_UNSIGNED_CHAR,3)
    for x in range(x1,x2+1):
      for y in range(y1,y2+1):

i.SetScalarComponentFromDouble(x-x1,y-y1,0,0,image.GetScalarComponentAsDouble(x,y,0,0))
    return i


x1,y1 being the upper left corner of the subimage
x2,y2 being the lower right corner of the subimage

and it appears to work when I view the subtile using:
    data = self.GetTile(myvtkimage,0,0,256,256).GetPointData()
    data = numpy_support.vtk_to_numpy(data.GetArray(0))
    d = data[:,0]
    dd = d.reshape(256,256)
    iii = sitk.GetImageFromArray(dd)
    sitk.WriteImage(iii,"/home/erich/subtile.jpg")

But, they don't appear the same because a segmentation program that works
fine on the original image doesn't work on the subtiled image (even using
the same original dimensions)

Any thoughts?



-- 
==========================================================
Erich Bremer, M.Sc.
Director for Cyberinfrastructure
Department of Biomedical Informatics
Stony Brook Medicine
Tel. : 1-631-444-3560
Fax  : 1-631-444-8873
Cell : 1-631-681-6228
erich.bremer at stonybrook.edu
Office Location/Mailing Address
HSC, L3: Room 119
Stony Brook, NY 11794-8330
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160419/d77b11bb/attachment.html>


More information about the vtkusers mailing list