Python create random image
10 Python code examples are found related to "
create random image".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: unittest_utils.py From DOTA_models with Apache License 2.0 | 5 votes |
def create_random_image(image_format, shape): """Creates an image with random values. Args: image_format: An image format (PNG or JPEG). shape: A tuple with image shape (including channels). Returns: A tuple (<numpy ndarray>, <a string with encoded image>) """ image = np.random.randint(low=0, high=255, size=shape, dtype='uint8') io = StringIO.StringIO() image_pil = PILImage.fromarray(image) image_pil.save(io, image_format, subsampling=0, quality=100) return image, io.getvalue()
Example 2
Source File: utils.py From Facial-Recognition-Attendance-System with MIT License | 5 votes |
def create_save_random_image(file_path='result_image.png'): import numpy as np rgb = np.random.randint(255, size=(900, 800, 3), dtype=np.uint8) import cv2 cv2.imwrite(file_path, rgb) return file_path
Example 3
Source File: unittest_utils.py From models with Apache License 2.0 | 5 votes |
def create_random_image(image_format, shape): """Creates an image with random values. Args: image_format: An image format (PNG or JPEG). shape: A tuple with image shape (including channels). Returns: A tuple (<numpy ndarray>, <a string with encoded image>) """ image = np.random.randint(low=0, high=255, size=shape, dtype='uint8') fd = io.BytesIO() image_pil = PILImage.fromarray(image) image_pil.save(fd, image_format, subsampling=0, quality=100) return image, fd.getvalue()