{ "cells": [ { "cell_type": "markdown", "source": [ "# Cone\n", "\n", "This page illustrates the `Cone` shape in the Julia package\n", "[`ImagePhantoms`](https://github.com/JuliaImageRecon/ImagePhantoms.jl)." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "### Setup" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "Packages needed here." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using ImagePhantoms: Object, phantom, radon, spectrum\n", "using ImagePhantoms: Cone, cone\n", "import ImagePhantoms as IP\n", "using ImageGeoms: ImageGeom, axesf\n", "using MIRTjim: jim, prompt, mid3\n", "using FFTW: fft, fftshift, ifftshift\n", "using LazyGrids: ndgrid\n", "using Unitful: mm, unit, °\n", "using Plots: plot, plot!, scatter!, default\n", "using Plots # gif @animate\n", "default(markerstrokecolor=:auto)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "The following line is helpful when running this file as a script;\n", "this way it will prompt user to hit a key after each figure is displayed." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "isinteractive() ? jim(:prompt, true) : prompt(:draw);" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Overview\n", "\n", "A basic shape used in constructing 3D digital image phantoms\n", "is the cone,\n", "specified by its center, base radii, height, angle(s) and value.\n", "All of the methods in `ImagePhantoms` support physical units,\n", "so we use such units throughout this example.\n", "(Using units is recommended but not required.)\n", "\n", "Here are 3 ways to define a `Object{Cone}`,\n", "using physical units." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "center = (20mm, 10mm, -15mm)\n", "width = (25mm, 30mm, 35mm) # x radius, y radius, height\n", "ϕ0s = :(π/6) # symbol version for nice plot titles\n", "ϕ0 = eval(ϕ0s)\n", "angles = (ϕ0, 0, 0)\n", "Object(Cone(), center, width, angles, 1.0f0) # top-level constructor\n", "cone( 20mm, 10mm, 5mm, 25mm, 35mm, 15mm, π/6, 0, 0, 1.0f0) # 9 arguments\n", "ob = cone(center, width, angles, 1.0f0) # tuples (recommended use)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Phantom image using `phantom`\n", "\n", "Make a 3D digital image of it using `phantom` and display it.\n", "We use `ImageGeoms` to simplify the indexing." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "deltas = (1.0mm, 1.1mm, 0.9mm)\n", "dims = (2^8, 2^8+2, 49) # odd\n", "ig = ImageGeom( ; dims, deltas, offsets=:dsp)\n", "oversample = 3\n", "img = phantom(axes(ig)..., [ob], oversample)\n", "p1 = jim(axes(ig), img;\n", " title=\"Cone, rotation ϕ=$ϕ0s\", xlabel=\"x\", ylabel=\"y\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "The image integral should match the object volume:" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "volume = IP.volume(ob)\n", "(sum(img)*prod(ig.deltas), volume)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "Show middle slices" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "jim(mid3(img), \"Middle 3 planes\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "---\n", "\n", "*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" ], "metadata": {} } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.3" }, "kernelspec": { "name": "julia-1.10", "display_name": "Julia 1.10.3", "language": "julia" } }, "nbformat": 4 }