API Reference
Calibration
FilmCalibration
Source code in app/calibration/calibration.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
__init__(groundtruth_image, bits_per_channel=8, calibration_type='single-channel', fitting_function_name='polynomial', filter_type='median')
Initializes the film calibration process by setting the ground truth image and the calibration type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groundtruth_image
|
ndarray
|
The original ground truth image where the irradiated films are located. It must be a NumPy array with dimensions [height, width, channels]. |
required |
bits_per_channel
|
int
|
Number of bits per channel (default is 8). |
8
|
calibration_type
|
str
|
Calibration type ('single-channel' or 'multi-channel'). Default is 'single-channel'. |
'single-channel'
|
fitting_function_name
|
str
|
Name of the fitting function to use. Default is 'polynomial'. |
'polynomial'
|
filter_type
|
str
|
Type of filter to apply to images. Default is 'median'. |
'median'
|
Source code in app/calibration/calibration.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
add_roi(dose, x, y, width, height)
Registers a region of interest (ROI) associated with a given dose. If the dose does not exist, a new CalibrationDose instance is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dose
|
float
|
Dose value (in Gy). |
required |
x
|
int
|
X-coordinate (top-left corner) of the ROI. |
required |
y
|
int
|
Y-coordinate (top-left corner) of the ROI. |
required |
size
|
int
|
Length of the square defining the ROI. |
required |
Source code in app/calibration/calibration.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
calibrate(calibration_type='single-channel')
Calibrates the film based on the specified calibration type. Currently, only single-channel calibration is implemented, which includes:
- Computing channel averages.
- Computing netOD (or another independent variable) for each dose.
- Fitting the calibration function using curve_fit.
The fitting uses the independent variable as the independent value and the dose as the dependent value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calibration_type
|
str
|
Calibration type ('single-channel' or 'multi-channel'). Default is 'single-channel'. |
'single-channel'
|
Returns:
| Type | Description |
|---|---|
list
|
A list of optimal parameters for each channel obtained from curve_fit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the pre-irradiation pixel value (PV_before) is not defined. |
Source code in app/calibration/calibration.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
compute_channel_independent_values(channel=0)
Computes the independent variable (e.g., netOD or netT) for each dose using the global pre-irradiation pixel value (PV_before).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
int
|
The channel index for which to compute the independent variable (default is 0). |
0
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary mapping dose values to the computed independent variable. |
Source code in app/calibration/calibration.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
compute_dose_map(film_file, channel=0, new_size=512)
Loads an irradiated film from a .tif file and computes the dose map using the calibrated model and the single-channel method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
film_file
|
str
|
Path to the .tif file that contains the irradiated film. |
required |
channel
|
int
|
The channel of the image to be used for calculating the dose map (default is 0). |
0
|
new_size
|
int
|
A new size for resizing the image (not used in the current implementation). |
512
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A 2D array representing the calculated dose map for the film. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the global pre-irradiation pixel value (PV_before) for the specified channel is not defined or if the independent variable used is not supported. |
Source code in app/calibration/calibration.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
from_json(filename)
classmethod
Loads a FilmCalibration instance from a JSON file. The JSON must contain the keys: - groundtruth_image - bits_per_channel - calibration_type - filter_type - dose_to_independent_by_channel - parameters - uncertainties - fitting_func_name Note: The doses, pre-irradiation pixel values (pixel_values_before), and the fitting function instance are not stored; the fitting function instance is re-initialized using the fitting_func_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the JSON file to load. |
required |
Returns:
| Type | Description |
|---|---|
FilmCalibration
|
The reconstructed FilmCalibration instance. |
Source code in app/calibration/calibration.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
get_metric(metric_name, channel=None)
Computes a specified metric for the calibration curve(s) and returns a tuple containing the metric value and its formatted name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_name
|
str
|
The metric to compute. Options are: - 'r2' or 'r^2' for the coefficient of determination, - 'rmse' for the root mean square error, - 'mse' for the mean square error, - 'chi2', 'chi-squared', or 'chi^2' for the chi-squared value. |
required |
channel
|
int
|
The channel index for which to compute the metric. If None, returns a dictionary mapping each channel index to a (value, formatted name) tuple. |
None
|
Returns:
| Type | Description |
|---|---|
tuple or dict
|
A tuple (metric_value, formatted_metric_name) if a channel is specified, otherwise a dictionary mapping channel indices to such tuples. |
Source code in app/calibration/calibration.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
get_rois_by_dose()
Prints out the ROIs for each registered dose.
Source code in app/calibration/calibration.py
104 105 106 107 108 109 110 111 | |
get_total_dose_count()
Returns the total number of doses registered in the calibration.
Returns:
| Type | Description |
|---|---|
int
|
Total number of doses. |
Source code in app/calibration/calibration.py
92 93 94 95 96 97 98 99 100 101 102 | |
get_total_roi_count()
Returns the total number of ROIs registered across all doses.
Returns:
| Type | Description |
|---|---|
int
|
Total number of ROIs. |
Source code in app/calibration/calibration.py
80 81 82 83 84 85 86 87 88 89 90 | |
graph_calibration_curve(metric_name='r2')
Graphs the calibration curves for each channel. The x-axis represents the independent variable (e.g., netOD or netT) and the y-axis represents the dose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_name
|
str
|
The metric to display on the curve legend (default is 'r2'). |
'r2'
|
Source code in app/calibration/calibration.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
graph_response_curve(metric_name='r2')
Graphs the response curves for each channel. The x-axis corresponds to the dose (Gy) and the y-axis corresponds to the film response (e.g., netOD or netT), which is the independent variable.
For each channel, this method numerically inverts the calibration function (which returns the dose for a given response) to obtain the independent variable for a range of doses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_name
|
str
|
The metric to display on the curve legend (default is 'r2'). |
'r2'
|
Source code in app/calibration/calibration.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
to_json(filename)
Exports the FilmCalibration instance to a JSON file. Only the following attributes are saved: - groundtruth_image (converted to list) - bits_per_channel - calibration_type - filter_type - pixel_values_before - dose_to_independent_by_channel - parameters (converted to lists) - uncertainties (converted to lists) - fitting_func_name Note: The doses, pre-irradiation pixel values (pixel_values_before), and the fitting function instance are not saved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the JSON file where the instance will be saved. |
required |
Source code in app/calibration/calibration.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
CalibrationDose
Source code in app/calibration/dose.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
__init__(dose_value, calibration=None)
Initializes an instance for a specific dose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dose_value
|
float
|
Dose value (in Gy). |
required |
calibration
|
FilmCalibration
|
The FilmCalibration instance that this dose is part of. |
None
|
Source code in app/calibration/dose.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
add_roi(x, y, width, height)
Adds a square region of interest (ROI) associated with this dose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X-coordinate (top-left corner) of the ROI. |
required |
y
|
int
|
Y-coordinate (top-left corner) of the ROI. |
required |
size
|
int
|
The side length of the square ROI. |
required |
Source code in app/calibration/dose.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
compute_average_pv(channel=0)
Computes the average post-exposure pixel value (PV_after) for all ROIs associated with this dose. It applies a median filter on the specified channel of the ground truth image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
int
|
The image channel to process (default is 0). |
0
|
Returns:
| Type | Description |
|---|---|
float
|
The computed average pixel value for the specified channel or None if no ROI exists. |
Source code in app/calibration/dose.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
compute_independent_value(pixel_values_before, channel)
Computes the independent variable for this dose based on the pre-exposure pixel value (PV_before) and the average post-exposure pixel value (PV_after). The type of independent variable (e.g., netOD or netT) is determined by the configuration of the calibration function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_values_before
|
dict
|
A dictionary mapping each channel to its pre-exposure pixel value. |
required |
channel
|
int
|
The image channel to use for the calculation. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The computed independent variable value for this dose on the specified channel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the average post-exposure pixel value for the given channel has not been computed. |
Source code in app/calibration/dose.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get_roi_count()
Returns the number of regions of interest (ROIs) registered for this dose.
Returns:
| Type | Description |
|---|---|
int
|
The number of ROIs. |
Source code in app/calibration/dose.py
115 116 117 118 119 120 121 122 123 124 | |
functions.py
This module defines a FittingFunction class that encapsulates a fitting function, its name, descriptive text, the names of its fitting parameters, and the possible types of independent variables ("x") that can be used (e.g., netOD, netT, reflectance).
FittingFunction
Source code in app/calibration/functions.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
__init__(name, func, initial_param_guess, description, param_names, independent_variable)
Initializes a FittingFunction instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the fitting function. |
required |
func
|
callable
|
The fitting function. The independent variable (x) should be its first argument. |
required |
initial_param_guess
|
list
|
A list of initial parameter guesses for the function. |
required |
description
|
str
|
A descriptive text (e.g., a LaTeX string) representing the fitting function. |
required |
param_names
|
list
|
A list of fitting parameter names (e.g., ["a", "b", "n"]). |
required |
independent_variable
|
str
|
The independent variable of the function (e.g., "netOD", "netT"). |
required |
Source code in app/calibration/functions.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
cuadratic(x, a, b, c)
Quadratic fitting function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float or array - like
|
The independent variable (e.g., netOD). |
required |
a
|
float
|
Fitting parameters. |
required |
b
|
float
|
Fitting parameters. |
required |
c
|
float
|
Fitting parameters. |
required |
Returns:
| Type | Description |
|---|---|
float or array - like
|
Calculated dose. |
Source code in app/calibration/functions.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
get_fitting_function(name)
Retrieves the FittingFunction instance by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the fitting function (e.g., "polynomial"). |
required |
Returns:
| Type | Description |
|---|---|
FittingFunction
|
The corresponding FittingFunction instance if found; otherwise, None. |
Source code in app/calibration/functions.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
polynomial(x, a, b, n)
Polynomial fitting function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float or array - like
|
The independent variable (e.g., netOD). |
required |
a
|
float
|
Fitting parameters. |
required |
b
|
float
|
Fitting parameters. |
required |
n
|
float
|
Fitting parameters. |
required |
Returns:
| Type | Description |
|---|---|
float or array - like
|
Calculated dose. |
Source code in app/calibration/functions.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
rational(x, a, b)
Rational fitting function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float or array - like
|
The independent variable (e.g., netOD). |
required |
a
|
float
|
Fitting parameters. |
required |
b
|
float
|
Fitting parameters. |
required |
Returns:
| Type | Description |
|---|---|
float or array - like
|
Calculated dose. |
Source code in app/calibration/functions.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
image_processing.py
This module provides functions for processing images, including reading TIFF and DICOM images, applying filters, displaying images, cropping regions of interest (ROIs), and performing template matching.
crop_square_roi(image, x, y, side_length)
Crops a square region of interest (ROI) from the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input image as a NumPy array. |
required |
x
|
int
|
X-coordinate (column) of the top-left corner of the ROI. |
required |
y
|
int
|
Y-coordinate (row) of the top-left corner of the ROI. |
required |
side_length
|
int
|
Length of one side of the square ROI. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The cropped ROI as a NumPy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the ROI exceeds the image boundaries. |
Source code in app/calibration/image_processing.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
filter_image(image, filter_type=None, kernel_size=3)
Applies a filtering or preprocessing operation to the provided image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input image data (grayscale). |
required |
filter_type
|
str
|
Type of filter to apply. Possible values include: "none", "gaussian", "median", "sobel", etc. This function currently demonstrates placeholder options. |
None
|
kernel_size
|
int
|
The size of the filter kernel. |
3
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The filtered image as a NumPy array. |
Source code in app/calibration/image_processing.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
get_real_dimensions(image_path)
Calculates the physical dimensions (in centimeters) of an image from its metadata. Supports TIFF and DICOM image formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
Path to the image file. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
(width_cm, height_cm) - the width and height in centimeters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required metadata is missing or the format is unsupported. |
Source code in app/calibration/image_processing.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
read_image(image_path)
Reads an image from the specified file path using skimage.io. For TIFF images, a custom reader is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
Path to the image file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
image |
ndarray
|
The loaded image as a NumPy array. |
Source code in app/calibration/image_processing.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
read_image_tif(image_path)
Reads a TIFF image from the specified file path using tifffile. Normalizes the image to the range [0, 1] based on its bit depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
Path to the TIFF image file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
image |
ndarray
|
The loaded and normalized image as a NumPy array. |
Source code in app/calibration/image_processing.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
reflect_image(image, mode='horizontal')
Reflects (flips) an image along the specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
The input image as a NumPy array. |
required |
mode
|
str
|
'horizontal' to flip left to right, 'vertical' to flip top to bottom. |
'horizontal'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The reflected image. |
Source code in app/calibration/image_processing.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
rotate_image(image, times=1, direction='clockwise')
Rotates an image by 90-degree increments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
NumPy array representing the image. |
required |
times
|
int
|
Number of 90° rotations (e.g., 1 for 90°, 2 for 180°, etc.). |
1
|
direction
|
str
|
'clockwise' for clockwise rotation, or 'counterclockwise' for counterclockwise rotation. |
'clockwise'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The rotated image. |
Source code in app/calibration/image_processing.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
save_image(image, output_path)
Saves an image (NumPy array) to the specified file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
NumPy array representing the image to be saved. |
required |
output_path
|
str
|
Full path of the output file (including the file format, e.g., .tiff or .png). |
required |
Source code in app/calibration/image_processing.py
137 138 139 140 141 142 143 144 145 146 147 148 | |
show_image(image, title=None, show_labels=True, show_axis=True)
Displays the provided image along with an optional coordinate system to facilitate region of interest (ROI) selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
The image to display. |
required |
title
|
str
|
Title for the displayed image. |
None
|
show_labels
|
bool
|
If True, display axis labels. |
True
|
show_axis
|
bool
|
If True, display the axis. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
image |
ndarray
|
The same image that was displayed. |
Source code in app/calibration/image_processing.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
template_matching(TPS_map_path, film_tif_path, output_path, verbose=False)
Performs template matching between a dose map (TPS map) from a DICOM file and an original film TIFF image. The function aligns the images using template matching, crops the matching region, applies transformations to standardize orientation, and saves the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
TPS_map_path
|
str
|
File path to the TPS map DICOM file. |
required |
film_tif_path
|
str
|
File path to the original film TIFF image. |
required |
output_path
|
str
|
File path where the processed (cropped and transformed) image will be saved. |
required |
Source code in app/calibration/image_processing.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
tif_bits_per_channel(image_path)
Retrieves the number of bits per channel for a TIFF image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
Path to the TIFF image. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of bits per channel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the BitsPerSample tag is not found or if its values are not identical. |
Source code in app/calibration/image_processing.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
Dose Analysis
display_dose_profile(path, x=None, y=None, save_fig=False)
Loads a dose map from a file (.npy or .dcm) and displays interactive profiles: - Dose map image with reference lines. - Horizontal (row) and vertical (column) profiles with interactive sliders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path to the dose map (.npy or .dcm). |
required |
x
|
array - like
|
Horizontal coordinates; if None, pixel indices are used. |
None
|
y
|
array - like
|
Vertical coordinates; if None, pixel indices are used. |
None
|
save_fig
|
bool
|
If True, saves the figure as a PNG file. |
False
|
Source code in app/dose_analysis/dose_profile.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
plot_isodose_map(path, save_fig=False)
Plots an isodose map from a given file and provides interactive sliders to adjust the contour levels and image opacity.
The input file can be either a DICOM (.dcm) file or a NumPy binary (.npy) file. In the case of a DICOM file, the function multiplies the pixel array by the DoseGridScaling attribute. The isodose levels are initially set at 30%, 60%, and 90% of the maximum dose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the dose map file (supported formats: .dcm or .npy). |
required |
save_fig
|
bool
|
If True, saves the resulting figure as a PNG file with a name based on the input file. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file format is not supported. |
Source code in app/dose_analysis/isodoses.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |