import json import os import pickle import random from glob import glob import matplotlib.pyplot as plt import pandas as pd import seaborn as sns import streamlit as st from PIL import Image @st.cache(allow_output_mutation=True, max_entries=10, ttl=3600) def load_query(image_path): image = Image.open(image_path) width, height = image.size new_width = width new_height = height left = (width - new_width) / 2 top = (height - new_height) / 2 right = (width + new_width) / 2 bottom = (height + new_height) / 2 # Crop the center of the image cropped_image = image.crop( (left + 5, top + 40, right - 2125, bottom - (2805)) ).resize((300, 300)) return cropped_image # CHM ############################################################################ @st.cache(allow_output_mutation=True, max_entries=10, ttl=3600) def load_chm_nns(image_path): image = Image.open(image_path) width, height = image.size new_width = width new_height = height left = (width - new_width) / 2 top = (height - new_height) / 2 right = (width + new_width) / 2 bottom = (height + new_height) / 2 # Crop the center of the image cropped_image = image.crop((left + 525, top + 2830, right - 0, bottom - (10))) return cropped_image @st.cache(allow_output_mutation=True, max_entries=10, ttl=3600) def load_chm_corrs(image_path): image = Image.open(image_path) width, height = image.size new_width = width new_height = height left = (width - new_width) / 2 top = (height - new_height) / 2 right = (width + new_width) / 2 bottom = (height + new_height) / 2 # Crop the center of the image cropped_image = image.crop((left + 15, top + 1835, right - 45, bottom - 445)) return cropped_image # CHM ############################################################################ # KNN ############################################################################ @st.cache(allow_output_mutation=True, max_entries=10, ttl=3600) def load_knn_nns(image_path): image = Image.open(image_path) width, height = image.size new_width = width new_height = height left = (width - new_width) / 2 top = (height - new_height) / 2 right = (width + new_width) / 2 bottom = (height + new_height) / 2 # Crop the center of the image cropped_image = image.crop((left + 525, top + 40, right - 10, bottom - (2805))) return cropped_image # KNN ############################################################################ # EMD ############################################################################ @st.cache(allow_output_mutation=True, max_entries=10, ttl=3600) def load_emd_nns(image_path): image = Image.open(image_path) width, height = image.size new_width = width new_height = height left = (width - new_width) / 2 top = (height - new_height) / 2 right = (width + new_width) / 2 bottom = (height + new_height) / 2 # Crop the center of the image cropped_image = image.crop((left + 525, top + 480, right - 5, bottom - (2365))) return cropped_image @st.cache(allow_output_mutation=True, max_entries=10, ttl=3600) def load_emd_corrs(image_path): image = Image.open(image_path) width, height = image.size new_width = width new_height = height left = (width - new_width) / 2 top = (height - new_height) / 2 right = (width + new_width) / 2 bottom = (height + new_height) / 2 # Crop the center of the image cropped_image = image.crop((left + 90, top + 880, right - 75, bottom - 1438)) return cropped_image # EMD ############################################################################ @st.cache() def convert_df(df): return df.to_csv().encode("utf-8")