# Image Vectorizing and PixPlot ### Image Vectorization: <hr> All compiled with a file on my github called `image_vectorizer.py`. Also on a viewable [google drive link](https://drive.google.com/file/d/10KHZY-C2KnanV0AqZdY5ybJTZCQeDXK6/view?usp=sharing). #### Significant parts of the file: ```python # For some reason, won't work without this. import ssl ssl._create_default_https_context = ssl._create_unverified_context ``` ```python # Helper method I used to parse the image file names. You might need to adjust this. def extract_page(elem: str): return int((elem.split('Res/')[1]).split('_')[0]) # Isolating ID. ``` ```python # Seting up our model from ImageNet base = InceptionV3(include_top=True, weights='imagenet') model = Model(inputs=base.input, outputs=base.get_layer('avg_pool').output) vecs = [] ``` ```python # We actually create the vectors for each image. for path in paths: # Extracting just the title from each png. # read the images img = Image.open(path) im = preprocess_input( img_to_array( img.resize((299,299)) ) ) vec = model.predict(np.expand_dims(im, 0)).squeeze() vecs.append(vec) ``` The rest of the code is a creating the matrices based on the `cosine_similarity` of the vectors. Some basic CSV parsing. As for the dataset, all the code will work off of [this folder](https://drive.google.com/drive/folders/1frm8oDNf3qvdirPNv-p50DPKDArXmAVd?usp=share_link) of lower-resolution images. I'm not sure why I didn't use the **higher quality** photos, as that could've helped with vectorizations (but, maybe slowed down `Pixplot`? I'm not sure). Regardless, here are the [higher res images](https://drive.google.com/drive/folders/10B4Dm9UDOhXl3jiVQZl8enK1TO3fnQfs?usp=sharing). ### Pixplot `Pixplot` can be compiled and then rerun just by starting a server. The compilation process is frustrating and annoying and uses a very old version of Python that **cannot be run on silicon Mac (M1, M2...)**. All of my efforts, including using a `x86-64 Rosetta` terminal didn't work - the hardware *fundamentally cannot* do it. Luckily I compiled it on an old computer! The [compiled zip](https://drive.google.com/file/d/1LGK_G2gW8REsWLvfX6QvIe506YmzX0s1/view?usp=sharing) just needs to be downloaded and decompressed. (Be sure to have `Python 3.7.0`) > Should you want to do this process again (that is, recompile everything with say, new images), there are some pretty bad instructions to follow [here](https://github.com/YaleDHLab/pix-plot). Once `Python` is on your computer, open a terminal, `cd` into the folder (where you open and decompress that folder), and then run `python3 -m http.server 5000` to start a server with it. The results will be viewable on [this website](http://localhost:5000/output). You should see your data laid out like this: ![](https://hackmd.io/_uploads/H1j7scwB2.png)