Skip to content

Commit cb45787

Browse files
authored
Merge pull request #157 from DiamondLightSource/rescale_agnostic
Rescale to int cpu/gpu agnostic
2 parents c4fd8cc + f35187b commit cb45787

File tree

13 files changed

+186
-40
lines changed

13 files changed

+186
-40
lines changed

conda/recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ requirements:
2222
- setuptools-git-versioning
2323
run:
2424
- python
25-
- numpy>= 1.20, <= 1.25
25+
- numpy>= 1.20, <= 1.26
2626
- cupy=12.3.0
2727
- astra-toolbox
2828
- nvtx
1.13 KB
Loading
1.14 KB
Loading
906 Bytes
Loading
15.3 KB
Loading
9.15 KB
Loading
9.57 KB
Loading

docs/source/reference/api.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ This section contains the API reference and usage information for HttomolibGPU.
88

99
HTTomolibGPU Modules
1010
---------------------
11-
v.2.1
12-
'''''
1311

1412
.. toctree::
1513
:glob:
@@ -22,4 +20,4 @@ v.2.1
2220
../api/httomolibgpu.prep.phase
2321
../api/httomolibgpu.prep.stripe
2422
../api/httomolibgpu.recon.algorithm
25-
../api/httomolibgpu.recon.rotation
23+
../api/httomolibgpu.recon.rotation

docs/source/reference/methods.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ Data correction module
1717
methods_list/outlier_removal
1818

1919

20+
.. _data_rescale_module:
21+
22+
Data rescale module
23+
^^^^^^^^^^^^^^^^^^^^^^
24+
25+
.. toctree::
26+
:glob:
27+
28+
methods_list/rescale_to_int
2029

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. _method_rescale_to_int:
2+
3+
Rescale to integers
4+
^^^^^^^^^^^^^^^^^^^
5+
6+
**Description**
7+
8+
This method is used to rescale the data before it gets saved into the images. The method allows you to rescale the data into 8, 16,
9+
or 32 bit of unsigned integer as well as to use the percentage scaling (explained bellow) to enhance contrast and remove outliers in the resulting images.
10+
11+
**Where and how to use it:**
12+
13+
The main purpose of this module is to help saving the data into images with rescaling. If the bit depth is reduced in the data, it can help to reduce the size of the saved images and in some situations simplify and accelerate of data analysis.
14+
15+
.. warning:: It is worth to note, however, that it is a lossy conversion when the bit depth of data is reduced. This can significantly alter the visual perception of the data as well as the quantitative side.
16+
17+
The rescaling module allows you to change the bit depth of a grayscale image, e.g., from 16-bit to 8-bit and also rescale the data in advance to avoid
18+
clipping of the data and therefore the loss of the information.
19+
20+
.. note:: The method does not save the data into images automatically, but only rescale the data. The user needs to take care of saving the data using an image saving method, e.g., the `image saver <https://diamondlightsource.github.io/httomolib/api/httomolib.misc.images.html>`_ of the HTTomolib library.
21+
22+
**What are the adjustable parameters:**
23+
24+
* :code:`bits` defines the number of bits in the resulting data. The input can be any data type and will be rescaled into unsigned integer of 8, 16 or 32 bit type.
25+
26+
* :code:`perc_range_min` defines the lower cutoff point in the input data, in percent of the data range (defaults to 0). The lower bound is computed as :math:`\frac{\textrm{perc_range_min} * (\max-\min)}{100} + \min`. Note that :math:`\max` and :math:`\min` values will be automatically estimated from the input data, unless they are provided with the `glob_stats` optional parameter.
27+
28+
* :code:`perc_range_max` defines the upper cutoff point in the input data, in percent of the data range (defaults to 100). The higher bound is computed as :math:`\frac{\textrm{perc_range_max} * (\max-\min)}{100} + \min`.
29+
30+
**Practical example:**
31+
32+
In this example we demonstrate how to use the rescaling when saving the data from float 32-bit precision into rescaled 8-bit.
33+
34+
.. list-table::
35+
36+
37+
* - .. figure:: ../../_static/auto_images_methods/rescale_to_int_proj_0_to_100.png
38+
39+
Projection data saved into 8-bit image with :code:`perc_range_min = 0` and :code:`perc_range_max = 100` scaling.
40+
41+
- .. figure:: ../../_static/auto_images_methods/rescale_to_int_histo_0_to_100.png
42+
43+
The corresponding histogram of the image to the left. Note that the background contains high values (250-255) and they dominate the image which is what reflected in the histogram.
44+
45+
* - .. figure:: ../../_static/auto_images_methods/rescale_to_int_proj_10_to_90.png
46+
47+
Projection data saved into 8-bit image with :code:`perc_range_min = 10` and :code:`perc_range_max = 90` scaling. Note that the contrast appears to be better with this scaling.
48+
- .. figure:: ../../_static/auto_images_methods/rescale_to_int_histo_10_to_90.png
49+
50+
The corresponding histogram of the image to the left. Note that the background is now outside the range and the histogram shows a good distribution of values withing the [0,128] range. If possible, however, it is better to aim for a wider histogram which represents the image well within the given range.
51+
52+
* - .. figure:: ../../_static/auto_images_methods/rescale_to_int_proj_30_to_70.png
53+
54+
Projection data saved into 8-bit image with :code:`perc_range_min = 30` and :code:`perc_range_max = 70` scaling. This is en example of a poorer scaling when the loss of the information is clearly visible through poorer contrast.
55+
- .. figure:: ../../_static/auto_images_methods/rescale_to_int_histo_30_to_70.png
56+
57+
The corresponding histogram of the image to the left. Note that the histogram has been significantly flattened with this scaling. Meaning that there is less values that represent the image in the selected range. And the histogram also has got less variation of values compared to the histogram without percentage scaling. Such flat histograms is best to avoid.

0 commit comments

Comments
 (0)