File size: 3,916 Bytes
9313bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71ff69f
9313bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71ff69f
 
 
9313bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71ff69f
 
 
9313bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71ff69f
 
 
9313bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71ff69f
 
 
9313bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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 + 25 + 10))
    ).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 + 25 + 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 + 475, top + 875, right - 280, bottom - (1810 + 25 + 10))
    )
    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 + 25 + 10))
    )
    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 + 25 + 10))
    )
    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")