[Insight-users] Problem in 3D segmentation

Rodrigo Trujillo Rodrigo Trujillo" <rodrigo.trujillo at cenpra.gov.br
Wed, 28 Apr 2004 14:15:28 -0300


This is a multi-part message in MIME format.

------=_NextPart_000_0056_01C42D2B.41D99A40
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0057_01C42D2B.41D99A40"


------=_NextPart_001_0057_01C42D2B.41D99A40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,=20

I'm testing itkShapeDetectionLevelSetImageFilter in Python. With 2D =
images (1 slice) my program
works very well, but when i tried to expand the code for 3D images, the =
following error occurs:

"
Traceback (most recent call last):
  File "C:\Meus =
Documentos\Rodrigo\Segmentacao\ShapeDetection_3D_MRI.py", line 84, in ?
    shapeD.Update()
  File "C:/ITK/Release\itkShapeDetectionLevelSetImageFilter.py", line =
692, in Update
    def Update(*args): return =
apply(_itkShapeDetectionLevelSetImageFilter.itkShapeDetectionLevelSetImag=
eFilterF3F3_Pointer_Update,args)
RuntimeError: =
C:\Compilacao\InsightToolkit-1.6.0\Code\Common\itkDataObject.cxx:376:
Requested region is (at least partially) outside the largest possible =
region.=20
"

Does somebody know the reason of the error ? And how can i solve ?
My code is attached.


Thanks,=20

Rodrigo Trujillo
------=_NextPart_001_0057_01C42D2B.41D99A40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm testing =
itkShapeDetectionLevelSetImageFilter in=20
Python. </FONT><FONT face=3DArial size=3D2>With 2D images (1 =
slice)&nbsp;my=20
</FONT><FONT face=3DArial size=3D2>program</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>works very well, but </FONT><FONT =
face=3DArial=20
size=3D2>when&nbsp;i tried to expand the code for 3D images, the =
following error=20
</FONT><FONT face=3DArial size=3D2>occurs:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Traceback (most recent call =
last):<BR>&nbsp; File=20
"C:\Meus Documentos\Rodrigo\Segmentacao\ShapeDetection_3D_MRI.py", line =
84, in=20
?<BR>&nbsp;&nbsp;&nbsp; shapeD.Update()<BR>&nbsp; File=20
"C:/ITK/Release\itkShapeDetectionLevelSetImageFilter.py", line 692, in=20
Update<BR>&nbsp;&nbsp;&nbsp; def Update(*args): return=20
apply(_itkShapeDetectionLevelSetImageFilter.itkShapeDetectionLevelSetImag=
eFilterF3F3_Pointer_Update,args)<BR>RuntimeError:=20
C:\Compilacao\InsightToolkit-1.6.0\Code\Common\itkDataObject.cxx:376:<BR>=
Requested=20
region is (at least partially) outside the largest possible=20
region.</FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Does somebody know the reason of the =
error ? And=20
how can&nbsp;i solve ?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>My code is attached.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Rodrigo =
Trujillo</FONT></DIV></BODY></HTML>

------=_NextPart_001_0057_01C42D2B.41D99A40--

------=_NextPart_000_0056_01C42D2B.41D99A40
Content-Type: text/plain;
	name="ShapeDetection_3D_MRI.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ShapeDetection_3D_MRI.py"

import vtk
import ConnectVTKITK as itk
from vtk.tk.vtkTkRenderWidget import *

reader =3D vtk.vtkImageReader2()
reader.SetDataByteOrderToLittleEndian()
reader.SetFilePrefix('C://TEMP//InVesalius//Jair')
reader.SetDataSpacing(0.32,0.32,0.6)
reader.SetDataExtent(0,255,0,255,2,27)
reader.Update()

imageCast =3D vtk.vtkImageCast()
imageCast.SetOutputScalarTypeToFloat()
imageCast.SetInput(reader.GetOutput())
imageCast.Update()

vtkExporter =3D vtk.vtkImageExport()
vtkExporter.SetInput(imageCast.GetOutput())
itkImporter =3D itk.itkVTKImageImportF3_New()
itk.ConnectVTKToITKF3(vtkExporter, itkImporter.GetPointer())
itkImporter.Update()  # Sem este update, dah pau !!!

# Passando um filtro de SMOOTHING
filter  =3D itk.itkCurvatureAnisotropicDiffusionImageFilterF3F3_New()
filter.SetInput(itkImporter.GetOutput())

filter.SetNumberOfIterations(6)
filter.SetTimeStep(0.0625)
filter.SetConductanceParameter(3.0)
filter.Update()

# Criando o gradiente das imagem
gradiente =3D =
itk.itkGradientMagnitudeRecursiveGaussianImageFilterF3F3_New()
gradiente.SetInput(filter.GetOutput())
gradiente.SetSigma(0.7)
gradiente.Update()

