hyfi.graphics
COLLAGE
Source code in hyfi/graphics/collage.py
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 |
|
collage(images_or_uris, output_file=None, num_cols=3, num_images=12, collage_width=1200, padding=10, background_color='black', crop_to_min_size=False, show_filename=False, filename_offset=(5, 5), fontname=None, fontsize=12, fontcolor='#000', **kwargs)
staticmethod
Create a collage of images.
Source code in hyfi/graphics/collage.py
gallery_ndarray_images(array, ncols=7)
staticmethod
Create a gallery of images from a numpy array.
Source code in hyfi/graphics/collage.py
get_grid_of_images(images, num_cols=3, padding=10, background_color='black')
staticmethod
Create a grid of images.
Source code in hyfi/graphics/collage.py
label_collage(collage, collage_filepath=None, title=None, title_fontsize=10, xlabel=None, ylabel=None, xticklabels=None, yticklabels=None, xlabel_fontsize=12, ylabel_fontsize=12, dpi=100, fg_fontcolor='white', bg_color='black', caption=None, **kwargs)
staticmethod
Create a collage of images.
Source code in hyfi/graphics/collage.py
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 |
|
make_subplot_pages_from_images(images, num_images_per_page, num_cols, num_rows=None, output_dir=None, output_file_format='collage_p{page_num}.png', titles=None, title_fontsize=10, title_color='black', figsize=None, width_multiple=4, height_multiple=2, sharex=True, sharey=True, squeeze=True, dpi=100, verbose=False)
staticmethod
Make subplot pages from images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images
|
List[Union[str, Path, ndarray, Image]]
|
List of images to be plotted. |
required |
num_images_per_page
|
int
|
Number of images per page. |
required |
num_cols
|
int
|
Number of columns. |
required |
num_rows
|
Optional[int]
|
Number of rows. If None, it will be calculated automatically. |
None
|
output_dir
|
Optional[Union[str, Path]]
|
Output directory. |
None
|
output_file_format
|
str
|
Output file format. |
'collage_p{page_num}.png'
|
titles
|
Optional[List[str]]
|
List of titles for each image. |
None
|
title_fontsize
|
int
|
Title fontsize. |
10
|
title_color
|
str
|
Title color. |
'black'
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size. |
None
|
width_multiple
|
float
|
Width multiple. |
4
|
height_multiple
|
float
|
Height multiple. |
2
|
sharex
|
bool
|
Share x-axis. |
True
|
sharey
|
bool
|
Share y-axis. |
True
|
squeeze
|
bool
|
Squeeze. |
True
|
dpi
|
int
|
Dots per inch. |
100
|
Source code in hyfi/graphics/collage.py
make_subplots_from_images(images, num_cols, num_rows=None, output_file=None, titles=None, title_fontsize=10, title_color='black', figsize=None, width_multiple=4, height_multiple=2, sharex=True, sharey=True, squeeze=True, dpi=100, verbose=False)
staticmethod
Make subplots from images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images
|
List[Union[str, Path, ndarray, Image]]
|
List of images to be plotted. |
required |
num_cols
|
int
|
Number of columns. |
required |
num_rows
|
Optional[int]
|
Number of rows. If None, it will be calculated automatically. |
None
|
output_file
|
Optional[Union[str, Path]]
|
Output file path. |
None
|
titles
|
Optional[List[str]]
|
List of titles for each image. |
None
|
title_fontsize
|
int
|
Title fontsize. |
10
|
title_color
|
str
|
Title color. |
'black'
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size. |
None
|
sharex
|
bool
|
Share x-axis or not. |
True
|
sharey
|
bool
|
Share y-axis or not. |
True
|
squeeze
|
bool
|
Squeeze or not. |
True
|
dpi
|
int
|
Dots per inch. |
100
|
Source code in hyfi/graphics/collage.py
Collage
GUTILs
Image utils.
Source code in hyfi/graphics/utils.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 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 |
|
convert_figure_to_image(fig, dpi=300)
staticmethod
Convert a Matplotlib figure to a PIL Image and return it
Source code in hyfi/graphics/utils.py
find_font_file(query)
staticmethod
Find font file by query string
get_grid_size(num_images, num_cols=None, num_rows=None, truncate=True, fit_to_grid=True)
staticmethod
Get number of rows and columns for a grid of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_images
|
int
|
Number of images. |
required |
num_cols
|
int
|
Number of columns. Defaults to None. |
None
|
num_rows
|
int
|
Number of rows. Defaults to None. |
None
|
truncate
|
bool
|
Truncate number of images to fit grid. Defaults to True. If False, the number of images will be increased to fit the grid. |
True
|
Returns:
Type | Description |
---|---|
Tuple[int, int, int]
|
Tuple[int, int, int]: Number of images, columns and rows. |
Source code in hyfi/graphics/utils.py
get_image_font(fontname=None, fontsize=12)
staticmethod
Get font for PIL image.
Source code in hyfi/graphics/utils.py
get_plot_font(fontpath=None, fontname=None, lang='en', set_font_for_matplot=True, verbose=False)
staticmethod
Get font for plot
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fontpath
|
Optional[str]
|
Font file path |
None
|
fontname
|
Optional[str]
|
Font name |
None
|
lang
|
str
|
Language |
'en'
|
set_font_for_matplot
|
bool
|
Set font for matplot |
True
|
verbose
|
bool
|
Verbose mode |
False
|
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
Tuple of font name and font path |
Source code in hyfi/graphics/utils.py
get_ticks_from_lim(lim, num_ticks)
staticmethod
Get n evenly spaced ticks from lim.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lim
|
Tuple[float, float]
|
Tuple of (min, max) values. |
required |
num_ticks
|
int
|
Number of ticks to get. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Array of ticks. |
Source code in hyfi/graphics/utils.py
load_image(image_or_uri, max_width=None, max_height=None, max_pixels=None, scale=1.0, resize_to_multiple_of=None, crop_box=None, mode='RGB', **read_kwargs)
staticmethod
Load image from file or URI.
Source code in hyfi/graphics/utils.py
load_image_as_ndarray(image_or_uri)
staticmethod
load_images(images_or_uris, max_width=None, max_height=None, max_pixels=None, scale=1.0, resize_to_multiple_of=None, crop_to_min_size=False, mode='RGB', **kwargs)
staticmethod
Load images from files or URIs.
Source code in hyfi/graphics/utils.py
print_filename_on_image(image_or_uri, print_filename=False, filename=None, filename_offset=(5, 5), fontname=None, fontsize=12, fontcolor=None)
staticmethod
Convert an image to a PIL Image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_or_uri
|
The image or image URI. |
required | |
print_filename
|
bool
|
Whether to print the filename on the image. |
False
|
filename
|
Optional[str]
|
The filename to show on the image. |
None
|
filename_offset
|
Tuple[float, float]
|
The offset of the filename from the top left corner. |
(5, 5)
|
fontname
|
Optional[str]
|
The font name to use for the filename. |
None
|
fontsize
|
int
|
The font size to use for the filename. |
12
|
fontcolor
|
Optional[str]
|
The font color to use for the filename. |
None
|
Returns:
Type | Description |
---|---|
Image
|
The PIL Image. |
Source code in hyfi/graphics/utils.py
save_adjusted_subplots(fig, output_file, left=0.1, right=0.9, bottom=0.1, top=0.9, wspace=0, hspace=0, tight_layout=True, bbox_inches='tight', pad_inches=0, transparent=True, dpi=300, verbose=True)
staticmethod
Save subplots after adjusting the figure
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure |
required |
output_file
|
str
|
Output file path |
required |
left
|
float
|
Left |
0.1
|
right
|
float
|
Right |
0.9
|
bottom
|
float
|
Bottom |
0.1
|
top
|
float
|
Top |
0.9
|
wspace
|
float
|
Wspace |
0
|
hspace
|
float
|
Hspace |
0
|
tight_layout
|
bool
|
Tight layout |
True
|
bbox_inches
|
str
|
Bbox inches |
'tight'
|
pad_inches
|
float
|
Pad inches |
0
|
transparent
|
bool
|
Transparent |
True
|
dpi
|
int
|
DPI |
300
|
verbose
|
bool
|
Verbose mode |
True
|
Source code in hyfi/graphics/utils.py
scale_image(image, max_width=None, max_height=None, max_pixels=None, scale=1.0, resize_to_multiple_of=None, resample=Image.LANCZOS)
staticmethod
Scale image to have at most max_pixels
pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
PIL image. |
required |
max_width
|
Optional[int]
|
Maximum width. |
None
|
max_height
|
Optional[int]
|
Maximum height. |
None
|
max_pixels
|
Optional[int]
|
Maximum number of pixels. |
None
|
scale
|
float
|
Scale factor. |
1.0
|
resize_to_multiple_of
|
Optional[int]
|
Resize to multiple of this value. |
None
|
resample
|
int
|
Resampling filter. |
LANCZOS
|
Returns:
Type | Description |
---|---|
Image
|
PIL image. |
Source code in hyfi/graphics/utils.py
MOTION
Source code in hyfi/graphics/motion.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 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 |
|
create_video(input_image_dir, video_output_file, input_url, fps, start_number, vframes, force=False)
staticmethod
Create a video from a list of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_image_dir
|
str
|
Base directory. |
required |
video_path
|
str
|
Path to the video. |
required |
input_url
|
str
|
Input URL. |
required |
fps
|
int
|
Frames per second. |
required |
start_number
|
int
|
Start number. |
required |
vframes
|
int
|
Number of frames. |
required |
force
|
bool
|
Force video creation. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the video is not found. |
Source code in hyfi/graphics/motion.py
extract_frames(input_video_file, every_nth_frame, ouput_dir, frame_filename_pattern='%04d.jpg', ffmpeg_path='/usr/bin/ffmpeg')
staticmethod
Extract frames from a video.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_video_file
|
str
|
Path to the video. |
required |
every_nth_frame
|
int
|
Extract every nth frame. |
required |
ouput_dir
|
str
|
Path to the output directory. |
required |
frame_filename_pattern
|
str
|
Frame filename pattern. Defaults to "%04d.jpg". |
'%04d.jpg'
|
Source code in hyfi/graphics/motion.py
make_gif(image_filepaths=None, filename_patterns=None, base_dir=None, output_file=None, duration=100, loop=0, width=0, optimize=True, quality=50, display_to_notebook=False, force=False, **kwargs)
staticmethod
Create a GIF from a list of images or a list of filenames.