def main(): # Read and Demosaicing image filepath = "dataset/dragon.png" img_raw = cv2.imread(filepath, 0) img_demosaiced = pa.demosaicing(img_raw) # Calculate Stokes vector radians = np.array([0, np.pi/4, np.pi/2, np.pi*3/4]) img_stokes = pa.calcStokes(img_demosaiced, radians) # Convert Stokes vector to DoLP and AoLP img_DoLP = pa.cvtStokesToDoLP(img_stokes) # 0~1 img_AoLP = pa.cvtStokesToAoLP(img_stokes) # 0~pi name, ext = os.path.splitext(filepath) # Apply the HSV color map on the AoLP image img_AoLP_color = pa.applyColorToAoLP(img_AoLP) cv2.imwrite(name+"_AoLP"+".png", img_AoLP_color) # Set saturation to DoLP # As a result, the image is lighter and has color only at the polarized area img_AoLP_light = pa.applyColorToAoLP(img_AoLP, saturation=img_DoLP) cv2.imwrite(name+"_AoLP_saturation"+".png", img_AoLP_light) # Set value to DoLP # As a result, the image is darker and has color only at the polarized area img_AoLP_dark = pa.applyColorToAoLP(img_AoLP, value=img_DoLP) cv2.imwrite(name+"_AoLP_value"+".png", img_AoLP_dark)
def main(): # Read polarization image filepath = "dataset/dragon.png" img_raw = cv2.imread(filepath, -1) # Demosaicing img_demosaiced = pa.demosaicing(img_raw) img_0, img_45, img_90, img_135 = cv2.split(img_demosaiced) print("Export demosaicing images : {}".format(filepath)) name, ext = os.path.splitext(filepath) cv2.imwrite(name + "-0" + ext, img_0) cv2.imwrite(name + "-45" + ext, img_45) cv2.imwrite(name + "-90" + ext, img_90) cv2.imwrite(name + "-135" + ext, img_135)
def pol2color(image): img_demosaiced = pa.demosaicing(image) # Calculate the Stokes vector per-pixel angles = np.deg2rad([0, 45, 90, 135]) img_stokes = pa.calcStokes(img_demosaiced, angles) # Decompose the Stokes vector into its components img_S0, img_S1, img_S2 = cv2.split(img_stokes) # Convert the Stokes vector to Intensity, DoLP and AoLP img_intensity = pa.cvtStokesToIntensity(img_stokes) img_DoLP = pa.cvtStokesToDoLP(img_stokes) img_AoLP = pa.cvtStokesToAoLP(img_stokes) # https://github.com/elerac/polanalyser/wiki/How-to-Visualizing-the-AoLP-Image # img_AoLP_cmapped = pa.applyColorToAoLP(img_AoLP, value=img_DoLP) img_AoLP_cmapped = pa.applyColorToAoLP(img_AoLP, saturation=img_DoLP) return img_AoLP_cmapped
def main(): # Read image and demosaicing filepath = "dataset/dragon.png" img_raw = cv2.imread(filepath, 0) img_demosaiced = pa.demosaicing(img_raw) # Calculate the Stokes vector per-pixel radians = np.array([0, np.pi / 4, np.pi / 2, np.pi * 3 / 4]) img_stokes = pa.calcStokes(img_demosaiced, radians) # Decomposition into 3 components (S0, S1, S2) img_S0, img_S1, img_S2 = cv2.split(img_stokes) # Convert Stokes vector to meaningful values img_intensity = pa.cvtStokesToIntensity(img_stokes) img_Imax = pa.cvtStokesToImax(img_stokes) img_Imin = pa.cvtStokesToImin(img_stokes) img_DoLP = pa.cvtStokesToDoLP(img_stokes) # 0~1 img_AoLP = pa.cvtStokesToAoLP(img_stokes) # 0~pi # Normarize and save images name, ext = os.path.splitext(filepath) dtype_raw = img_raw.dtype img_intensity_norm = normarize(img_intensity, dtype_raw) cv2.imwrite(name + "_intensity" + ext, img_intensity_norm) img_Imax_norm = normarize(img_Imax, dtype_raw) cv2.imwrite(name + "_Imax" + ext, img_Imax_norm) img_Imin_norm = normarize(img_Imin, dtype_raw) cv2.imwrite(name + "_Imin" + ext, img_Imin_norm) img_DoLP_norm = normarize(img_DoLP * 255, np.uint8, gamma=1.0) cv2.imwrite(name + "_DoLP" + ".png", img_DoLP_norm) img_AoLP_color = pa.applyColorToAoLP(img_AoLP) # apply pseudo-color cv2.imwrite(name + "_AoLP" + ".png", img_AoLP_color)
# hist_HDR = plt.hist(img_HDR.ravel(), 256) # hist_HDR = plt.hist(np.log10(img_HDR.ravel()+1)) # plt.imshow(img_HDR) # plt.imshow(np.log10(img_HDR+1)) # plt.imshow(np.log10(np.float64(img_mid)+1)) hist_HDR = plt.hist(np.log10(img_HDR.ravel() + 1), 1000) plt.title('HDR image') plt.xlabel("log10 pixel byte values / s") plt.ylabel("Frequency") plt.savefig(os.path.dirname(imfile) + '/HDR_histogram.png') plt.close() """ ## Process for polarization """ img_demosaiced = pa.demosaicing(img_HDR) img_000, img_045, img_090, img_135 = cv2.split(img_demosaiced) plt.imshow(img_000) # Calculate the Stokes vector per-pixel radians = np.array([0, np.pi / 4, np.pi / 2, np.pi * 3 / 4]) img_stokes = pa.calcStokes(img_demosaiced, radians) plt.imshow(img_stokes) # Decompose the Stokes vector into its components img_S0, img_S1, img_S2 = cv2.split(img_stokes) # Convert the Stokes vector to Intensity, DoLP and AoLP
# pip install numba import numpy as np from matplotlib import pyplot as plt from matplotlib.pylab import cm import cv2 import polanalyser as pa from tkinter.filedialog import askopenfilename import os imfile = askopenfilename() img_raw = cv2.imread(imfile, 0) #0 means greyscale img_demosaiced = pa.demosaicing(img_raw) img_000, img_045, img_090, img_135 = cv2.split(img_demosaiced) plt.imshow(img_000) # Calculate the Stokes vector per-pixel radians = np.array([0, np.pi / 4, np.pi / 2, np.pi * 3 / 4]) img_stokes = pa.calcStokes(img_demosaiced, radians) plt.imshow(img_stokes) # Decompose the Stokes vector into its components img_S0, img_S1, img_S2 = cv2.split(img_stokes) # Convert the Stokes vector to Intensity, DoLP and AoLP