<div dir="ltr"><div>Hello vtk-users,</div><div><br></div><div>I want to visualize a medical dataset using the HSV model color. I found this great VTK example that works very well <a href="https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/ImageGradient/">https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/ImageGradient/</a></div><div><br></div><div>However, this example use the vtkImageViewer class and the output is only one slice of the dataset. Anyone knows what mapper could be used to visualize the same  output but in a 3D way? </div><div><br></div><div>Any help provided for this would be greatly appreciated! <br></div><div><br></div><div>Here the code of the example:</div><div><br></div><div><div>import vtk</div><div><br></div><div>def main():<br></div><div>    fileName = get_program_parameters()</div><div>    colors = vtk.vtkNamedColors()</div><div><br></div><div>    # Read the CT data of the human head.</div><div>    reader = vtk.vtkMetaImageReader()</div><div>    reader.SetFileName(fileName)</div><div>    reader.Update()</div><div><br></div><div>    cast = vtk.vtkImageCast()</div><div>    cast.SetInputConnection(reader.GetOutputPort())</div><div>    cast.SetOutputScalarTypeToFloat()</div><div><br></div><div>    # Magnify the image.</div><div>    magnify = vtk.vtkImageMagnify()</div><div>    magnify.SetInputConnection(cast.GetOutputPort())</div><div>    magnify.SetMagnificationFactors(2, 2, 1)</div><div>    magnify.InterpolateOn()</div><div><br></div><div>    # Smooth the data.</div><div>    # Remove high frequency artifacts due to linear interpolation.</div><div>    smooth = vtk.vtkImageGaussianSmooth()</div><div>    smooth.SetInputConnection(magnify.GetOutputPort())</div><div>    smooth.SetDimensionality(2)</div><div>    smooth.SetStandardDeviations(1.5, 1.5, 0.0)</div><div>    smooth.SetRadiusFactors(2.01, 2.01, 0.0)</div><div><br></div><div>    # Compute the 2D gradient.</div><div>    gradient = vtk.vtkImageGradient()</div><div>    gradient.SetInputConnection(smooth.GetOutputPort())</div><div>    gradient.SetDimensionality(2)</div><div><br></div><div>    # Convert the data to polar coordinates.</div><div>    # The image magnitude is mapped into saturation value,</div><div>    # whilst the gradient direction is mapped into hue value.</div><div>    polar = vtk.vtkImageEuclideanToPolar()</div><div>    polar.SetInputConnection(gradient.GetOutputPort())</div><div>    polar.SetThetaMaximum(255.0)</div><div><br></div><div>    # Add a third component to the data.</div><div>    # This is needed since the gradient filter only generates two components,</div><div>    #  and we need three components to represent color.</div><div>    pad = vtk.vtkImageConstantPad()</div><div>    pad.SetInputConnection(polar.GetOutputPort())</div><div>    pad.SetOutputNumberOfScalarComponents(3)</div><div>    pad.SetConstant(200.0)</div><div><br></div><div>    # At this point we have Hue, Value, Saturation.</div><div>    # Permute components so saturation will be constant.</div><div>    # Re-arrange components into HSV order.</div><div>    permute = vtk.vtkImageExtractComponents()</div><div>    permute.SetInputConnection(pad.GetOutputPort())</div><div>    permute.SetComponents(0, 2, 1)</div><div><br></div><div>    # Convert back into RGB values.</div><div>    rgb = vtk.vtkImageHSVToRGB()</div><div>    rgb.SetInputConnection(permute.GetOutputPort())</div><div>    rgb.SetMaximum(255.0)</div><div><br></div><div>    # Set up a viewer for the image.</div><div>    # Note that vtkImageViewer and vtkImageViewer2 are convenience wrappers around</div><div>    # vtkActor2D, vtkImageMapper, vtkRenderer, and vtkRenderWindow.</div><div>    # So all that needs to be supplied is the interactor.</div><div>    viewer = vtk.vtkImageViewer()</div><div>    viewer.SetInputConnection(rgb.GetOutputPort())</div><div>    viewer.SetZSlice(22)</div><div>    viewer.SetColorWindow(255.0)</div><div>    viewer.SetColorLevel(127.0)</div><div>    viewer.GetRenderWindow().SetSize(512, 512)</div><div>    viewer.GetRenderer().SetBackground(colors.GetColor3d("Silver"))</div><div><br></div><div>    # Create the RenderWindowInteractor.</div><div>    iren = vtk.vtkRenderWindowInteractor()</div><div>    viewer.SetupInteractor(iren)</div><div>    viewer.Render()</div><div><br></div><div>    iren.Initialize()</div><div>    iren.Start()</div><div><br></div><div><br></div><div>def get_program_parameters():</div><div>    import argparse</div><div>    description = 'ImageGradient.'</div><div>    epilogue = '''</div><div>Visualization of gradient information.</div><div>   '''</div><div>    parser = argparse.ArgumentParser(description=description, epilog=epilogue,</div><div>                                     formatter_class=argparse.RawDescriptionHelpFormatter)</div><div>    parser.add_argument('fileName',</div><div>                        help='The file FullHead.mhd. Note: file FullHead.raw.gz must also be present in the same folder.')</div><div>    args = parser.parse_args()</div><div>    return args.fileName</div><div><br></div><div><br></div><div>if __name__ == '__main__':</div><div>    main()</div></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Lizeth  Castellanos.</div><div><br></div><div><br></div><div><br></div></div></div></div></div></div>
</div>