1.Introduction
- image dataset
I created a dataset where all the images are of Kobe Bryant.So I wrote a scrapy program to get all the images they had of Kobe Bryant.The website is https://www.gettyimages.com. And download all the images which are relevant to Kobe Bryant. Just like that
And here we are, the Kobe-Bryant dataset are all set!The link of this dataset: https://drive.google.com/file/d/188WvOJIYxa49OwJDMKoqDt34bmJ39m4P/view?usp=sharing
original image is:
- Photo Mosaics
a) Method I (k-d tree): First I tried to use k-d tree to query the fittest image from our dataset to stick to the image block,so I check how to use k-d tree, here is the reference:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.KDTree.html
First, I collect average color for the output image and the images in the database, then use k-d tree to query it, but then I found that first, when I just query them, this happened
Then I found that in the calculation of dominant color, there exists one expansion only contains white elements, so just cut this dimension. After that, I found that those images I got from my scrapy codes are various in format, so that when I tried to query those images, I found some dimension errors, so in the begining of my codes, I transformed those images into 'RGB' format, that's the normolization part. Next thing I do is to adjust the image, about the size and other things. For example, some pre-treatment are needed, like erase the noise etc..
b) Method II(Using distance): First I need to adjust the image, since I have done lots of work in method I, I may not need to adjust a lot in color, but in size. This time, I would not resize all the photo to a certain scale, instead, by using aspect ratio for each image in my dataset. I just chose the image which has similar ratio to our grid size, so that it could fit better! After I did the method I, I have found that the key is to find the closest color to a specific grid zone in the output image, so what I need to do is to first, get the size of the output image and the grid size, second, for each grid, calculate the average color for this grid. After i get those information, all I need to do is to find the closest one from my dataset, just traverse the dataset once to find that. When I finished all the process, just need to put those selected images into those grids one by one, then it could be done ! here is the main function:
Then I have found that the output image I found has a large black area(not pure black, but has some color in it), so that when I handle those areas, it has a large possibility that it will use the same image. So first, for those black images, I created a few filters to make them slight lighter or darker, and then apply them randomly. Next, in case that the situation still happens, I have created a list where if some images use more than certain specific times, the function will query the next closest one.
3)Output image
Method I:
Method II:
After finishing those, I found two problems, first, the background image has so many consistent color, like a big area of black or yellow, second, when I zoom in, I cannot see the images so clearly in each grid, and the last is that it may use one image so many times.
So in order to solve these, first I find a new image which has rich color in it:
and enrich my dataset by crawling more images.
Next, I create a function which use some packages in PIL.Image, to create a high resolution image, here is the function
after that, a new problem occurs, that is the limitation of max pixels, so I just change this limitation by this:
and next when I set the grid to be (40, 40), it turns out to be like this:
I cannot see the background image so clearly, so I just changed the size of the grid
but I find out that I used one image so many times, so I just changed my query function of searching the kd-tree by adding k into it, and create a list where it doesn't allow to use the same picture within a certain distance.
Finally, in order to see the image in each grid clearly, I used the resize function in our dataset.
After all those preparations are set, just run the program, it turns out to be like that
Note: I just find that the gettyimage might have some way to prevent big-scale crawling so that the resolution of images scale down.And it has a threhold when I want to increase the resolution.
Other work:
original:
Mosaics:
image_name:
I searched for lots of ways and implentment on my own