# Save PNG picture of model anterior view

**URL:** <https://discourse.slicer.org/t/save-png-picture-of-model-anterior-view/30080>\
**Category:** Support\
**Created:** [June 16, 2023, 6:32pm UTC](https://discourse.slicer.org/t/save-png-picture-of-model-anterior-view/30080 "2023-06-16T18:32:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [June 16, 2023, 6:32pm UTC](https://discourse.slicer.org/t/save-png-picture-of-model-anterior-view/30080/1 "2023-06-16T18:32:19Z")

</div>

I have drawn the blue box by hand to understand the problem.  
I want to save the blue box content as PNG file.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/4/24fa7533b06c111e0e726038143c6d373ba1e683.png)

I can find the coordinates of the boundary points of the blue box.

```auto
ModelNode = slicer.mrmlScene.GetFirstNodeByName('Model')
Vertices = numpy_support.vtk_to_numpy(ModelNode.GetPolyData().GetPoints().GetData())
blueboxMin=[Vertices[:,0].min(), Vertices[:,1].min(), Vertices[:,2].min()]
blueboxMax=[Vertices[:,0].max(), Vertices[:,1].max(), Vertices[:,2].max()]

```

But I don’t know how to save this region inside as PNG.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 16, 2023, 8:03pm UTC](https://discourse.slicer.org/t/save-png-picture-of-model-anterior-view/30080/2 "2023-06-16T20:03:21Z")

</div>

If you want a quick image of the 3D View, you can right-click in the view and select “Copy image” which will copy it to your clipboard and then you can paste it to your application of choice for saving as a png, or paste it directly into a power point file.

You can also use the “Screen Capture” module to save images of the various slice views.

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [June 16, 2023, 8:40pm UTC](https://discourse.slicer.org/t/save-png-picture-of-model-anterior-view/30080/3 "2023-06-16T20:40:23Z")

</div>

Thanks Jame,  
I found the solution to the problem:

```auto
# Set background to black (required for transparent background)
view = slicer.app.layoutManager().threeDWidget(0).threeDView()
view.rotateToViewAxis(3) # look from anterior direction
#view.resetFocalPoint() # reset the 3D view cube size and center it
#view.resetCamera() # reset camera zoom

```

after that

```auto
# Capture RGBA image
renderWindow = view.renderWindow()
renderWindow.SetAlphaBitPlanes(1)
wti = vtk.vtkWindowToImageFilter()
wti.SetInputBufferTypeToRGBA()
wti.SetInput(renderWindow)
writer = vtk.vtkPNGWriter()
writer.SetFileName("C:/Users/Administrator/Desktop/Slicer/face.png")
writer.SetInputConnection(wti.GetOutputPort())
writer.Write()

```

and cropping RGB

```auto
image = Image.open("C:/Users/Administrator/Desktop/Slicer/face.png")
image = image.convert("RGBA") 
width, height = image.size

left = width
top = height
right = 0
bottom = 0
for x in range(width):
    for y in range(height):
        pixel = image.getpixel((x, y))
        if pixel[3] != 0:
            left = min(left, x)
            top = min(top, y)
            right = max(right, x)
            bottom = max(bottom, y)

cropped_image = image.crop((left, top, right + 1, bottom + 1))
cropped_image.save("cropped_face.png")

```
