
"""
@Description : 完成图像的14bit-8bit线性映射
@Author : A1988
@Time : 2023/5/9 11:51 下午
@Site : https://www.zhihu.com/people/ylong1988
: https://blog.csdn.net/kongqiweiliang1
@File : func_autoagc.py
"""
import cv2
import os
import datetime
import numpy as np
import copy
from matplotlib import pyplot as plt
from PIL import Image
from datetime import datetime
from mpl_toolkits.mplot3d import Axes3D
import time
import datetime
import natsort
from func_autoagc import *
from common import *
def nothing1(*args):
pass
def nothing2(*args):
pass
def func_autoagc(agcimg, lower, upper):
max_ = np.percentile(agcimg, upper) # np.nanmax(agcimg)
min_ = np.percentile(agcimg, lower) # np.nanmin(agcimg)
dstagc = ((agcimg.clip(min_, max_) - min_) / (max_ - min_))
dstagc = (dstagc * 255).clip(0, 255).astype(np.uint8)
return dstagc
if __name__ == '__main__':
FILEPATH = "D:/PyCharm/myInfrared/images/01_nuc/T20231117_nuc/Mono14bit_Scene/"
FILENAME = "Pipe0_1280x1024_Raw16_1_1_1.raw"
cv2.namedWindow('myInfrared', cv2.WINDOW_KEEPRATIO)
cv2.createTrackbar('upper', 'myInfrared', 990, 1000, nothing1)
cv2.createTrackbar('lower', 'myInfrared', 50, 1000, nothing2)
while True:
uppervalue = cv2.getTrackbarPos('upper', 'myInfrared')
lowervalue = cv2.getTrackbarPos('lower', 'myInfrared')
srcimg = np.fromfile(FILEPATH + FILENAME, dtype=np.uint16).reshape(1024, 1280)
dstimg = func_autoagc(srcimg, lowervalue/100, uppervalue/10)
dstimg = func_histAddImg(dstimg)
current_date = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime())
cv2.putText(dstimg, "{}".format(FILENAME + ' ' + str(current_date)), (330, 30), cv2.FONT_HERSHEY_DUPLEX, 0.7, (255, 255, 255), 1)
cv2.imshow("myInfrared", dstimg)
cv2.waitKey(30)