color_img_path = 'calibration/time_average/colorimg/' + str( laser_power) + "_" + str(total_frame_number) + ".bmp" if os.path.exists(color_img_path): # if False: img_pil = Image.open(color_img_path) img_np = np.array(img_pil) temperature_ave = tc.totemperature(img_np) TEMP = temperature_ave # 1次元配列 TEMPplt = temperature_ave.reshape(90 * 120) # 2次元配列 else: # 温度の時間平均算出開始 # 1枚目の溶融池画像を格納 img_pil = Image.open(base_name + str(begin_frame_number) + ".BMP") img_np = np.array(img_pil) rough_trimmed_img = tr.img_trimming(img_np, 220, 310, 640, 1279) x, y = gp.get_gravitypoint_img(rough_trimmed_img) trimmed_img = rough_trimmed_img[:, x - 60:x + 60] # 温度データに変換 ###### temperature_sum = tc.totemperature(trimmed_img) for frame_number in range(begin_frame_number + 1, end_frame_number + 1): # 1枚ずつ重心周りでトリミングしていく img_pil = Image.open(base_name + str(frame_number) + ".BMP") img_np = np.array(img_pil) rough_trimmed_img = tr.img_trimming(img_np, 220, 310, 640, 1279) x, y = gp.get_gravitypoint_img(rough_trimmed_img) # うまくいった trimmed_img = rough_trimmed_img[:, x - 60:x + 60] # 色データから温度データに変換 ###### temperature_np = tc.totemperature(trimmed_img)
laser_power = int(input()) frames = 100 RGBvalue = 0 height = 90 width = 120 RGBmin = 25 RGBmax = 255 # pathの設定 color_img_path = 'calibration/time_average/colorimg/20210421/' + str( laser_power) + "_101.bmp" if os.path.exists(color_img_path): img_pil = Image.open(color_img_path) pyro_np = np.array(img_pil) temperature_ave = tc.totemperature(pyro_np) pyro_x, pyro_y = gp.get_gravitypoint_img(pyro_np) pyro_temp_g = temperature_ave TEMP = temperature_ave # 次元配列 TEMPplt = temperature_ave.reshape(90 * 120) # 2次元配列 # # # 温度ヒストグラム表示 # plt.hist(TEMPplt, color="red", bins=128) # plt.ylim(0, 200) # plt.xlim(1300, 3000) # plt.xlabel("temperature") # plt.show() # print('after / before projection?') # afbf = input() afbf = 'after' # print('Average range') # average = int(input())
def timeAverage(laser_power, middle_frame_number, frames): """ 二色温度計画像を時間平均する Parameters ---------- laser_power : int レーザ出力 begin_frame_number : int 平均するフレームの開始点 end_frame_number : int 平均するフレームの終了点 Returns ------- TEMP : numpyの二次元配列 二色温度計の時間平均値 """ # pathの設定 total_frame_number = frames + 1 directory_name = "/Users/paix/Desktop/Python_lab/frame_data/20210706/pyrometer_short/" base_name = directory_name + str(laser_power) + "/" + str( laser_power) + "0OUT" os.makedirs('frame_data/20210706/colorimg/', exist_ok=True) color_img_path = 'frame_data/20210706/colorimg/' + str( laser_power) + "_" + str(total_frame_number) + ".bmp" if os.path.exists(color_img_path): # if False: img_pil = Image.open(color_img_path) img_np = np.array(img_pil) temperature_ave = tc.totemperature(img_np) TEMP = temperature_ave # 1次元配列 TEMPplt = temperature_ave.reshape(90 * 120) # 2次元配列 # # 温度ヒストグラム表示 # plt.hist(TEMPplt, color="red", bins=128) # plt.ylim(0, 200) # plt.xlim(1300, 3000) # plt.xlabel("temperature") # plt.show() else: # 温度の時間平均算出開始 # 1枚目の溶融池画像を格納 begin_frame_number = middle_frame_number - int(frames / 2) end_frame_number = middle_frame_number + int(frames / 2) img_pil = Image.open(base_name + str(begin_frame_number) + ".BMP") img_np = np.array(img_pil) rough_trimmed_img = tr.img_trimming(img_np, 240, 330, 640, 1279) x, y = gp.get_gravitypoint_img(rough_trimmed_img) trimmed_img = rough_trimmed_img[:, x - 60:x + 60] # 温度データに変換 ###### temperature_sum = tc.totemperature(trimmed_img) for frame_number in range(begin_frame_number + 1, end_frame_number + 1): ic(frame_number) # 1枚ずつ重心周りでトリミングしていく img_pil = Image.open(base_name + str(frame_number) + ".BMP") img_np = np.array(img_pil) rough_trimmed_img = tr.img_trimming(img_np, 240, 330, 640, 1279) x, y = gp.get_gravitypoint_img(rough_trimmed_img, False) # うまくいった # trimmed_img = rough_trimmed_img[ : , x - 60 : x + 60] trimmed_img = img_np[240 + y - 45:240 + y + 45, 640 + x - 60:640 + x + 60] # 色データから温度データに変換 ###### temperature_np = tc.totemperature(trimmed_img) temperature_sum += temperature_np total_frame_number = end_frame_number - begin_frame_number + 1 temperature_ave = temperature_sum / total_frame_number TEMP = temperature_ave # 1次元配列 TEMPplt = temperature_ave.reshape(90 * 120) # 2次元配列 # # 温度ヒストグラム表示 # plt.hist(TEMPplt, color="red", bins=128) # plt.ylim(0, 200) # plt.xlim(1300, 3000) # plt.show() ic(temperature_ave.shape) # # 温度データから色データに再変換 img_ave = tc.tocolor(temperature_ave) # 平均化した溶融池温度分布の色画像を表示 img_ave = np.array(img_ave, dtype=np.int8) pil_img = Image.fromarray(img_ave, mode="RGB") save_name = str(laser_power) + "_" + str(total_frame_number) + ".bmp" pil_img.save('frame_data/20210706/colorimg/' + save_name) # pil_img.save('calibration/time_average/colorimg/20210421/' + save_name) # 温度の時間平均算出終了 return TEMP