From 3e8b607b97cf48f7b018aea42b09256262afc9e2 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Fri, 26 Apr 2024 04:12:13 +0200 Subject: [PATCH] Add `analyze_bayer_filter_mean_denoiser.py` --- .../analyze_bayer_filter_mean_denoiser.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 datasets/raise/analyze_bayer_filter_mean_denoiser.py diff --git a/datasets/raise/analyze_bayer_filter_mean_denoiser.py b/datasets/raise/analyze_bayer_filter_mean_denoiser.py new file mode 100644 index 0000000..fba2548 --- /dev/null +++ b/datasets/raise/analyze_bayer_filter_mean_denoiser.py @@ -0,0 +1,44 @@ +import numpy as np +from utils import Color +import os +from tqdm import tqdm +import rawpy +import matplotlib.pyplot as plt + +''' +for color in Color: + #if color == 'green_bottom': + # continue + print(color) +''' + +os.chdir('flat-field/NEF') + +firstBayerFilterOccurrenceImages = [] + +for fileName in tqdm(os.listdir()): + with rawpy.imread(fileName) as raw: + colorDesc = raw.color_desc.decode('ascii') + assert colorDesc == 'RGBG' + assert np.array_equal(raw.raw_pattern, np.array([[0, 1], [3, 2]], dtype = np.uint8)) + # RG + # GB + firstBayerFilterOccurrenceImage = raw.raw_image_visible.copy()[:2, :2] + firstBayerFilterOccurrenceImages += [firstBayerFilterOccurrenceImage] + +firstBayerFilterOccurrenceImages = np.array(firstBayerFilterOccurrenceImages) +print(rawImageVisible) + +NUMBER_OF_COLORS = 3 +HEX_COLOR = '#' + '%02x' * NUMBER_OF_COLORS +COLOR_BASE = 256 + +def getColor(colorIndex): + return HEX_COLOR % tuple((255 if colorIndex == colorIndexTmp else 0) for colorIndexTmp in range(NUMBER_OF_COLORS)) + +#X, Y = np.histogram(firstBayerFilterOccurrenceImages[:,0,0]) +#plt.plot(X, Y) +for colorIndex, (colorY, colorX) in enumerate([(0, 0), (0, 1), (1, 1)]): + X = firstBayerFilterOccurrenceImages[:, colorY, colorX] - np.mean(firstBayerFilterOccurrenceImages, axis = 0)[colorY, colorX] + plt.hist(X, bins = len(set(X)), color = getColor(colorIndex), alpha = 0.3) +plt.show()