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 + 75, top + 145, right - 2025, bottom - 2915) ).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 + 475, top + 140, right - 280, bottom - 2920)) 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 + 475, top + 875, right - 280, bottom - 1810)) 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 + 475, top + 510, right - 280, bottom - 2550)) 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 + 10, top + 2075, right - 420, bottom - 925)) 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 + 10, top + 2500, right - 20, bottom)) return cropped_image # EMD ############################################################################ @st.cache() def convert_df(df): return df.to_csv().encode("utf-8")