A Python library to process images and YUV files.
Dependencies:
- numpy
- PIL
- scipy
This function is developed for training a deep neural network. It can extract a number of patches from a picture. In addtion, this function is a generator and can be used in a for loop.
img: an Image object (PIL.Image)
h: the height of a patch
w : the width of a patch
num: how many patches to extract
This function is developed for training a deep neural network. It extracts a number of patches from a picture and pack the patches into a ndarray object. This function calls get_random_pics to get random patches.
img: an Image object
h: the height of a patch
w: the width of a patch
num: how many patches to extract
return: a 4 dimension ndarray object: [num, w, h, 3]
This function is developed for training a deep neural network. It extracts (height / h) * (width / w) patches from a picture and these patches are not overlapped. In addtion, this function is a generator and can be used in a for loop.
img: an Image object (PIL.Image)
h: the height of a patch
w : the width of a patch
Extract an frame from a YUV file. This function returns an n by 3 matrix containing Y, U and V components.
filename: a string, like "capture.yuv"
height: the frame's height
width: the frame's width
frameId: the frame number to be extracted, starting from 1
Extract all the frames and their corrsponding frame ID in a YUV file. This function is a generator and therefore can be used in a for loop.
filename: a string, like "capture.yuv"
height: the frame's height
width: the frame's width
num_frames: how many frames in the YUV file
Convert YUV to RGB . The conversion formula can be found here.
yuv_frame: an n by 3 matrix containing Y, U and V seperately.
return: an n by 3 matrix containing R, G and B seperately.
Read frames from a yuv file and save the frame to image files
yuv_filename: the yuv file to convert
height, width: the height and the width of the yuv file
num_frames: how many frames of the yuv file to convert
format: such as "jpg", "bmp"
img_filename: a string used in image files
Draw a box on a YUV frame.
yuv_frame: a n by 3 matrix containing Y, U and V, seperately, or a (height, width, 3) matrix
color: "r", "g" or "b"
Compare two images and save the difference between these images into a new image file.
file1: the first image file to compare (string)
file2: the second image file to compare (string)
diff_file: where to save the difference (string)
Convert RGB to YUV. The conversion formula can be found here.
rgb_frame: an n by 3 matrix containing R, G, and B seperately.
return: an n by 3 matrix containing Y, U and V seperately.
Save a RGB frame to a file.
filename: The file name, like "test.bmp".
rgb: a n by 3 matrix containing R, G and B seperately.
2-d discrete cosine transform. This function can be found here.
a: 2-d ndarray object
2-d inverse discrete cosine transform. This function can be found here.
a: 2-d ndarray object