img_int = np.array( Image.open( "/Users/paix/Desktop/Python_lab/calibration/time_average/colorimg/CMOS_int8_1600_B.bmp" )) img_pyrometer = np.array( Image.open( "/Users/paix/Desktop/Python_lab/calibration/time_average/colorimg/1600_11.bmp" )) print(np.all(img_int == img_uint)) img_error = img_int - img_pyrometer ic(img_error.size) ic(np.count_nonzero(img_error)) error_rate = np.count_nonzero(img_error) / img_error.size * 100 ic(error_rate) temp_CMOS = tc.totemperature(img_int) temp_CMOS = np.where(temp_CMOS > 2200, 0, temp_CMOS) temp_CMOS = np.where(temp_CMOS < 1800, 0, temp_CMOS) temp_pyrometer = tc.totemperature(img_pyrometer) temp_pyrometer = np.where(temp_pyrometer > 2200, 0, temp_pyrometer) temp_pyrometer = np.where(temp_pyrometer < 1800, 0, temp_pyrometer) temp_error = temp_pyrometer - temp_CMOS ic(np.sum(temp_error)) # これ絶対値とる必要あるかも ic(np.count_nonzero(temp_CMOS)) ic(np.sum(temp_error) / np.count_nonzero(temp_CMOS)) ic(np.max(temp_error)) ic(np.min(temp_error)) # print(np.isclose(img_int, img_pyrometer))
print('laser power? 1400 / 1600 / 1800') 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')
width = 120 RGBmin = 20 RGBmax = 255 # pathの設定 total_frame_number = end_frame_number - begin_frame_number + 1 directory_name = "/Users/paix/Desktop/Python_lab/frame_data/20201123/10/twocolors/" base_name = directory_name + str(laser_power) + "_600/" + str( laser_power) + "0OUT" 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):
import twocolor_convert as tc from matplotlib import pyplot as plt import os # numpyの配列表示数の設定 np.set_printoptions(threshold=np.inf) if __name__ == '__main__': # レーザ出力とフレーム数の設定 # pathの設定 print("ヒストグラム表示したい画像のパスを入力") color_img_path = input() if os.path.exists(color_img_path): # if False: img_pil = Image.open(color_img_path) img_np = np.array(img_pil) h, w = img_np[:,:,0].shape ic(h) ic(w) temperature_ave = tc.totemperature(img_np) TEMP = temperature_ave# 1次元配列 TEMPplt = temperature_ave.reshape(h*w)# 2次元配列 # # 温度ヒストグラム表示 plt.hist(TEMPplt, color="red", bins=128) # plt.ylim(0, 200) plt.ylim(0, 2500) plt.xlim(1300, 3000) plt.xlabel("temperature") plt.show()
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
# for layer_number in ['1', '5', '11']: dir_name = "/Users/paix/Desktop/Python_lab/frame_data/20210610/temperature/" + laser_power + "_" + feed_rate + "_" + layer_number + "/" if os.path.exists(dir_name): files = os.listdir(dir_name) count = len(files) all_peak = np.array([]) all_temp = np.array([]) all_width = np.array([]) all_area = np.array([]) for file in sorted(glob.glob(dir_name + "*")): # ic(i) ic(file) # img = np.array(Image.open(dir_name + "/img_" + str(i) + ".bmp")) img = np.array(Image.open(file)) temperature_np = np.round(tc.totemperature(img), -1) all_peak = np.append(all_peak, temperature_np.max()) all_temp = np.append(all_temp, temperature_np.reshape(-1)) all_width = np.append( all_width, np.amax(np.sum(np.where(temperature_np > 20, 1, 0), axis=1))) all_area = np.append( all_area, np.sum(np.sum(np.where(temperature_np > 20, 1, 0), axis=1))) outliers = 3 #外れ値の指定(最初と最後の数フレームは外れ値になる) all_temp = all_temp[outliers * 90000:count - outliers * 90000] all_peak = all_peak[outliers:count - outliers] all_width = all_width[outliers:count - outliers] all_area = all_area[outliers:count - outliers] ic(all_temp.shape) ave = save_3D_hist(all_temp,