Last active
March 31, 2023 10:27
-
-
Save behackl/c5cb14f702d9ec7c83dbb303f13afda6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ghcr.io/kbredies/gratopy:pocl-latest | |
ARG NB_UID=1000 | |
ARG NB_USER=gratopy | |
ENV USER ${NB_USER} | |
ENV NB_UID ${NB_UID} | |
ENV HOME /home/${NB_USER} | |
RUN adduser --disabled-password \ | |
--gecos "Default user" \ | |
--uid ${NB_UID} \ | |
${NB_USER} | |
RUN pip3 install notebook | |
USER ${NB_USER} | |
COPY . ${HOME} | |
USER root | |
RUN chown -R ${NB_UID} ${HOME} | |
USER ${NB_USER} | |
ENV PATH="${PATH}:${HOME}/.local/bin" | |
WORKDIR ${HOME} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "094bd1fc", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import pyopencl as cl\n", | |
"import matplotlib.pyplot as plt\n", | |
"\n", | |
"import gratopy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "0cb61f49", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# check that gratopy has been imported correctly\n", | |
"gratopy.VERSION" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9afef88b", | |
"metadata": {}, | |
"source": [ | |
"# Example 1\n", | |
"\n", | |
"... from https://gratopy.readthedocs.io/en/latest/getting_started.html#first-example-radon-transform" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5db64b23", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# discretization parameters\n", | |
"number_angles = 60\n", | |
"number_detectors = 300\n", | |
"Nx = 300\n", | |
"# Alternatively to number_angles one could give as angle input\n", | |
"# angles = np.linspace(0, np.pi, number_angles+1)[:-1]\n", | |
"\n", | |
"# create pyopencl context\n", | |
"ctx = cl.create_some_context()\n", | |
"queue = cl.CommandQueue(ctx)\n", | |
"\n", | |
"# create phantom as test image (a pyopencl.array.Array of dimensions (Nx, Nx))\n", | |
"phantom = gratopy.phantom(queue,Nx)\n", | |
"\n", | |
"# create suitable projectionsettings\n", | |
"PS = gratopy.ProjectionSettings(queue, gratopy.RADON, phantom.shape,\n", | |
" number_angles, number_detectors)\n", | |
"\n", | |
"# compute forward projection and backprojection of created sinogram\n", | |
"# results are pyopencl arrays\n", | |
"sino = gratopy.forwardprojection(phantom, PS)\n", | |
"backproj = gratopy.backprojection(sino, PS)\n", | |
"\n", | |
"# plot results\n", | |
"plt.figure()\n", | |
"plt.title(\"Generated Phantom\")\n", | |
"plt.imshow(phantom.get(), cmap=\"gray\")\n", | |
"\n", | |
"plt.figure()\n", | |
"plt.title(\"Sinogram\")\n", | |
"plt.imshow(sino.get(), cmap=\"gray\")\n", | |
"\n", | |
"plt.figure()\n", | |
"plt.title(\"Backprojection\")\n", | |
"plt.imshow(backproj.get(), cmap=\"gray\")\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6e99940b", | |
"metadata": {}, | |
"source": [ | |
"# Example 2\n", | |
"... from https://gratopy.readthedocs.io/en/latest/getting_started.html#second-example-fanbeam-transform" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "4d064136", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# discretization parameters\n", | |
"number_angles = 60\n", | |
"number_detectors = 300\n", | |
"image_shape = (500, 500)\n", | |
"\n", | |
"# create pyopencl context\n", | |
"ctx = cl.create_some_context()\n", | |
"queue = cl.CommandQueue(ctx)\n", | |
"\n", | |
"# physical parameters\n", | |
"my_detector_width = 120\n", | |
"my_R = 200\n", | |
"my_RE = 100\n", | |
"\n", | |
"# fanbeam setting with automatic image_width\n", | |
"PS1 = gratopy.ProjectionSettings(queue, gratopy.FANBEAM,\n", | |
" img_shape=image_shape,\n", | |
" angles=number_angles,\n", | |
" n_detectors=number_detectors,\n", | |
" detector_width=my_detector_width,\n", | |
" R=my_R, RE=my_RE)\n", | |
"\n", | |
"\n", | |
"print(\"image_width chosen by gratopy: {:.2f}\".format((PS1.image_width)))\n", | |
"\n", | |
"# fanbeam setting with set image_width\n", | |
"my_image_width = 80.0\n", | |
"PS2 = gratopy.ProjectionSettings(queue, gratopy.FANBEAM,\n", | |
" img_shape=image_shape,\n", | |
" angles=number_angles,\n", | |
" n_detectors=number_detectors,\n", | |
" detector_width=my_detector_width,\n", | |
" R=my_R, RE=my_RE,\n", | |
" image_width=my_image_width)\n", | |
"\n", | |
"# plot geometries associated to these projectionsettings\n", | |
"fig, (axes1, axes2) = plt.subplots(1,2)\n", | |
"PS1.show_geometry(np.pi/4, figure=fig, axes=axes1, show=False)\n", | |
"PS2.show_geometry(np.pi/4, figure=fig, axes=axes2, show=False)\n", | |
"axes1.set_title(\"Geometry chosen by gratopy as: {:.2f}\".format((PS1.image_width)))\n", | |
"axes2.set_title(\"Geometry for manually-chosen image_width as: {:.2f}\"\n", | |
" .format((my_image_width)))\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "8245d535", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment