# No Image when slicing along YZ or XZ plane

**URL:** https://discourse.vtk.org/t/no-image-when-slicing-along-yz-or-xz-plane/6695
**Category:** Support
**Created:** [September 25, 2021, 10:05am UTC](https://discourse.vtk.org/t/no-image-when-slicing-along-yz-or-xz-plane/6695 "2021-09-25T10:05:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Birkl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@Birkl](https://discourse.vtk.org/u/Birkl)
#### Post date: [September 25, 2021, 10:05am UTC](https://discourse.vtk.org/t/no-image-when-slicing-along-yz-or-xz-plane/6695/1 "2021-09-25T10:05:59Z")

</div>

Hi everyone,  
I’m currently working on MIPs for the 3 anatomical planes but I ran into some issues with sagittal and frontal.  
For those two I only get a completely black image as the output.

Below is the function to generate the MIP. (There might be a lot of bad style)  
\_input\_connection is the outputPort from a vtkImageBlend. The blend currently only got one input connection from a vtkNIFTIImageReader.  
If I put it directly into a vtkImageViewer2 and slice the image in there it works fine but for the MIP I need the vtkImageResliceMapper.

```auto
def __render_MIP(_input_connection : vtk.vtkAlgorithmOutput, _plane : int, _render_window : vtk.vtkRenderWindow, _renderer : vtk.vtkRenderer, _position : float):
    dummy_algorithm = vtk.vtkImageWriter() #can basically use any vtkImageAlgorithm
    dummy_algorithm.SetInputConnection(_input_connection)
    image = dummy_algorithm.GetInput()

    center = image.GetCenter()

    hist = vtk.vtkImageHistogramStatistics()
    hist.SetInputConnection(_input_connection)
    hist.Update()
    hist_range = hist.GetAutoRange()
    
    lut = vtk.vtkLookupTable()
    ctf = vtk.vtkColorTransferFunction()
    ctf.SetColorSpaceToDiverging()
    ctf.AddRGBPoint(0, 0, 0, 0)
    ctf.AddRGBPoint(1, 1, 1, 1)
    lut.SetNumberOfTableValues(256)
    lut.Build()

    for i in range(0, 245):
        rgb = list(ctf.GetColor(float(i) / 256)) + [1]
        lut.SetTableValue(i, rgb)

    lut.SetTableRange(hist_range[0], hist_range[1])
    lut.SetSaturationRange(0, 0)
    lut.SetHueRange(0, 1)
    lut.SetValueRange(0, 1)
    lut.SetNumberOfColors(256)
    lut.Build()

    plane = vtk.vtkPlane()
    plane.SetOrigin(center)

    if _plane == vars.VIEW_SAGITTAL():
        plane.SetNormal(1, 0, 0)
    elif _plane == vars.VIEW_FRONTAL():
        plane.SetNormal(0, 1, 0)
    else:
        plane.SetNormal(0, 0, 1)

    

    image_reslice_mapper = vtk.vtkImageResliceMapper()
    image_reslice_mapper.SetInputConnection(_input_connection)
    image_reslice_mapper.SetSlicePlane(plane)
    image_reslice_mapper.SetSlabThickness(3)
    image_reslice_mapper.SetSlabTypeToMin()
    image_reslice_mapper.SetSlabSampleFactor(1)
    image_reslice_mapper.ResampleToScreenPixelsOff()

    viewer = vtk.vtkImageViewer2()
    viewer.SetInputConnection(_input_connection)
    viewer.GetImageActor().SetMapper(image_reslice_mapper)
    viewer.GetWindowLevel().SetLookupTable(lut)

    max_slice = viewer.GetSliceMax()
    viewer.SetSlice(int(max_slice * _position))

    viewer.SetRenderWindow(_render_window)
    viewer.SetRenderer(_renderer)

    _renderer.ResetCamera()

    return viewer, None

```

Would be fantastic if somebody could help me out here.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 27, 2021, 3:13am UTC](https://discourse.vtk.org/t/no-image-when-slicing-along-yz-or-xz-plane/6695/2 "2021-09-27T03:13:22Z")

</div>

The YZ and XZ slices seem to disappear because the camera is viewing them edge-on. This can be fixed by rotating the camera around the focal point so that it faces the slice.

You might be able to rotate the camera by calling SetSliceOrientation() on the viewer, but I’m not sure what additional side-effects this might have, since vtkImageViewer2 wasn’t designed to be used with vtkImageResliceMapper and might behave strangely with this mapper.

The vtkImageResliceMapper class was meant to be used as the mapper for the vtkImageSlice class, which can in turn be controlled with vtkInteractorStyleImage (all with a general-purpose vtkRenderWindow and vtkRenderWindowInteractor, rather than with the vtkImageViewer2 class).

---

<div class="post-metadata">

### Author: ![Birkl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@Birkl](https://discourse.vtk.org/u/Birkl)
#### Post date: [September 29, 2021, 8:39am UTC](https://discourse.vtk.org/t/no-image-when-slicing-along-yz-or-xz-plane/6695/3 "2021-09-29T08:39:23Z")

</div>

Thanks!  
Changing the orientation worked for my purpose.  
I tried to rework that section for a vtkImageSlice and adding it directly to the renderer but figuring that out probably would cost me more time.
