utils
crop_to_ratio(image, ratio=1)
Reshapes an image to the specified ratio by cropping along the larger dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
Image
|
PIL.Image to crop. |
required |
ratio |
float
|
width to height ratio to which to crop the image. Use 1 to obtain a square image. |
1
|
Returns:
Type | Description |
---|---|
Image
|
Cropped PIL.Image. |
Source code in phomo/utils.py
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 |
|
open_img_file(img_file, crop_ratio=None, size=None, mode=None)
Open an image file with some extra bells and whistles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_file |
PathLike
|
path to the image. |
required |
crop_ratio |
Optional[float]
|
width to height to which to crop the image. |
None
|
size |
Optional[Tuple[int, int]]
|
resize image. |
None
|
mode |
Optional[str]
|
convert the image to the provided mode. See PIL image modes. |
None
|
Returns:
Type | Description |
---|---|
Image
|
Image instance. |
Source code in phomo/utils.py
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 |
|
rainbow_of_squares(target_dir, size=(10, 10), r_range=range(0, 256, 15), g_range=range(0, 256, 15), b_range=range(0, 256, 15))
Generate a bunch of solid-color tiles for experimentation and testing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_dir |
Path
|
direcotry in which to place the rainbow tiles. |
required |
size |
Tuple[int, int]
|
size of the images, width followed by height. |
(10, 10)
|
r_range_params |
Passed to |
required | |
g_range_params |
Passed to |
required | |
b_range_params |
Passed to |
required |
Source code in phomo/utils.py
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 |
|
resize_array(array, size, *args, **kwargs)
Resize an array representing and image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
ndarray
|
array containing the images data. |
required |
size |
Tuple[int, int]
|
desired size, width followed by height. |
required |
*args, |
**kwargs
|
passed to |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Array containing the resized image data. |
Source code in phomo/utils.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|