-
Notifications
You must be signed in to change notification settings - Fork 2
/
screencapture.py
117 lines (83 loc) · 5.05 KB
/
screencapture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
######ADD SPECIES LABEL TO TOP OF 3D VIEW
specieslabel = "Fratercula arctica" #input species name
view=slicer.app.layoutManager().threeDWidget(0).threeDView()
# Set text to "Something"
view.cornerAnnotation().SetText(vtk.vtkCornerAnnotation.UpperRight,specieslabel)
# Set color to red
view.cornerAnnotation().GetTextProperty().SetColor(1,1,0)#set text color
# Update the view
view.forceRender()
###############3
#create directory for gifs
import os
gifdir = slicedir+'\\'+ID+'gif'
os.mkdir(gifdir)
#capture 3d rotation
layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)
threeDView = threeDWidget.threeDView()
viewNodeID = 'vtkMRMLViewNode1'
cap3d = ScreenCapture.ScreenCaptureLogic()
view = cap3d.viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID))
for i in range(25):
threeDView.yaw()#rotate thre 3D
threeDView.yaw()#rotate thre 3D
cap3d.captureImageFromView(view,gifdir+'\\'+ID+'gif'+str(i)+'.png')#slicer.mrmlScene.GetRootDirectory()
#os.path.join(gifdir)
#gifdir = 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif'
#make list of imagepaths
imgpaths = []
for i in range(0,len(os.listdir(gifdir))):
imgpaths.append(gifdir+'\\'+os.listdir(gifdir)[i])
import subprocess
subprocess.run(imgpaths, universal_newlines=True, input=data)
imgpaths = ['D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif0.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif1.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif2.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif3.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif4.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif5.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif6.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif7.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif8.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif9.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif10.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif11.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif12.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif13.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif14.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif15.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif16.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif17.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif18.png', 'D:\\Analysis_plots\\3dslicerscreenshots\\BO-02-2019\\BO-02-2019gif\\BO-02-2019gif19.png']
gifdir
from PIL import Image, ImageDraw
# save to GIF in here
images = []#make list of image objects
for n in imgpaths: #populat the list
frame = Image.open(n)
images.append(frame)
# Save the frames as an animated GIF
images[0].save('E:\\Analysis_plots\\3dslicerscreenshots\\ADP-01-2019\\ADP-01-2019gif'+'\\ID.gif',
save_all=True,
append_images=images[1:],
duration=100,
loop=0)
# Disable slice annotations immediately
slicer.modules.DataProbeInstance.infoWidget.sliceAnnotations.sliceViewAnnotationsEnabled=False
slicer.modules.DataProbeInstance.infoWidget.sliceAnnotations.updateSliceViewFromGUI()
# Disable slice annotations persistently (after Slicer restarts)
settings = qt.QSettings()
settings.setValue('DataProbe/sliceViewAnnotations.enabled', 0)
#views nodes:
#3d 'vtkMRMLViewNode1'
#'vtkMRMLSliceNodeRed'
#'vtkMRMLSliceNodeYellow'
#'vtkMRMLSliceNodeGreen'
#Capture a single slice view:
#create directory for pics
import os
slicedir = 'D:\\Analysis_plots\\3dslicerscreenshots\\'+ID
os.mkdir(slicedir)
import ScreenCapture
viewNodeID = 'vtkMRMLSliceNodeRed'
cap = ScreenCapture.ScreenCaptureLogic()
view = cap.viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID))
cap.captureImageFromView(view,slicedir+'\\'+ID+'redslice.tif')
import ScreenCapture
viewNodeID = 'vtkMRMLSliceNodeRed'
cap = ScreenCapture.ScreenCaptureLogic()
view = cap.viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID))
cap.captureImageFromView(view,slicedir+'\\'+ID+'redslice2.tif')
#ScreenCapture.ScreenCaptureLogic().viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID)).createVideo()
threeDView.yaw()#rotate thre 3D
cap.captureImageFromView(view,'c:/tmp/testj.png')
os.listdir(gifdir)[0]
def listdir_fullpath(d):
return [os.path.join(d, f) for f in os.listdir(d)]
listdir_fullpath(d)
#slice sweep
import ScreenCapture
ScreenCapture.ScreenCaptureLogic().captureSliceSweep(getNode('vtkMRMLSliceNodeRed'), -125.0, 75.0, 30, "c:/tmp", "image_%05d.png")