Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions auto_examples/DICOMExample/create3DSeqFromDicom.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Create 3D Sequence from DICOM\nauthor: OpenTPS team\n\nThis example shows how to read data from a 4DCT folder, create a dynamic 3D sequence with the 4DCT data, and save this sequence in serialized format on the drive.\n\nrunning time: ~ 10 minutes\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up the environment in google collab\n First you need to change the type of execution in the bottom left from processor to GPU. Then you can run the example.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nif \"google.colab\" in sys.modules:\n from IPython import get_ipython\n get_ipython().system('git clone https://gitlab.com/openmcsquare/opentps.git')\n get_ipython().system('pip install ./opentps')\n get_ipython().system('pip install scipy==1.10.1')\n get_ipython().system('pip install cupy-cuda12x')\n import opentps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"imports\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nfrom pathlib import Path\nimport sys"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"import the needed opentps.core packages\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from opentps.core.io.dataLoader import readData\nfrom opentps.core.data.dynamicData._dynamic3DSequence import Dynamic3DSequence\nfrom opentps.core.io.serializedObjectIO import saveSerializedObjects"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the current working directory, its parent, then add the testData folder at the end of it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"testDataPath = os.path.join(Path(os.getcwd()).parent.absolute(), 'testData/')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# read a serialized dynamic sequence\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dataPath = 'Path_to_your_4DCT_data/' # replace with the path to your 4DCT data folder\n\nprint('Datas present in ' + dataPath + 'are loaded.')\ndataList = readData(dataPath)\nprint(len(dataList), 'images found in the folder')\nprint('Image type =', type(dataList[0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"create a Dynamic3DSequence and change its name\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dynseq = Dynamic3DSequence(dyn3DImageList=dataList)\nprint('Type of the created object =', type(dynseq))\nprint('Sequence name =', dynseq.name)\ndynseq.name = 'Light4DCT'\nprint('Sequence name = ', dynseq.name)\nprint('Sequence lenght =', len(dynseq.dyn3DImageList))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"save it as a serialized object\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"savingPath = testDataPath + 'lightDynSeq'\nsaveSerializedObjects(dynseq, savingPath)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
158 changes: 158 additions & 0 deletions auto_examples/DICOMExample/create3DSeqFromImages.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Create 3D Sequence from Images\nauthor: OpenTPS team\n\nThis example shows how to read data from a 4DCT folder, create a dynamic 3D sequence with the 4DCT data, and save this sequence in serialized format on the drive.\n\nrunning time: ~ 10 minutes\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up the environment in google collab\n First you need to change the type of execution in the bottom left from processor to GPU. Then you can run the example.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nif \"google.colab\" in sys.modules:\n from IPython import get_ipython\n get_ipython().system('git clone https://gitlab.com/openmcsquare/opentps.git')\n get_ipython().system('pip install ./opentps')\n get_ipython().system('pip install scipy==1.10.1')\n get_ipython().system('pip install cupy-cuda12x')\n import opentps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"imports\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nfrom pathlib import Path\nimport sys"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"import the needed opentps.core packages\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from opentps.core.io.dataLoader import readData\nfrom opentps.core.data.dynamicData._dynamic3DSequence import Dynamic3DSequence\nfrom opentps.core.io.serializedObjectIO import saveSerializedObjects"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the current working directory, its parent, then add the testData folder at the end of it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"testDataPath = os.path.join(Path(os.getcwd()).parent.absolute(), 'testData/')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"read a serialized dynamic sequence\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dataPath = 'Path_to_your_4DCT_data/' # replace with the path to your 4DCT data folder\n\nprint('Datas present in ' + dataPath + 'are loaded.')\ndataList = readData(dataPath)\nprint(len(dataList), 'images found in the folder')\nprint('Image type =', type(dataList[0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"create a Dynamic3DSequence and change its name\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dynseq = Dynamic3DSequence(dyn3DImageList=dataList)\nprint('Type of the created object =', type(dynseq))\nprint('Sequence name =', dynseq.name)\ndynseq.name = 'Light4DCT'\nprint('Sequence name = ', dynseq.name)\nprint('Sequence lenght =', len(dynseq.dyn3DImageList))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"save it as a serialized object\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"savingPath = testDataPath + 'lightDynSeq'\nsaveSerializedObjects(dynseq, savingPath)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading
Loading