Skip to content

Instantly share code, notes, and snippets.

@hirocarma
Created August 13, 2023 10:10
Show Gist options
  • Save hirocarma/e60d4ff72d82299b09153b038f16924e to your computer and use it in GitHub Desktop.
Save hirocarma/e60d4ff72d82299b09153b038f16924e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import sys
import cv2
import numpy as np
import colorsys
import matplotlib.pyplot as plt
import math
from scipy import stats
def Lab_plt(IMG_DIR, IMG_DIR2, p_title):
files = os.listdir(IMG_DIR)
files = sorted(files)
fps = 24
Ll=[];Lc=[]
for i, file in enumerate(files):
if not i % (fps / 8) == 0:
continue
img_path = IMG_DIR + '/' + file
img = cv2.imread(img_path)
lab_img = cv2.cvtColor(img, cv2.COLOR_BGR2Lab)
mean_l = int(np.mean(lab_img[:,:,0]))
mean_a = int(np.mean(lab_img[:,:,1]))
mean_b = int(np.mean(lab_img[:,:,2]))
mean_c = math.sqrt(mean_a**2+mean_b**2)
Ll.append(mean_l)
Lc.append(mean_c)
l_mean = np.mean(Ll)
c_mean = np.mean(Lc)
files = os.listdir(IMG_DIR2)
files = sorted(files)
fps = 24
Ll2=[];Lc2=[]
for i, file in enumerate(files):
if not i % (fps / 8) == 0:
continue
img_path = IMG_DIR2 + '/' + file
img = cv2.imread(img_path)
lab_img = cv2.cvtColor(img, cv2.COLOR_BGR2Lab)
mean_l = int(np.mean(lab_img[:,:,0]))
mean_a = int(np.mean(lab_img[:,:,1]))
mean_b = int(np.mean(lab_img[:,:,2]))
mean_c = math.sqrt(mean_a**2+mean_b**2)
Ll2.append(mean_l)
Lc2.append(mean_c)
l_mean2 = np.mean(Ll2)
c_mean2 = np.mean(Lc2)
p_fname =p_title
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['IPAPGothic', 'VL PGothic']
fig = plt.figure(figsize=(16, 8), dpi=100, facecolor='lightgray', tight_layout=True)
ax4 = fig.add_subplot(111, fc='w', xlabel='c*(彩度)', ylabel='L*(明度)')
ax4.set_title(p_title +" L*a*b* トーン:明度x彩度 比較")
ax4.scatter(Lc,Ll,c="blue",s=1,label="TV1期")
ax4.axhline(y=l_mean , color='aqua',linestyle='dashed', linewidth=1)
ax4.text(145, l_mean, "mean:" + str(round(l_mean,1)), ha='right', size=10)
ax4.axvline(x=c_mean , color='aqua',linestyle='dashed', linewidth=1)
ax4.text(c_mean, -4, "mean:" + str(round(c_mean,1)), ha='right', size=10)
ax4.scatter(Lc2,Ll2,c="red",s=1,label="アンコン編")
ax4.axhline(y=l_mean2 , color='magenta',linestyle='dashed', linewidth=1)
ax4.text(145, l_mean2, "mean:" + str(round(l_mean2,1)), ha='right', size=10)
ax4.axvline(x=c_mean2 , color='magenta',linestyle='dashed', linewidth=1)
ax4.text(c_mean2, -4, "mean:" + str(round(c_mean2,1)), ha='right', size=10)
ax4.set_xlim([140, 240])
ax4.set_ylim([-10, 255])
ax4.grid()
plt.legend(loc="upper left")
fig.savefig(p_fname +'-lab-tone-comp.png', facecolor=fig.get_facecolor())
plt.show()
if __name__ == '__main__':
IMG_DIR = sys.argv[1]
IMG_DIR2 = sys.argv[2]
p_title = sys.argv[3]
Lab_plt(IMG_DIR, IMG_DIR2, p_title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment