[Insight-users] What's wrong with this code?
Luis Ibanez
luis.ibanez at kitware.com
Thu, 22 Apr 2004 14:08:03 -0400
This is a multi-part message in MIME format.
--------------090403080809060006030103
Content-Type: text/plain; charset=GB2312
Content-Transfer-Encoding: 8bit
Hi Tsai,
A couple of things were wrong with
the example that you sent.
A) The threshold parameter for the
Watershed filter is too high:
Watershed.SetThreshold(1.0)
It is supposed to be a fraction
of 1.0, and typically should be
something like 1/10 of the water
level that you want to extract.
This line has been changed to
Watershed.SetThreshold( 0.1 )
B) The output of the Watershed filter
is an image of labels. This image
has pixel type = "unsigned long".
Therefore the writer that you need
is not of type:
writer = itkImageFileWriterF2_New()
It should be of type:
writer = itkImageFileWriterUL2_New()
C) The filename that you provide for the
output has extension .png. However,
the PNG format only supports unsigned
char and unsigned short pixel types.
For F2 or UL2 you should rather use a
fileformat like MetaImage. That is, use
an extension like ".mhd"
Please fine attached the modified version
of your code, that is now working fine.
Note also that a variant of this example
has now been commited under
Insight/Examples/Segmenation/
WatershedSegmentation1.py
Regards,
Luis
---------------
tsai wrote:
> Hello,insight-usersŁĄ
>
> import sys,os
> import paths
> from InsightToolkit import *
> from vtkMINCReader import *
> from ConnectVTKITK import *
>
> reader =itkImageFileReaderF2_New()
> reader.SetFileName("d:/Life/photo/genius.jpg")
>
> diffusion = itkGradientAnisotropicDiffusionImageFilterF2F2_New()
> diffusion.SetInput(reader.GetOutput())
> diffusion.SetTimeStep(0.0625)
> diffusion.SetConductanceParameter(9.0)
> diffusion.SetNumberOfIterations( 5 );
> ##
> gradient = itkGradientMagnitudeImageFilterF2F2_New()
> gradient.SetInput(diffusion.GetOutput())
>
> Watershed = itkWatershedImageFilterF2_New()
> Watershed.SetInput(gradient.GetOutput())
> Watershed.SetThreshold(1.0)
> Watershed.SetLevel(0.6)
> #print Watershed.GetOutput()
>
> writer = itkImageFileWriterF2_New()
> writer.SetFileName("e:/xjf.png")
> writer.SetInput( Watershed.GetOutput() )
> writer.Write()
>
>
> Best Regards,
>
> tsai
> tsai at sjtu.edu.cn
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
======================================================
--------------090403080809060006030103
Content-Type: text/plain;
name="code.py"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="code.py"
aW1wb3J0IHN5cyxvcwpmcm9tIEluc2lnaHRUb29sa2l0IGltcG9ydCAqCmZyb20gQ29ubmVj
dFZUS0lUSyBpbXBvcnQgKgoKcmVhZGVyID0gaXRrSW1hZ2VGaWxlUmVhZGVyRjJfTmV3KCkK
cmVhZGVyLlNldEZpbGVOYW1lKCJicmFpbi5qcGciKQoKZGlmZnVzaW9uID0gaXRrR3JhZGll
bnRBbmlzb3Ryb3BpY0RpZmZ1c2lvbkltYWdlRmlsdGVyRjJGMl9OZXcoKQpkaWZmdXNpb24u
U2V0SW5wdXQocmVhZGVyLkdldE91dHB1dCgpKQpkaWZmdXNpb24uU2V0VGltZVN0ZXAoMC4w
NjI1KQpkaWZmdXNpb24uU2V0Q29uZHVjdGFuY2VQYXJhbWV0ZXIoOS4wKQpkaWZmdXNpb24u
U2V0TnVtYmVyT2ZJdGVyYXRpb25zKCAgNSApOwoKZ3JhZGllbnQgPSBpdGtHcmFkaWVudE1h
Z25pdHVkZUltYWdlRmlsdGVyRjJGMl9OZXcoKQpncmFkaWVudC5TZXRJbnB1dChkaWZmdXNp
b24uR2V0T3V0cHV0KCkpCgpXYXRlcnNoZWQgPSBpdGtXYXRlcnNoZWRJbWFnZUZpbHRlckYy
X05ldygpCldhdGVyc2hlZC5TZXRJbnB1dChncmFkaWVudC5HZXRPdXRwdXQoKSkKV2F0ZXJz
aGVkLlNldFRocmVzaG9sZCgwLjEpCldhdGVyc2hlZC5TZXRMZXZlbCgwLjYpCgp3cml0ZXIg
PSBpdGtJbWFnZUZpbGVXcml0ZXJVTDJfTmV3KCkKd3JpdGVyLlNldEZpbGVOYW1lKCJ4amYu
bWhkIikKd3JpdGVyLlNldElucHV0KCBXYXRlcnNoZWQuR2V0T3V0cHV0KCkgICkKd3JpdGVy
LlVwZGF0ZSgpCgoKCg==
--------------090403080809060006030103--