From 5991e3a98c7dd759800e3822d32003d45741e1cb Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 21 Mar 2023 20:02:03 +0100 Subject: [PATCH] Testing --- main.py | 2 +- NumpyHDR.py => numpyHDR.py | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) rename NumpyHDR.py => numpyHDR.py (97%) diff --git a/main.py b/main.py index b0d2ae3..554b546 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,6 @@ import numpyHDR hdr = numpyHDR.NumpyHDR() liste = ['hdr/webcam20_3_2023_ev0.jpg','hdr/webcam20_3_2023_ev1.jpg','hdr/webcam20_3_2023_ev-2.jpg'] hdr.input_image = liste -hdr.output_path = 'hdr/fused_merten7' +hdr.output_path = 'hdr/fused_merten12' hdr.compress_quality = 75 hdr.sequence(0.8, 0.1) diff --git a/NumpyHDR.py b/numpyHDR.py similarity index 97% rename from NumpyHDR.py rename to numpyHDR.py index ce29098..5892cda 100644 --- a/NumpyHDR.py +++ b/numpyHDR.py @@ -1,5 +1,7 @@ -from PIL import Image import numpy as np +from PIL import Image + + #import matplotlib.pyplot as plt class NumpyHDR: @@ -131,10 +133,8 @@ class NumpyHDR: # Load the input images and convert them to floating-point format. images = [] for path in image_paths: - #print(path) - img = Image.open(path).convert('RGB') + img = Image.open(path) img = img.resize((1280, 720)) - img = np.array(img).astype(np.float32) / 255.0 img = np.power(img, gamma) images.append(img) @@ -143,7 +143,6 @@ class NumpyHDR: for img in images: gray = np.dot(img, [0.2989, 0.5870, 0.1140]) - #kernel = np.array([[-1, 1, -1], [1, 7, 1], [-1, 1, -1]]) kernel = np.array([[-1, -1, -1], [-1, 7, -1], [-1, -1, -1]]) laplacian = np.abs(self.convolve2d(gray, kernel)) weight = np.power(laplacian, contrast_weight) @@ -200,6 +199,22 @@ class NumpyHDR: return new_image return fused + def open_image(filename): + # Open the image file in binary mode + with open(filename, 'rb') as f: + # Read the binary data from the file + binary_data = f.read() + + # Convert the binary data to a 1D numpy array of uint8 type + image_array = np.frombuffer(binary_data, dtype=np.uint8) + + # Reshape the 1D array into a 2D array with the correct image shape + # (Assuming a 3-channel RGB image with shape (height, width)) + height = int.from_bytes(binary_data[16:20], byteorder='big') + width = int.from_bytes(binary_data[20:24], byteorder='big') + image_array = image_array[24:].reshape((height, width, 3)) + + return image_array def sequence(self, gain, weight): print(self.input_image)