From ec3ddd9c94ee1a7c6a6a2adbf52c576b91aa72eb Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 25 Apr 2024 12:37:21 +0200 Subject: [PATCH] Add `generate_histogram.py` --- datasets/raise/generate_histogram.py | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 datasets/raise/generate_histogram.py diff --git a/datasets/raise/generate_histogram.py b/datasets/raise/generate_histogram.py new file mode 100644 index 0000000..6704e6f --- /dev/null +++ b/datasets/raise/generate_histogram.py @@ -0,0 +1,44 @@ +import os +from PIL import Image +import matplotlib.pyplot as plot + +os.chdir('/home/benjamin/Desktop/bens_folder/school/ens/asp/aria/internship/work/datasets/raise/flat-field/TIF') + +image = Image.open('flat_001.tif') +image.histogram() + +HEX_COLOR = '#%02x%02x%02x' + +def getRed(redIntensity): + return HEX_COLOR % (redIntensity, 0, 0) + +def getGreen(greenIntensity): + return HEX_COLOR % (0, greenIntensity, 0) + +def getBlue(blueIntensity): + return HEX_COLOR % (0, 0, blueIntensity) + +def getColor(intensity, colorIndex): + return HEX_COLOR % tuple((intensity if colorIndex == colorIndexTmp else 0) for colorIndexTmp in range(3)) + +histogram = image.histogram() + +COLOR_BASE = 256 +red = histogram[0:COLOR_BASE] +green = histogram[COLOR_BASE:COLOR_BASE*2] +blue = histogram[COLOR_BASE*2:COLOR_BASE*3] + +#for colorIndex, color in [red, green, blue] +plt.figure(0) +for i in range(0, COLOR_BASE): + plt.bar(i, red[i], color = getColor(i, 0),alpha=0.3) + +plt.figure(1) +for i in range(0, COLOR_BASE): + plt.bar(i, green[i], color = getColor(i, 1),alpha=0.3) + +plt.figure(2) +for i in range(0, COLOR_BASE): + plt.bar(i, blue[i], color = getColor(i, 2),alpha=0.3) + +plt.show() \ No newline at end of file