Image Filters API Reference
This section provides documentation for all image manipulation and filtering actions.
image_filters
A collection of image filtering and adjustment functions.
Provides various image manipulations including color inversion, grayscale conversion, contrast/brightness/saturation adjustments, blurring, sharpening, edge detection, color balance, hue rotation, posterization, borders, and rotation.
adjust_brightness(image, brightness)
Adjust the brightness of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
brightness
|
int
|
An integer from -100 to 100 representing the brightness level. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with adjusted brightness. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If brightness is not an integer. |
ValueError
|
If brightness is not between -100 and 100. |
Source code in src/image_converter/image_filters.py
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 | |
adjust_contrast(image, contrast)
Adjust the contrast of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
contrast
|
int
|
An integer from -100 to 100 representing the contrast level. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with adjusted contrast. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If contrast is not an integer. |
ValueError
|
If contrast is not between -100 and 100. |
Source code in src/image_converter/image_filters.py
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 | |
adjust_saturation(image, saturation)
Adjust the saturation of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
saturation
|
int
|
An integer from -100 to 100 representing the saturation level. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with adjusted saturation. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If saturation is not an integer. |
ValueError
|
If saturation is not between -100 and 100. |
Source code in src/image_converter/image_filters.py
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 | |
apply_blur(image, radius)
Apply Gaussian Blur to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
radius
|
int
|
The radius of the blur. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The blurred image. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If radius is not a number. |
ValueError
|
If radius is negative. |
Source code in src/image_converter/image_filters.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
apply_border(image, thickness, color_str, position='expand')
Add a solid color border to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
thickness
|
int
|
Thickness of the border in pixels. |
required |
color_str
|
str
|
Color in Hex or RGB format (e.g., '#FF0000', 'red', '255,0,0'). |
required |
position
|
str
|
'expand' to add border outside, 'inside' to overlay border. Defaults to "expand". |
'expand'
|
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: Image with border. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If color format is invalid, thickness is negative, thickness exceeds maximum allowed limit, expanded image size exceeds maximum allowed limit, or position is invalid. |
Source code in src/image_converter/image_filters.py
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 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | |
apply_color_balance(image, red_factor, green_factor, blue_factor)
Adjust the color balance of an image by scaling RGB channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
red_factor
|
float
|
Multiplier for the red channel. |
required |
green_factor
|
float
|
Multiplier for the green channel. |
required |
blue_factor
|
float
|
Multiplier for the blue channel. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The color-balanced image. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If color balance factors are not numbers. |
ValueError
|
If factors are infinite, NaN, or negative. |
Source code in src/image_converter/image_filters.py
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 | |
apply_posterize(image, bits)
Reduces the number of bits for each color channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
bits
|
int
|
The number of bits to keep (1-8). |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The posterized image. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If bits is not an integer. |
ValueError
|
If bits is not between 1 and 8. |
Source code in src/image_converter/image_filters.py
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 | |
apply_sharpen(image, sharpness)
Apply sharpening to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
sharpness
|
int
|
An integer from 0 to 100 representing intensity. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The sharpened image. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If sharpness is not an integer. |
ValueError
|
If sharpness is not between 0 and 100. |
Source code in src/image_converter/image_filters.py
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 | |
apply_vignette(image, intensity=50)
Apply a vignette effect to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
intensity
|
int
|
The intensity of the vignette effect (0-100). Defaults to 50. |
50
|
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with the vignette effect applied. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If intensity is not an integer. |
ValueError
|
If intensity is not between 0 and 100. |
Source code in src/image_converter/image_filters.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
edge_detection(image, method, threshold=50)
Apply edge detection to an image using one of three methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
method
|
str
|
The edge detection method ('sobel', 'canny', 'kovalevsky'). |
required |
threshold
|
int
|
The sensitivity threshold for the Kovalevsky method. Defaults to 50. |
50
|
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with edges detected. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If scikit-image or numpy is not installed. |
ValueError
|
If an invalid edge detection method is provided. |
Source code in src/image_converter/image_filters.py
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 | |
grayscale(image)
Convert an image to grayscale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The grayscale image. |
Source code in src/image_converter/image_filters.py
229 230 231 232 233 234 235 236 237 238 239 | |
invert_colors(image)
Inverts the colors of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with inverted colors. |
Source code in src/image_converter/image_filters.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
rotate_hue(image, degrees)
Rotates the hue of the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
degrees
|
int
|
The angle to rotate the hue (0-360). |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with rotated hue. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If degrees is not a number. |
Source code in src/image_converter/image_filters.py
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 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
rotate_image(image, angle)
Rotates the image by a given angle, clamped to 90-degree increments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input image. |
required |
angle
|
int
|
The angle to rotate (will be rounded to nearest 90). |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: Rotated image. |
Source code in src/image_converter/image_filters.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | |
flip_image
Functions for flipping images.
Provides a function to flip an image horizontally, vertically, or both.
flip_image(image_input, direction)
Flip an image horizontally, vertically, or both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_input
|
Image
|
The image to modify. |
required |
direction
|
str
|
The direction to flip the image. Can be 'horizontal', 'vertical', or 'both'. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The flipped image. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid direction is provided. |
Source code in src/image_converter/flip_image.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 | |
scale_image
Functions for scaling and resizing images.
Handles scaling by a factor or to a specific dimensions, supporting various resampling filters such as nearest, bilinear, bicubic, and lanczos.
scale_image(image_input, scale_factor=None, new_size=None, resample_filter='bilinear')
Scale an image up or down, preserving aspect ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_input
|
Image
|
The image to modify. |
required |
scale_factor
|
float
|
The factor to scale the image by. Defaults to None. |
None
|
new_size
|
tuple
|
The new size of the image as a tuple (width, height) to fit within. Defaults to None. |
None
|
resample_filter
|
str
|
The resampling filter to use. Defaults to "bilinear". |
'bilinear'
|
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The scaled image. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid resample filter is provided. |
Source code in src/image_converter/scale_image.py
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 | |
remove_background
Functions for removing backgrounds from images.
Provides functionality to remove image backgrounds using rembg
and trim empty space from the resulting image.
remove_background(image_input, opt_border_width=0)
Remove the background from an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_input
|
Image
|
The image to modify. |
required |
opt_border_width
|
int
|
The number of pixels to be added and later removed from the border. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The image with its background removed and trimmed. |
Source code in src/image_converter/remove_background.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
trim(image)
Trim empty background space from an image by finding its bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image to be trimmed. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The cropped image if a bounding box was found, otherwise the original image. |
Source code in src/image_converter/remove_background.py
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 | |