# Passando sigmoid. Cria a funcao SPEED
sigmoid =3D itk.itkSigmoidImageFilterF3F3_New()
sigmoid.SetInput(gradiente.GetOutput())
sigmoid.SetOutputMinimum(0)
sigmoid.SetOutputMaximum(4095)
sigmoid.SetAlpha(-1.0) # Deve ser negativo para inverter as cores
sigmoid.SetBeta(14.0)
sigmoid.Update()

# Pipeline do FastMarching
fastMarching =3D itk.itkFastMarchingImageFilterF3F3_New()

sementes =3D itk.itkNodeContainerF3_New()     # Guardara as sementes =
(LevelSetNodes !!)
node =3D itk.itkLevelSetNodeF3()              # Pega a semente e =
transforma num LevelSetNode

idx =3D itk.itkIndex3()                       # Selecionando uma semente
idx.SetElement(0,130)
idx.SetElement(1,114)
idx.SetElement(2,20)

#node.SetValue(0.0)
node.SetValue(-5.0)
node.SetIndex(idx)

sementes.Initialize()                       # Inicializa as sementes
sementes.InsertElement(0,node)

fastMarching.SetTrialPoints(sementes.GetPointer())
fastMarching.SetOutputSize( =
gradiente.GetOutput().GetBufferedRegion().GetSize())
fastMarching.SetSpeedConstant( 1.0 )
fastMarching.SetStoppingValue(5.0)
fastMarching.Update()


# Implementacao do SHAPE

shapeD =3D itk.itkShapeDetectionLevelSetImageFilterF3F3_New()

shapeD.SetInput( fastMarching.GetOutput() )
shapeD.SetFeatureImage( sigmoid.GetOutput() )

shapeD.SetPropagationScaling( 10.0 )
shapeD.SetCurvatureScaling( 5.0 )

shapeD.SetMaximumRMSError( 0.02 )
shapeD.SetNumberOfIterations( 400 )
shapeD.Update()

# Threshold binario na imagem do Shape
bt =3D itk.itkBinaryThresholdImageFilterF3US3_New()  # Retorna UShort
bt.SetInput(shapeD.GetOutput())
bt.SetLowerThreshold(0)
bt.SetUpperThreshold(204)
bt.SetOutsideValue(0)
bt.SetInsideValue(2000)
bt.Update()

itkExporter =3D itk.itkVTKImageExportUS3_New()
itkExporter.SetInput(bt.GetOutput())
vtkImporter =3D vtk.vtkImageImport()
itk.ConnectITKUS3ToVTK(itkExporter.GetPointer(), vtkImporter)
vtkImporter.Update()


# Visualizacao

# Definindo a opacidade: Funcao de transferencia de opacidade

tfun =3D vtk.vtkPiecewiseFunction()
tfun.AddPoint(0.0, 0)
tfun.AddPoint(1.0, 0)
#tfun.AddPoint(199.0, 0)
#tfun.AddPoint(200.0, 0.5)
tfun.AddPoint(2.0, 1.0)
tfun.AddPoint(4095.0, 1.0)

# Definindo a funcao de transferencia de cores

ctfun =3D vtk.vtkColorTransferFunction()
ctfun.AddRGBPoint(0.0, 1.0, 0.1, 0.1)
ctfun.AddRGBPoint(4095.0, 1.0, 1.0, 1.0)


# Criando o volume
compositeFunction =3D vtk.vtkVolumeRayCastCompositeFunction()

volumeMapper =3D vtk.vtkVolumeRayCastMapper()
volumeMapper.SetInput(vtkImporter.GetOutput())
volumeMapper.SetVolumeRayCastFunction(compositeFunction)

volumeProperty =3D vtk.vtkVolumeProperty()
volumeProperty.SetColor(ctfun)
volumeProperty.SetScalarOpacity(tfun)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.ShadeOn()

Ator =3D vtk.vtkVolume()
Ator.SetMapper(volumeMapper)
Ator.SetProperty(volumeProperty)

ren =3D vtk.vtkRenderer()
ren.AddVolume(Ator)

# Criando a grade em volta do volume
out =3D vtk.vtkOutlineFilter()
out.SetInput(vtkImporter.GetOutput())

isoMapper2 =3D vtk.vtkOpenGLPolyDataMapper()
isoMapper2.SetInput(out.GetOutput())
isoMapper2.ScalarVisibilityOff()

isoActor2 =3D vtk.vtkOpenGLActor()
isoActor2.SetMapper(isoMapper2)

ren.AddActor(isoActor2)

janela =3D Tkinter.Tk()

imageframe =3D Frame(janela)
imageframe.pack(side=3DLEFT,fill =3D BOTH)

pane =3D vtkTkRenderWidget(imageframe,width =3D 512, height =3D 512)
pane.GetRenderWindow().AddRenderer(ren)
pane.pack()

janela.mainloop()

------=_NextPart_000_0056_01C42D2B.41D99A40--