Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thewtex/c4a158711726bbfebbd9dac9936c0f13 to your computer and use it in GitHub Desktop.
Save thewtex/c4a158711726bbfebbd9dac9936c0f13 to your computer and use it in GitHub Desktop.
ITK + Dask notebooks (August 2022)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1e772694",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/genevieb/em95/miniconda/conda/envs/itk-dask/bin/python\r\n"
]
}
],
"source": [
"!which python"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a1a0ad7e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# packages in environment at /home/genevieb/em95/miniconda/conda/envs/itk-dask:\r\n",
"itk 5.3rc4.post2 pypi_0 pypi\r\n",
"itk-core 5.3rc4.post2 pypi_0 pypi\r\n",
"itk-filtering 5.3rc4.post2 pypi_0 pypi\r\n",
"itk-io 5.3rc4.post2 pypi_0 pypi\r\n",
"itk-numerics 5.3rc4.post2 pypi_0 pypi\r\n",
"itk-registration 5.3rc4.post2 pypi_0 pypi\r\n",
"itk-segmentation 5.3rc4.post2 pypi_0 pypi\r\n"
]
}
],
"source": [
"!conda list | grep itk"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e99e08b3",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"(101, 64, 64)\n"
]
}
],
"source": [
"import tifffile\n",
"\n",
"psf_filename = \"psfs_z0p1/PSF_488nm_dz100nm.tif\"\n",
"psf = tifffile.imread(psf_filename)\n",
"print(psf.shape)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "835cdf9d",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/genevieb/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.1\n",
" warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <td>\n",
" <table>\n",
" <thead>\n",
" <tr>\n",
" <td> </td>\n",
" <th> Array </th>\n",
" <th> Chunk </th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" \n",
" <tr>\n",
" <th> Bytes </th>\n",
" <td> 58.59 GiB </td>\n",
" <td> 301.50 MiB </td>\n",
" </tr>\n",
" \n",
" <tr>\n",
" <th> Shape </th>\n",
" <td> (199, 201, 1024, 768) </td>\n",
" <td> (1, 201, 1024, 768) </td>\n",
" </tr>\n",
" <tr>\n",
" <th> Count </th>\n",
" <td> 199 Tasks </td>\n",
" <td> 199 Chunks </td>\n",
" </tr>\n",
" <tr>\n",
" <th> Type </th>\n",
" <td> uint16 </td>\n",
" <td> numpy.ndarray </td>\n",
" </tr>\n",
" </tbody>\n",
" </table>\n",
" </td>\n",
" <td>\n",
" <svg width=\"386\" height=\"194\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"0\" y1=\"0\" x2=\"41\" y2=\"0\" style=\"stroke-width:2\" />\n",
" <line x1=\"0\" y1=\"25\" x2=\"41\" y2=\"25\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"25\" style=\"stroke-width:2\" />\n",
" <line x1=\"1\" y1=\"0\" x2=\"1\" y2=\"25\" />\n",
" <line x1=\"2\" y1=\"0\" x2=\"2\" y2=\"25\" />\n",
" <line x1=\"3\" y1=\"0\" x2=\"3\" y2=\"25\" />\n",
" <line x1=\"5\" y1=\"0\" x2=\"5\" y2=\"25\" />\n",
" <line x1=\"6\" y1=\"0\" x2=\"6\" y2=\"25\" />\n",
" <line x1=\"7\" y1=\"0\" x2=\"7\" y2=\"25\" />\n",
" <line x1=\"9\" y1=\"0\" x2=\"9\" y2=\"25\" />\n",
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"25\" />\n",
" <line x1=\"11\" y1=\"0\" x2=\"11\" y2=\"25\" />\n",
" <line x1=\"13\" y1=\"0\" x2=\"13\" y2=\"25\" />\n",
" <line x1=\"14\" y1=\"0\" x2=\"14\" y2=\"25\" />\n",
" <line x1=\"15\" y1=\"0\" x2=\"15\" y2=\"25\" />\n",
" <line x1=\"16\" y1=\"0\" x2=\"16\" y2=\"25\" />\n",
" <line x1=\"18\" y1=\"0\" x2=\"18\" y2=\"25\" />\n",
" <line x1=\"19\" y1=\"0\" x2=\"19\" y2=\"25\" />\n",
" <line x1=\"20\" y1=\"0\" x2=\"20\" y2=\"25\" />\n",
" <line x1=\"22\" y1=\"0\" x2=\"22\" y2=\"25\" />\n",
" <line x1=\"23\" y1=\"0\" x2=\"23\" y2=\"25\" />\n",
" <line x1=\"24\" y1=\"0\" x2=\"24\" y2=\"25\" />\n",
" <line x1=\"26\" y1=\"0\" x2=\"26\" y2=\"25\" />\n",
" <line x1=\"27\" y1=\"0\" x2=\"27\" y2=\"25\" />\n",
" <line x1=\"28\" y1=\"0\" x2=\"28\" y2=\"25\" />\n",
" <line x1=\"30\" y1=\"0\" x2=\"30\" y2=\"25\" />\n",
" <line x1=\"31\" y1=\"0\" x2=\"31\" y2=\"25\" />\n",
" <line x1=\"32\" y1=\"0\" x2=\"32\" y2=\"25\" />\n",
" <line x1=\"33\" y1=\"0\" x2=\"33\" y2=\"25\" />\n",
" <line x1=\"35\" y1=\"0\" x2=\"35\" y2=\"25\" />\n",
" <line x1=\"36\" y1=\"0\" x2=\"36\" y2=\"25\" />\n",
" <line x1=\"37\" y1=\"0\" x2=\"37\" y2=\"25\" />\n",
" <line x1=\"39\" y1=\"0\" x2=\"39\" y2=\"25\" />\n",
" <line x1=\"40\" y1=\"0\" x2=\"40\" y2=\"25\" />\n",
" <line x1=\"41\" y1=\"0\" x2=\"41\" y2=\"25\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"0.0,0.0 41.88758677146205,0.0 41.88758677146205,25.412616514582485 0.0,25.412616514582485\" style=\"fill:#8B4903A0;stroke-width:0\"/>\n",
"\n",
" <!-- Text -->\n",
" <text x=\"20.943793\" y=\"45.412617\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >199</text>\n",
" <text x=\"61.887587\" y=\"12.706308\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,61.887587,12.706308)\">1</text>\n",
"\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"135\" y2=\"24\" style=\"stroke-width:2\" />\n",
" <line x1=\"111\" y1=\"120\" x2=\"135\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"111\" y2=\"120\" style=\"stroke-width:2\" />\n",
" <line x1=\"135\" y1=\"24\" x2=\"135\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"111.0,0.0 135.66491790838793,24.664917908387924 135.66491790838793,144.66491790838793 111.0,120.0\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"201\" y2=\"0\" style=\"stroke-width:2\" />\n",
" <line x1=\"135\" y1=\"24\" x2=\"225\" y2=\"24\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"135\" y2=\"24\" style=\"stroke-width:2\" />\n",
" <line x1=\"201\" y1=\"0\" x2=\"225\" y2=\"24\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"111.0,0.0 201.0,0.0 225.66491790838793,24.664917908387924 135.66491790838793,24.664917908387924\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"135\" y1=\"24\" x2=\"225\" y2=\"24\" style=\"stroke-width:2\" />\n",
" <line x1=\"135\" y1=\"144\" x2=\"225\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"135\" y1=\"24\" x2=\"135\" y2=\"144\" style=\"stroke-width:2\" />\n",
" <line x1=\"225\" y1=\"24\" x2=\"225\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"135.6649179083879,24.664917908387924 225.6649179083879,24.664917908387924 225.6649179083879,144.66491790838793 135.6649179083879,144.66491790838793\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Text -->\n",
" <text x=\"180.664918\" y=\"164.664918\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >768</text>\n",
" <text x=\"245.664918\" y=\"84.664918\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,245.664918,84.664918)\">1024</text>\n",
" <text x=\"113.332459\" y=\"152.332459\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,113.332459,152.332459)\">201</text>\n",
"</svg>\n",
" </td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"dask.array<imread, shape=(199, 201, 1024, 768), dtype=uint16, chunksize=(1, 201, 1024, 768), chunktype=numpy.ndarray>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from dask.array.image import imread\n",
"\n",
"raw_filename = \"raw-488nm/*.tif\"\n",
"imgs = imread(raw_filename)\n",
"imgs"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f125a926",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n",
"TiffTag 32781: coercing invalid ASCII to bytes\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"(201, 1024, 768)\n"
]
}
],
"source": [
"single_img_filename = \"raw-488nm/ex6-2_CamB_ch0_CAM1_stack0000_488nm_0000000msec_0001291795msecAbs_000x_000y_000z_0000t.tif\"\n",
"img = tifffile.imread(single_img_filename)\n",
"print(img.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5b43d300",
"metadata": {},
"outputs": [],
"source": [
"from skimage import restoration\n",
"\n",
"deconvolved_RL = restoration.richardson_lucy(img, psf, num_iter=30)\n",
"print(deconvolved_RL.shape)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2ca2a48b",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'itkRichardsonLucyDeconvolutionImageFilterIUS3IUS3' object has no attribute 'SetKernel'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [6]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mitk\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m deconvolved_RLitk\u001b[38;5;241m=\u001b[39m \u001b[43mitk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrichardson_lucy_deconvolution_image_filter\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkernel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpsf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43miterations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(deconvoled_RLitk\u001b[38;5;241m.\u001b[39mshape)\n",
"File \u001b[0;32m~/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/itk/support/helpers.py:139\u001b[0m, in \u001b[0;36maccept_array_like_xarray_torch.<locals>.image_filter_wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 135\u001b[0m kwargs[key] \u001b[38;5;241m=\u001b[39m image\n\u001b[1;32m 137\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m have_xarray_input \u001b[38;5;129;01mor\u001b[39;00m have_torch_input \u001b[38;5;129;01mor\u001b[39;00m have_array_input:\n\u001b[1;32m 138\u001b[0m \u001b[38;5;66;03m# Convert output itk.Image's to numpy.ndarray's\u001b[39;00m\n\u001b[0;32m--> 139\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[43mimage_filter\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mtuple\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs_list\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 140\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(output, \u001b[38;5;28mtuple\u001b[39m):\n\u001b[1;32m 141\u001b[0m output_list \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(output)\n",
"File \u001b[0;32m~/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/itk/itkRichardsonLucyDeconvolutionImageFilterPython.py:876\u001b[0m, in \u001b[0;36mrichardson_lucy_deconvolution_image_filter\u001b[0;34m(number_of_iterations, stop_iteration, size_greatest_prime_factor, boundary_condition, kernel_image, normalize, output_region_mode, *args, **kwargs)\u001b[0m\n\u001b[1;32m 873\u001b[0m specified_kwarg_typehints \u001b[38;5;241m=\u001b[39m { k:v \u001b[38;5;28;01mfor\u001b[39;00m (k,v) \u001b[38;5;129;01min\u001b[39;00m kwarg_typehints\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m kwarg_typehints[k] \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;241m.\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;241m.\u001b[39m }\n\u001b[1;32m 874\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mupdate(specified_kwarg_typehints)\n\u001b[0;32m--> 876\u001b[0m instance \u001b[38;5;241m=\u001b[39m \u001b[43mitk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mRichardsonLucyDeconvolutionImageFilter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mNew\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 877\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m instance\u001b[38;5;241m.\u001b[39m__internal_call__()\n",
"File \u001b[0;32m~/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/itk/support/template_class.py:735\u001b[0m, in \u001b[0;36mitkTemplate.New\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 732\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mitk\u001b[39;00m\n\u001b[1;32m 734\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m itk\u001b[38;5;241m.\u001b[39mTemplateTypeError(\u001b[38;5;28mself\u001b[39m, input_type)\n\u001b[0;32m--> 735\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkeys\u001b[49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mNew\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/itk/itkRichardsonLucyDeconvolutionImageFilterPython.py:802\u001b[0m, in \u001b[0;36mitkRichardsonLucyDeconvolutionImageFilterIUS3IUS3.New\u001b[0;34m(*args, **kargs)\u001b[0m\n\u001b[1;32m 800\u001b[0m obj \u001b[38;5;241m=\u001b[39m itkRichardsonLucyDeconvolutionImageFilterIUS3IUS3\u001b[38;5;241m.\u001b[39m__New_orig__()\n\u001b[1;32m 801\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mitk\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msupport\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m template_class\n\u001b[0;32m--> 802\u001b[0m \u001b[43mtemplate_class\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mNew\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 803\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m obj\n",
"File \u001b[0;32m~/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/itk/support/template_class.py:800\u001b[0m, in \u001b[0;36mNew\u001b[0;34m(self, *args, **kargs)\u001b[0m\n\u001b[1;32m 797\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mNew\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkargs):\n\u001b[1;32m 798\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mitk\u001b[39;00m\n\u001b[0;32m--> 800\u001b[0m \u001b[43mitk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_inputs\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 802\u001b[0m \u001b[38;5;66;03m# now, try to add observer to display progress\u001b[39;00m\n\u001b[1;32m 803\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mauto_progress\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m kargs\u001b[38;5;241m.\u001b[39mkeys():\n",
"File \u001b[0;32m~/em95/miniconda/conda/envs/itk-dask/lib/python3.10/site-packages/itk/support/extras.py:1508\u001b[0m, in \u001b[0;36mset_inputs\u001b[0;34m(new_itk_object, inargs, inkargs)\u001b[0m\n\u001b[1;32m 1506\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m attribName\u001b[38;5;241m.\u001b[39mislower():\n\u001b[1;32m 1507\u001b[0m attribName \u001b[38;5;241m=\u001b[39m _snake_to_camel(attribName)\n\u001b[0;32m-> 1508\u001b[0m attrib \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mgetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_itk_object\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mSet\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mattribName\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1510\u001b[0m \u001b[38;5;66;03m# Do not use try-except mechanism as this leads to\u001b[39;00m\n\u001b[1;32m 1511\u001b[0m \u001b[38;5;66;03m# segfaults. Instead limit the number of types that are\u001b[39;00m\n\u001b[1;32m 1512\u001b[0m \u001b[38;5;66;03m# tested. The list of tested type could maybe be replaced by\u001b[39;00m\n\u001b[1;32m 1513\u001b[0m \u001b[38;5;66;03m# a test that would check for iterables.\u001b[39;00m\n\u001b[1;32m 1514\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mitk\u001b[39;00m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'itkRichardsonLucyDeconvolutionImageFilterIUS3IUS3' object has no attribute 'SetKernel'"
]
}
],
"source": [
"import itk\n",
"\n",
"deconvolved_RLitk = itk.richardson_lucy_deconvolution_image_filter(img, kernel=psf, iterations=1)\n",
"print(deconvoled_RLitk.shape)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "e38c2f4d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <td>\n",
" <table>\n",
" <thead>\n",
" <tr>\n",
" <td> </td>\n",
" <th> Array </th>\n",
" <th> Chunk </th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" \n",
" <tr>\n",
" <th> Bytes </th>\n",
" <td> 58.59 GiB </td>\n",
" <td> 75.38 MiB </td>\n",
" </tr>\n",
" \n",
" <tr>\n",
" <th> Shape </th>\n",
" <td> (199, 201, 1024, 768) </td>\n",
" <td> (1, 201, 512, 384) </td>\n",
" </tr>\n",
" <tr>\n",
" <th> Count </th>\n",
" <td> 1791 Tasks </td>\n",
" <td> 796 Chunks </td>\n",
" </tr>\n",
" <tr>\n",
" <th> Type </th>\n",
" <td> uint16 </td>\n",
" <td> numpy.ndarray </td>\n",
" </tr>\n",
" </tbody>\n",
" </table>\n",
" </td>\n",
" <td>\n",
" <svg width=\"386\" height=\"194\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"0\" y1=\"0\" x2=\"41\" y2=\"0\" style=\"stroke-width:2\" />\n",
" <line x1=\"0\" y1=\"25\" x2=\"41\" y2=\"25\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"25\" style=\"stroke-width:2\" />\n",
" <line x1=\"1\" y1=\"0\" x2=\"1\" y2=\"25\" />\n",
" <line x1=\"2\" y1=\"0\" x2=\"2\" y2=\"25\" />\n",
" <line x1=\"3\" y1=\"0\" x2=\"3\" y2=\"25\" />\n",
" <line x1=\"5\" y1=\"0\" x2=\"5\" y2=\"25\" />\n",
" <line x1=\"6\" y1=\"0\" x2=\"6\" y2=\"25\" />\n",
" <line x1=\"7\" y1=\"0\" x2=\"7\" y2=\"25\" />\n",
" <line x1=\"9\" y1=\"0\" x2=\"9\" y2=\"25\" />\n",
" <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"25\" />\n",
" <line x1=\"11\" y1=\"0\" x2=\"11\" y2=\"25\" />\n",
" <line x1=\"13\" y1=\"0\" x2=\"13\" y2=\"25\" />\n",
" <line x1=\"14\" y1=\"0\" x2=\"14\" y2=\"25\" />\n",
" <line x1=\"15\" y1=\"0\" x2=\"15\" y2=\"25\" />\n",
" <line x1=\"16\" y1=\"0\" x2=\"16\" y2=\"25\" />\n",
" <line x1=\"18\" y1=\"0\" x2=\"18\" y2=\"25\" />\n",
" <line x1=\"19\" y1=\"0\" x2=\"19\" y2=\"25\" />\n",
" <line x1=\"20\" y1=\"0\" x2=\"20\" y2=\"25\" />\n",
" <line x1=\"22\" y1=\"0\" x2=\"22\" y2=\"25\" />\n",
" <line x1=\"23\" y1=\"0\" x2=\"23\" y2=\"25\" />\n",
" <line x1=\"24\" y1=\"0\" x2=\"24\" y2=\"25\" />\n",
" <line x1=\"26\" y1=\"0\" x2=\"26\" y2=\"25\" />\n",
" <line x1=\"27\" y1=\"0\" x2=\"27\" y2=\"25\" />\n",
" <line x1=\"28\" y1=\"0\" x2=\"28\" y2=\"25\" />\n",
" <line x1=\"30\" y1=\"0\" x2=\"30\" y2=\"25\" />\n",
" <line x1=\"31\" y1=\"0\" x2=\"31\" y2=\"25\" />\n",
" <line x1=\"32\" y1=\"0\" x2=\"32\" y2=\"25\" />\n",
" <line x1=\"33\" y1=\"0\" x2=\"33\" y2=\"25\" />\n",
" <line x1=\"35\" y1=\"0\" x2=\"35\" y2=\"25\" />\n",
" <line x1=\"36\" y1=\"0\" x2=\"36\" y2=\"25\" />\n",
" <line x1=\"37\" y1=\"0\" x2=\"37\" y2=\"25\" />\n",
" <line x1=\"39\" y1=\"0\" x2=\"39\" y2=\"25\" />\n",
" <line x1=\"40\" y1=\"0\" x2=\"40\" y2=\"25\" />\n",
" <line x1=\"41\" y1=\"0\" x2=\"41\" y2=\"25\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"0.0,0.0 41.88758677146205,0.0 41.88758677146205,25.412616514582485 0.0,25.412616514582485\" style=\"fill:#8B4903A0;stroke-width:0\"/>\n",
"\n",
" <!-- Text -->\n",
" <text x=\"20.943793\" y=\"45.412617\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >199</text>\n",
" <text x=\"61.887587\" y=\"12.706308\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,61.887587,12.706308)\">1</text>\n",
"\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"135\" y2=\"24\" style=\"stroke-width:2\" />\n",
" <line x1=\"111\" y1=\"60\" x2=\"135\" y2=\"84\" />\n",
" <line x1=\"111\" y1=\"120\" x2=\"135\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"111\" y2=\"120\" style=\"stroke-width:2\" />\n",
" <line x1=\"135\" y1=\"24\" x2=\"135\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"111.0,0.0 135.66491790838793,24.664917908387924 135.66491790838793,144.66491790838793 111.0,120.0\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"201\" y2=\"0\" style=\"stroke-width:2\" />\n",
" <line x1=\"135\" y1=\"24\" x2=\"225\" y2=\"24\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"111\" y1=\"0\" x2=\"135\" y2=\"24\" style=\"stroke-width:2\" />\n",
" <line x1=\"156\" y1=\"0\" x2=\"180\" y2=\"24\" />\n",
" <line x1=\"201\" y1=\"0\" x2=\"225\" y2=\"24\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"111.0,0.0 201.0,0.0 225.66491790838793,24.664917908387924 135.66491790838793,24.664917908387924\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"135\" y1=\"24\" x2=\"225\" y2=\"24\" style=\"stroke-width:2\" />\n",
" <line x1=\"135\" y1=\"84\" x2=\"225\" y2=\"84\" />\n",
" <line x1=\"135\" y1=\"144\" x2=\"225\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"135\" y1=\"24\" x2=\"135\" y2=\"144\" style=\"stroke-width:2\" />\n",
" <line x1=\"180\" y1=\"24\" x2=\"180\" y2=\"144\" />\n",
" <line x1=\"225\" y1=\"24\" x2=\"225\" y2=\"144\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"135.6649179083879,24.664917908387924 225.6649179083879,24.664917908387924 225.6649179083879,144.66491790838793 135.6649179083879,144.66491790838793\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Text -->\n",
" <text x=\"180.664918\" y=\"164.664918\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >768</text>\n",
" <text x=\"245.664918\" y=\"84.664918\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,245.664918,84.664918)\">1024</text>\n",
" <text x=\"113.332459\" y=\"152.332459\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(45,113.332459,152.332459)\">201</text>\n",
"</svg>\n",
" </td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"dask.array<rechunk-merge, shape=(199, 201, 1024, 768), dtype=uint16, chunksize=(1, 201, 512, 384), chunktype=numpy.ndarray>"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import dask.array as da\n",
"\n",
"imgs = da.rechunk(imgs)\n",
"imgs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc3ee594",
"metadata": {},
"outputs": [],
"source": [
"import itk\n",
"\n",
"deconvolved = da.map_blocks(itk.richardson_lucy_deconvolution_image_filter, imgs, kernel=psf, iterations=1, dtype=np.float32)\n",
"deconvolved"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment