8000 Add TransmissionAbsorptionConvertor example by hrobarts · Pull Request #180 · TomographicImaging/CIL-Demos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add TransmissionAbsorptionConvertor example #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
138 changes: 138 additions & 0 deletions how-to/3_Prepare_data/TransmissionAbsorptionConvertor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Transmission-absorption convertor\n",
"##### This example shows how to use the `TransmissionAbsorptionConvertor` processor"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the example dataset `dataexample.WALNUT` using `download_data()` then `get()`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from cil.utilities import dataexample\n",
"dataexample.WALNUT.download_data(data_dir='.', prompt=False)\n",
"data = dataexample.WALNUT.get('.')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a `TransmissionAbsorptionConvertor` procesor to convert from x-ray transmission data to x-ray absorption data using the Beer-Lambert law "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from cil.processors import TransmissionAbsorptionConverter\n",
"processor = TransmissionAbsorptionConverter()\n",
"processor.set_input(data)\n",
"data_abs = processor.get_output()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display the data before and after applying the `TransmissionAbsorptionConverter()` processor"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from cil.utilities.display import show2D\n",
"show2D([data, data_abs], ['Before TransmissionAbsorptionConverter', 'After TransmissionAbsorptionConverter'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the data contains zeros or negative numbers, you may want to consider using `Normaliser` first (see our examples on the How-To's page). Otherwise you can specify a minium value to use in the `TransmissionAbsorptionConverter` to avoid 0 in the log calculation"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"min_intensity = 0.0001 # specify a minimum value to avoid 0 in log"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also specify the value corresponding to the maximum transmission (white level), which will correspond to the transmission equalling zero, this might be useful if there are outliers in the data which you want to ignore"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"white_level = 1.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run `TransmissionAbsorptionConverter` again and plot the data with the new arguments"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"processor = TransmissionAbsorptionConverter(min_intensity=min_intensity, white_level=white_level)\n",
"processor.set_input(data)\n",
"data_abs = processor.get_output()\n",
"show2D([data, data_abs], ['Transmission', 'Absorption'])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "cil_tests",
"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.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
0