From 0a66de78d027aa06858527cff200238280b5c3bc Mon Sep 17 00:00:00 2001
From: Vaek <timothe.boulet@student-cs.fr>
Date: Thu, 25 Mar 2021 10:40:29 +0100
Subject: [PATCH] add utils.py file

---
 loadFer2013ds.py | 15 ++++++++++-----
 utils.py         | 24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 5 deletions(-)
 create mode 100644 utils.py

diff --git a/loadFer2013ds.py b/loadFer2013ds.py
index e7aea37..6e4f76c 100644
--- a/loadFer2013ds.py
+++ b/loadFer2013ds.py
@@ -4,15 +4,18 @@ import numpy as np
 import cv2
 import matplotlib.pyplot as plt
 
-maxNbrImages = 484845
+
+nbrImages = 35887
+maxNbrImages = nbrImages
 emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
 
 def traitement(a,b,c):  #For testing
-	arr = strToArray(b)
-	print(a)
-	plt.imshow(arr)
-	plt.show()
 	pass
+	# arr = strToArray(b)
+	# print(a)
+	# plt.imshow(arr)
+	# plt.show()
+	# pass
 
 def strToArray(string):  #Fer2013 provides images as string so it needs to be transformed
 	A = []
@@ -61,5 +64,7 @@ with open(filename,'r',encoding='utf-8') as file:
 		X.append(strToArray(stringImage))
 		Y.append(emotionNbr)
 
+		print(f"Image {i} sur {nbrImages} chargée", end='\r')
+
 X = np.array(X)
 Y = np.array(Y)
\ No newline at end of file
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..6edd9d5
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,24 @@
+def afficher(image):
+  if len(image.shape) == 3:
+    if image.shape[2] == 3: # (h,l,3)
+      plt.imshow(image)
+    elif image.shape[2] == 1: # (h,l,1)->(h,l)
+      image2 = image
+      plt.imshow(tf.squeeze(image))
+  elif len(image.shape)== 2:  # (h,l)
+    plt.imshow(image)
+
+def predir():
+  pass
+
+def normAndResize(image):
+  #For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it.
+
+  image = cv2.resize(image, dsize=(h,l), interpolation=cv2.INTER_CUBIC) #resize for h and l                                       #
+  if len(image.shape) == 3 and p==1 and image.shape[2] != 1 : #if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image)
+    image = image.mean(2)
+  image = np.reshape(image, (h,l,p))                                    #restore third dimension
+  image = image.astype("float32")
+  image = image/255                                                     #normalisation
+
+  return image
\ No newline at end of file
-- 
GitLab