The function create_mosaic
takes 6 arguments:
- img: The Image you want to convert as a numpy array
- images_tuple: A tuple created by giving the
create_img_array
function the filepath of your (cat) images and the size you want them to be - resolution: How much the input image gets pixelated (Higher values result in a lower quality)
- cat_size: How big one (cat) image should be (Should be the same as in the
create_img_array
function for best results) - accuracy: Determines how random the images are (When set to 1 or lower gives an error for some reason) (Set to 2 for the most accurate image)
- saveto: The filepath you want to save the result to
import cv2
import cat_image_mosaic
cats_filepath = "./cat_images"
cat_images = cat_image_mosaic.create_img_array(images_filepath=cats_filepath, img_size=25)
im = cat_image_mosaic.read_image("input6.png") #You can also use cv2.imread() but you'll have to keep in mind that cv2.imread() reads the image in BGR by default, while the create_mosaic() function works with RGB
cat_image_mosaic.create_mosaic(img=im, images_tuple=cat_images, resolution=75, cat_size=25, accuracy=5, logs=True)
I used a public dataset with 9000 cat images for the example (https://www.kaggle.com/datasets/crawford/cat-dataset)
Input Image:
Output Image:
(The colors are reversed because I accidentaly used cv2.imread()
)