Image
- class image.Image(filename=None)[source]
Bases:
object
Constructor of the image object. If filename the load function loads the image file.
- Parameters
filename (str (default=None)) – Image filename
- property channels
Get the image number of channels
- crop(dsize, size)[source]
Crop the image according to the given dimensions [dsize[0] : dsize[0] + size[0], dsize[1] : dsize[1] + size[1]]
- Parameters
dsize (2D iterable) – (X, Y) of the crop
size (2D iterable) – (width, height) of the crop
- Returns
cropped – Cropped image
- Return type
- draw_detections(dets, thresh, names)[source]
Draw the detections into the current image
- Parameters
dets (Detection list) – List of pre-computed detection objects
thresh (float) – Probability threshold to filter the boxes
names (iterable) – List of object names as strings
- Return type
self
- flip(axis=- 1)[source]
Flip the image along given axis (0 - horizontal, 1 - vertical)
- Parameters
axis (int (default=0)) – Axis to flip
- Return type
self
- from_numpy_matrix(array)[source]
Use numpy array as the image
- Parameters
array (array_like) – buffer of the input image as (width, height, channel)
- Return type
self
- get()[source]
Return the data object as a numpy array
- Returns
data – Image data as numpy array
- Return type
array-like
- property height
Get the image height
- letterbox(net_dim)[source]
resize image with unchanged aspect ratio using padding
- Parameters
net_dim (2D iterable) – width and height outputs
- Returns
resized – Resized Image
- Return type
- load(filename)[source]
Read Image from file
- Parameters
filename (str) – Image filename path
- Return type
self
- mean_std_norm()[source]
Normalize the current image as
image = (image - mean) / variance
- Return type
self
- rescale(var, process=normalization.normalize)[source]
Divide or multiply by train variance-image
- Parameters
variances (array_like) – Array of variances to apply to the image
process (normalization (int)) – Switch between normalization and denormalization
- Return type
self
- resize(dsize=None, scale_factor=(None, None))[source]
Resize the image according to the new shape given
- Parameters
dsize (2D iterable (default=None)) – Destination size of the image
scale_factor (2D iterable (default=(None, None))) – width scale factor, height scale factor
- Returns
res – Resized Image
- Return type
Notes
Note
The resize is performed using the LANCZOS interpolation.
- rgb2rgba()[source]
Add alpha channel to the original image
- Return type
self
Notes
Note
Pay attention to the value of the alpha channel! OpenCV does not set its values to null but they are and empty (garbage) array.
- rotate(angle)[source]
Rotate the image according to the given angle in degree fmt.
- Parameters
angle (float) – Angle in degree fmt
- Returns
rotated – Rotated image
- Return type
Note
Note
This rotation preserves the original size so some original parts can be removed from the rotated image. See ‘rotate_bound’ for a conservative rotation.
References
https://www.pyimagesearch.com/2017/01/02/rotate-images-correctly-with-opencv-and-python/
- rotate_bound(angle)[source]
Rotate the image according to the given angle in degree fmt.
- Parameters
angle (float) – Angle in degree fmt
- Returns
rotated – Rotated image
- Return type
Note
Note
This rotation preserves the original image, so the output can be greater than the original size. See ‘rotate’ for a rotation which preserves the size.
References
https://www.pyimagesearch.com/2017/01/02/rotate-images-correctly-with-opencv-and-python/
- save(filename)[source]
save the image
- Parameters
filename (str) – Output filename of the image
- Return type
True if everything is ok
- scale(scaling, process=normalization.normalize)[source]
Scale image values
- Parameters
scale (float) – Scale factor to apply to the image
process (normalization (int, default = normalize)) – Switch between normalization (0) and denormalization (1)
- Return type
self
- scale_between(minimum, maximum)[source]
Rescale image value between min and max
- Parameters
minimum (float (default = 0.)) – Min value
maximum (float (default = 1.)) – Max value
- Return type
self
- property shape
Get the image dimensions
- show(window_name, ms=0, fullscreen=None)[source]
show the image
- Parameters
window_name (str) – Name of the plot
ms (int (default=0)) – Milliseconds to wait
- Returns
check – True if everything is ok
- Return type
bool
- standardize(means, process=normalization.normalize)[source]
Remove or add train mean-image from current image
- Parameters
means (array_like) – Array of means to apply to the image
process (normalization (int, default = normalize)) – Switch between normalization (0) and denormalization (1)
- Return type
self
- property width
Get the image width