Add CT with 1 mm air padding on all edges for keeping TPS happy
"import shutil\n",
"from datetime import datetime\n",
"\n",
- "os.chdir(r\"E:\\Workspace\\dicomutils\\cube2\")\n",
- "if not os.path.exists(\"cube2_adjusted\"):\n",
- " os.mkdir(\"cube2_adjusted\")\n",
+ "os.chdir(r\"E:\\Workspace\\dicomutils\\cube3\")\n",
+ "if not os.path.exists(\"cube3_adjusted\"):\n",
+ " os.mkdir(\"cube3_adjusted\")\n",
"\n",
"for file in glob.glob(\"CT*.dcm\"):\n",
" ds = dcm.dcmread(file)\n",
" ds.PatientID = \"WATER\"\n",
" ds.PatientSex = \"O\"\n",
" \n",
- " ds.ImagePositionPatient[0]=-250\n",
+ " ds.ImagePositionPatient[0]=-251\n",
" ds.ImagePositionPatient[1]=0.5 \n",
" \n",
- " ds.save_as(\"cube2_adjusted\\\\\" + file)\n",
+ " if np.abs(ds.ImagePositionPatient[2])==251:\n",
+ " print(ds)\n",
+ " pixels = ds.pixel_array\n",
+ " pixels.fill(24)\n",
+ " ds.PixelData = pixels.tostring()\n",
+ " else:\n",
+ " print(ds)\n",
+ " pixels = ds.pixel_array\n",
+ " pixels[0][:] = 24.0\n",
+ " pixels[-1][:] = 24.0\n",
+ " pixels[:][0] = 24.0\n",
+ " pixels[:][-1] = 24.0\n",
+ " ds.PixelData = pixels.tostring()\n",
+ " \n",
+ " if ds.ImagePositionPatient[2]==-250:\n",
+ " np.savetxt(\"test.txt\", pixels)\n",
+ " \n",
+ " ds.save_as(\"cube3_adjusted\\\\\" + file)\n",
" print(ds.ImagePositionPatient)\n",
" print(ds.PixelSpacing[0])\n",
" \n",
- "shutil.make_archive(\"cube2_adjusted\", 'zip', \"cube2_adjusted\")"
+ "shutil.make_archive(\"cube3_adjusted\", 'zip', \"cube3_adjusted\")"
]
},
{
