Trim images
- plot_utils.trim_img(files, white_margin=True, pad_width=20, pad_color='w', inplace=False, verbose=True, show_old_img=False, show_new_img=False, forcibly_overwrite=False, resize=False, resize_ratio=1.0)[source]
Trim the margins of image file(s) on the hard drive, and (optionally) add padded margins of a specified width and color.
- Parameters:
files (str or list<str> or tuple<str>) – A file name (as Python str) or several file names (as Python list or tuple) to be trimmed.
white_margin (bool) – Whether to treat white color as the margin to be trimmed. If
True
, white image margins will be trimmed. IfFalse
, black image margins will be trimmed.pad_width (float) – The amount of white margins to be padded (unit: pixels).
pad_color (str or tuple<float> or list<float>) – The color of the padded margin. Valid
pad_color
values are color names recognizable by matplotlib: https://matplotlib.org/tutorials/colors/colors.htmlinplace (bool) – Whether or not to replace the existing figure file with the trimmed content.
verbose (bool) – Whether or not to print the progress onto the console.
show_old_img (bool) – Whether or not to show the old figure in the console.
show_new_img (bool) – Whether or not to show the trimmed figure in the console.
forcibly_overwrite (bool) – Whether or not to overwrite an image on the hard drive with the same name. Only applicable when
inplace
isFalse
.resize (bool) – Whether to resize the padded image
resize_ratio (float) – The image resizing ratio. It has no effect if ``resize` is false. For example, if it’s 0.5, it means resizing to 50% of the original width and height.