Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from PIL import Image, ImageEnhance
|
|
| 13 |
import numpy as np
|
| 14 |
import gspread
|
| 15 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 16 |
-
|
| 17 |
|
| 18 |
# -------------------------
|
| 19 |
# Global parameters
|
|
@@ -55,6 +55,24 @@ def match_brightness(source_img, target_img):
|
|
| 55 |
adjusted = enhancer.enhance(factor)
|
| 56 |
return adjusted
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# -------------------------
|
| 59 |
# Navigation via st.session_state
|
| 60 |
# -------------------------
|
|
@@ -176,7 +194,8 @@ if st.session_state.page == "evaluation":
|
|
| 176 |
img2 = Image.open(pair[1][1])
|
| 177 |
img2 = img2.convert("L")
|
| 178 |
|
| 179 |
-
img2 = match_brightness(img1, img2)
|
|
|
|
| 180 |
|
| 181 |
# Affichage dans deux colonnes avec radio buttons sous chacune
|
| 182 |
col1, col2 = st.columns(2)
|
|
|
|
| 13 |
import numpy as np
|
| 14 |
import gspread
|
| 15 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 16 |
+
from skimage.exposure import match_histograms
|
| 17 |
|
| 18 |
# -------------------------
|
| 19 |
# Global parameters
|
|
|
|
| 55 |
adjusted = enhancer.enhance(factor)
|
| 56 |
return adjusted
|
| 57 |
|
| 58 |
+
def match_histograms_pil(img_reference, img_to_adjust):
|
| 59 |
+
"""
|
| 60 |
+
Calque l'histogramme de `img_reference` sur `img_to_adjust`
|
| 61 |
+
(les deux images sont des objets PIL.Image).
|
| 62 |
+
Retourne une image PIL avec histogramme ajusté.
|
| 63 |
+
"""
|
| 64 |
+
# Convertir les deux images en tableaux numpy
|
| 65 |
+
ref_array = np.array(img_reference)
|
| 66 |
+
adj_array = np.array(img_to_adjust)
|
| 67 |
+
|
| 68 |
+
# Ajuster l'histogramme
|
| 69 |
+
matched = match_histograms(adj_array, ref_array, channel_axis=-1)
|
| 70 |
+
|
| 71 |
+
# Reconvertir en image PIL
|
| 72 |
+
matched_img = Image.fromarray(np.uint8(matched))
|
| 73 |
+
|
| 74 |
+
return matched_img
|
| 75 |
+
|
| 76 |
# -------------------------
|
| 77 |
# Navigation via st.session_state
|
| 78 |
# -------------------------
|
|
|
|
| 194 |
img2 = Image.open(pair[1][1])
|
| 195 |
img2 = img2.convert("L")
|
| 196 |
|
| 197 |
+
# img2 = match_brightness(img1, img2)
|
| 198 |
+
img2 = match_histograms_pil(img1, img2)
|
| 199 |
|
| 200 |
# Affichage dans deux colonnes avec radio buttons sous chacune
|
| 201 |
col1, col2 = st.columns(2)
|