Question: Write efficient Python code, minimizing loops with vectorization where possible.the input image is 5 1 2 x 5 1 2 and the tiles are 3

Write efficient Python code, minimizing loops with vectorization where possible.the input image is 512x512 and the tiles are 32x32. Both are RGB images, so the input image will have the shape (512,512,3) and each tile will have the shape (32,32,3).do not normalize the tiles by dividing by 255. Keep the values as integers between 0 and 255.You can save the resulting nparray as an '.png' or '.jpg' image like this: Image.fromarray(result).save('out.png'). import numpy as np
import matplotlib.pyplot as plt
from sklearn.neighbors import KDTree
from PIL import Image
import urllib.request
from keras.datasets import cifar100 as tiles_dataset. tiles = tiles_dataset.load_data()[0][0]. First, compute the mean colors of all the tiles and construct a kd-tree.
Now generate 10 random colors and query the kd-tree for the nearest neighbours. For each of the 10 colors, imshow (in a horizontal row): the original color, the nearest mean color and the tile corresponding to the mean color. 2. Make a mosaic of the image based on that. 3. imshow the portion of your mosaic that corresponds to the top-left 8x8 tiles.
Write efficient Python code, minimizing loops

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!