如何应用对比度/直方图算法来清理原始灰度图像?
在使用“opencv-python”和传感器校准对实际数据进行一些处理后,我得到了原始 y16 格式的图像(将 3 个手指指向传感器前面)。我将图像仅作为阴影(如图像中所示),我试图使其像正常的原始灰度图像(红外图像)一样更加可见。有什么建议/解决方案可以提高图像质量以便看得更清楚吗?
实际帧数据为yuv2格式(16bit)
视频采集
视频设置为Y16(原始数据),convert_rgb->0,prop_format->-1
帧读取
对帧数据的一些操作
-框架重塑为行、列*2
-转为无符号整数(.astype(np.uint16)
-大端格式(位移位)
-查看为无符号整数(np.uint16)
frame_roi作物
应用中值模糊
frame_roi位移(以提高可见性)
应用归一化
应用 CLAHE
显示图像
import numpy as np
import cv2
cap = cv2.VideoCapture(0, cv2.CAP_MSMF)
cols, rows = 340, 240
cap.set(cv2.CAP_PROP_FRAME_WIDTH, cols)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, rows)
cap.set(cv2.CAP_PROP_FPS, 30)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('Y','1','6',' '))
cap.set(cv2.CAP_PROP_CONVERT_RGB, 0)
cap.set(cv2.CAP_PROP_FORMAT, -1)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
while(cap.isOpened()):
ret, frame = cap.read()
if not ret:
break
frame = frame.reshape(rows, cols*2)
frame = frame.astype(np.uint16)
frame = (frame[:, 0::2] << 8) + frame[:, 1::2]
frame = frame.view(np.uint16)
frame_roi = frame[:, 10:-10]
frame_roi = cv2.medianBlur(frame_roi, 3)
frame_roi = frame_roi << 3
normed = cv2.normalize(frame_roi, None, 0, 255, cv2.NORM_MINMAX,cv2.CV_8U)
cl1 = clahe.apply(normed)
cv2.imshow('preview',cl1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
//norm.png
I am getting this image as raw y16 format (pointing 3 fingers in front of sensor) after some processing on the actual data using 'opencv-python' and sensor calibration. I am getting the image as shadow only (as seen in image), I am trying to get it more visible like the normal raw grayscale image (IR image). Any suggestion/solution to improve the image quality to see it more better?
The actual frame data is in yuv2 format (16bit)
video capture
video set to Y16 (raw data), convert_rgb->0, prop_format->-1
frame read
some operation on frame data
-frame reshape to rows, cols*2
-to unsigned int (.astype(np.uint16)
-to big-endian format (bit shift)
-view as unsigned int (np.uint16)
frame_roi crop
applied medianBlur
frame_roi bit shift (to improve visiblity)
applied normalization
applied CLAHE
show image
import numpy as np
import cv2
cap = cv2.VideoCapture(0, cv2.CAP_MSMF)
cols, rows = 340, 240
cap.set(cv2.CAP_PROP_FRAME_WIDTH, cols)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, rows)
cap.set(cv2.CAP_PROP_FPS, 30)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('Y','1','6',' '))
cap.set(cv2.CAP_PROP_CONVERT_RGB, 0)
cap.set(cv2.CAP_PROP_FORMAT, -1)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
while(cap.isOpened()):
ret, frame = cap.read()
if not ret:
break
frame = frame.reshape(rows, cols*2)
frame = frame.astype(np.uint16)
frame = (frame[:, 0::2] << 8) + frame[:, 1::2]
frame = frame.view(np.uint16)
frame_roi = frame[:, 10:-10]
frame_roi = cv2.medianBlur(frame_roi, 3)
frame_roi = frame_roi << 3
normed = cv2.normalize(frame_roi, None, 0, 255, cv2.NORM_MINMAX,cv2.CV_8U)
cl1 = clahe.apply(normed)
cv2.imshow('preview',cl1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
//norm.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论