Input Validation
Data-based
Quality (No-reference)
pymdma.image.measures.input_val.DOM
Computes DOM sharpness score for an image. It is effective in detecting motion-blur, de-focused images or inherent properties of imaging system.
Objective: Sharpness
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the edge filter. |
2
|
sharpness_threshold
|
int
|
Threshold for considering if a pixel is sharp or not. |
2
|
edge_threshold
|
float
|
Threshold for edge. |
0.0001
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Kumar et al., Sharpness estimation for document and scene images (2012). https://ieeexplore.ieee.org/document/6460868
Code was adapted from: pydom, Sharpness Estimation for Document and Scene Images. https://github.com/umang-singhal/pydom
Examples:
>>> dom = DOM()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = dom.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/dom.py
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 | |
pymdma.image.measures.input_val.Tenengrad
Computes Tenengrad score for an image. Sharpness measure based on the gradient magnitude.
Objective: Sharpness
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
Size of the Sobel kernel. |
3
|
threshold
|
int
|
Threshold for valid gradient pixels. Used to supress noise, smooth the curve and impose sensitivity. |
0
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Groen et al., A Comparison of Different Focus Functions for Use in Autofocus Algorithms (1984) https://onlinelibrary.wiley.com/doi/pdf/10.1002/cyto.990060202
More information on Tenengrad: Her et al., Research of Image Sharpness Assessment Algorithm for Autofocus (2019) https://ieeexplore.ieee.org/abstract/document/8980980
Examples:
>>> tenengrad = Tenengrad()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = tenengrad.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 | |
pymdma.image.measures.input_val.TenengradRelative
Computes Tenengrad score for an image in relation to a blurred instance of itself. Sharpness measure based on the gradient magnitude.
Objective: Sharpness
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
Size of the Sobel kernel. |
3
|
threshold
|
int
|
Threshold for valid gradient pixels. Used to supress noise, smooth the curve and impose sensitivity. |
0
|
criteria
|
str
|
Criteria for relative tenengrad score. Can be |
"ratio"
|
blur_factor
|
float
|
Degree of blurring to apply to the image. The lower the value, the more blurred the image. Must be in the range [0., 1.]. |
0.0
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Groen et al., A Comparison of Different Focus Functions for Use in Autofocus Algorithms (1984) https://onlinelibrary.wiley.com/doi/pdf/10.1002/cyto.990060202
More information on Tenengrad: Her et al., Research of Image Sharpness Assessment Algorithm for Autofocus (2019) https://ieeexplore.ieee.org/abstract/document/8980980
Examples:
>>> tenengrad = TenengradRelative()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = tenengrad.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 | |
pymdma.image.measures.input_val.EME
Computes the Measure of Enhancement (EME) score. Quantifies the enhancement of an image by measuring the contrast ratio of the image. Adapted from: https://www.researchgate.net/publication/244268659_A_New_Measure_of_Image_Enhancement
Objective: Contrast
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blocks_size
|
tuple of int
|
Size of the blocks to divide the image into. |
(100, 100)
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Agaian et al., A New Measure of Image Enhancement (2000). https://www.researchgate.net/publication/244268659_A_New_Measure_of_Image_Enhancement
Examples:
>>> eme = EME()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = eme.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 | |
pymdma.image.measures.input_val.ExposureBrightness
Computes Exposure and Brightness level Metric. Values higher than 1 indicate overexposure, while values closer to 0 indicate underexposure.
Objective: Exposure and Brightness
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
Examples:
>>> exposure_brightness = ExposureBrightness()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = exposure_brightness.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 | |
pymdma.image.measures.input_val.Brightness
Computes brightness level of an image.
Objective: Brightness
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Darel Rex Finley, HSP Color Model — Alternative to HSV (HSB) and HSL (2006). http://alienryderflex.com/hsp.html
Marian Stefanescu, Measuring and enhancing image quality attributes (2021). https://towardsdatascience.com/measuring-enhancing-image-quality-attributes-234b0f250e10
Examples:
>>> brightness = Brightness()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = brightness.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 | |
pymdma.image.measures.input_val.Colorfulness
Computes colorfulness level of an image.
Objective: Colorfulness
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Hasler et al., Measuring colourfulness in natural images (2003). https://infoscience.epfl.ch/server/api/core/bitstreams/77f5adab-e825-4995-92db-c9ff4cd8bf5a/content
Code was adapted from: Adrian Rosebrock, Computing image “colorfulness” with OpenCV and Python (2017). https://pyimagesearch.com/2017/06/05/computing-image-colorfulness-with-opencv-and-python/
Examples:
>>> colorfulness = Colorfulness()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = colorfulness.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 | |
pymdma.image.measures.input_val.CLIPIQA
Compute the CLIP-based IQA score. Wrapper of the PIQ CLIP-IQA metric. Evaluates perceptual quality of an image using a CLIP model.
Objective: General Image Quality
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_size
|
tuple of int, int
|
Size for each image. If a single integer is provided, the image will be thumbnail resized. In thumbnail resizing, the aspect ratio is maintained and batch calculation is not allowed (slower computation). |
tuple of int
|
interpolation
|
int
|
Interpolation method for resizing. |
cv2.INTER_LINEAR
|
data_range
|
float
|
The range of the data. By default, it is assumed to be [0, 255]. |
255
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Wang et al., Exploring CLIP for Assessing the Look and Feel of Images (2022). https://arxiv.org/abs/2207.12396
This is a wrapper class for the implementation in: piq, PyTorch Image Quality: Metrics for Image Quality Assessment. https://github.com/photosynthesis-team/piq
Examples:
>>> clip_iqa = CLIPIQA()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = clip_iqa.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
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 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
pymdma.image.measures.input_val.BRISQUE
Computes Blind/referenceless Image Spatial Quality Evaluator (BRISQUE) score. Wrapper of the PIQ BRISQUE metric implementation.
Objective: General Image Quality
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
The size of the Gaussian kernel. |
7
|
kernel_sigma
|
float
|
The standard deviation of the Gaussian kernel. |
7 / 6
|
data_range
|
float
|
The range of the data. By default, it is assumed to be [0, 255]. |
255
|
device
|
str
|
Device to run the computation. |
"cpu"
|
same_size
|
bool
|
If True, all provided images must have the same size (faster computation). |
False
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
Mittal et al., No-Reference Image Quality Assessment in the Spatial Domain (2012). https://live.ece.utexas.edu/publications/2012/TIP%20BRISQUE.pdf
This is a wrapper class for the implementation in: piq, PyTorch Image Quality: Metrics for Image Quality Assessment. https://github.com/photosynthesis-team/piq
Examples:
>>> brisque = BRISQUE()
>>> imgs = np.random.rand(20, 100, 100, 3) # (N, H, W, C)
>>> result: MetricResult = brisque.compute(imgs)
Source code in src/pymdma/image/measures/input_val/data/no_reference.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
Quality (Full-reference)
pymdma.image.measures.input_val.PSNR
Computes Peak Signal to Noise Ratio (PSNR) between two images.
Objective: Signal-to-noise ratio
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_range
|
int
|
Maximum value of the image data (e.g., 255 for 8-bit images). |
255
|
convert_to_grayscale
|
bool
|
Whether to convert the images to grayscale before computing PSNR. |
False
|
allow_nan
|
bool
|
Whether to allow NaN values in the returned scores. |
False
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility (unsused). |
{}
|
References
wikipedia.org: Peak signal-to-noise ratio https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
Examples:
>>> psnr = PSNR()
>>> reference_imgs = np.random.rand(20, 256, 256, 3) # (N, H, W, C)
>>> target_imgs = np.random.rand(20, 256, 256, 3) # (N, H, W, C)
>>> result: MetricResult = psnr.compute(reference_imgs, target_imgs)
Source code in src/pymdma/image/measures/input_val/data/psnr.py
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 | |
pymdma.image.measures.input_val.SSIM
Computes the Structural Similarity Index (SSIM) between two images. Wrapper of the PIQ SSIMLoss implementation.
Objective: Similarity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
The side-length of the sliding window used in comparison. Must be an odd value. |
11
|
sigma
|
float
|
Sigma of normal distribution. |
1.5
|
k1
|
float (default: 0.01)
|
Algorithm parameter, K1 (small constant). |
0.01
|
k2
|
float (default: 0.03)
|
Algorithm parameter, K2 (small constant). |
0.03
|
downsample
|
bool (default: False)
|
Whether to downsample the images to speed up the computation. |
False
|
data_range
|
int
|
Maximum value of the image data (e.g., 255 for 8-bit images). |
255
|
channel_last_dim
|
bool (default: True)
|
Indicates if the input images have the color channel as the last dimension. Needed for compatibility with torch operations. |
True
|
device
|
str
|
Device to use for computation. |
'cpu'
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility (unsused). |
{}
|
References
This class is a wrapper of the implementation from: piq, PyTorch Image Quality: Metrics and Measure for Image Quality Assessment, https://github.com/photosynthesis-team/piq
Examples:
>>> ssim = SSIM()
>>> reference_imgs = np.random.rand(20, 256, 256, 3) # (N, H, W, C)
>>> target_imgs = np.random.rand(20, 256, 256, 3) # (N, H, W, C)
>>> result: MetricResult = ssim.compute(reference_imgs, target_imgs)
Source code in src/pymdma/image/measures/input_val/data/ssim.py
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 | |
pymdma.image.measures.input_val.MSSSIM
Computes the Multiscale Structural Similarity Index (MSSSIM) between two images. Wrapper of the PIQ MultiScaleSSIMLoss implementation.
Objective: Similarity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
The side-length of the sliding window used in comparison. Must be an odd value. |
11
|
sigma
|
float
|
Sigma of normal distribution. |
1.5
|
k1
|
float (default: 0.01)
|
Algorithm parameter, K1 (small constant). |
0.01
|
k2
|
float (default: 0.03)
|
Algorithm parameter, K2 (small constant). |
0.03
|
scale_weights
|
list
|
Weights for different scales. |
None
|
data_range
|
int
|
Maximum value of the image data (e.g., 255 for 8-bit images). |
255
|
channel_last_dim
|
bool (default: True)
|
Indicates if the input images have the color channel as the last dimension. Needed for compatibility with torch operations. |
True
|
device
|
str
|
Device to use for computation. |
'cpu'
|
**kwargs
|
dict
|
Additional keyword arguments for compatibility. |
{}
|
References
This class is a wrapper of the implementation from: piq, PyTorch Image Quality: Metrics and Measure for Image Quality Assessment, https://github.com/photosynthesis-team/piq
Examples:
>>> mssim = MSSIM()
>>> reference_imgs = np.random.rand(20, 256, 256, 3) # (N, H, W, C)
>>> target_imgs = np.random.rand(20, 256, 256, 3) # (N, H, W, C)
>>> result: MetricResult = mssim.compute(reference_imgs, target_imgs)
Source code in src/pymdma/image/measures/input_val/data/ssim.py
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 | |