[Detector] opencv displays the raw image of the detector

[Detector] opencv displays the raw image of the detector

1. Background

For detectors (as opposed to cameras that image visible light, detectors here refer to cameras that image X-rays).
RAW files are almost unprocessed information obtained directly from the CCD or CMOS.
The RAW format is a lossless format. Compared with the JPG format, the RAW format has many advantages. It will record all the details of the image, and you can modify these details according to the scene in the later stage.

Among them, the file in RAW format can be used as the input file for CT modeling of VG, but please note that the format of the file is uint16, that is, a single pixel can be expressed as 2*16-1 (65536) levels!

2. Code

The code is very simple, use numpy to read the raw file, arrange the data into a 3-dimensional array, and then display it with opencv.
The code example is as follows:

# -*- coding: utf-8 -*-
'''prompt:I only publish in csdn:jn10010537! 2023.06.28;'''
import cv2
import numpy as np

def read_raw_from_detector(raw_dir,rows=1536,cols=1536,channels = 1,dtype='uint16'):
    '''
    读取探测器拍摄的raw图像。
    本函数,默认是NDT0505J拍摄的raw图像。
    :param raw_dir:raw文件路径
    :param rows:行,即图像的像素高度;
    :param cols:列,即图像的像素宽度;
    :param channels:通道,默认是单通道。
    :param dtype:像素的数据类型,默认是uint16
    :return:None
    '''
    # 利用numpy的fromfile函数读取raw文件,注意指定正确的数据格式
    raw_data = np.fromfile(raw_dir, dtype=dtype)
    # 将1维数组转化为3维数组,reshape函数将读取到的数据进行重新排列。
    img_rgb = raw_data.reshape(rows, cols, channels)
    # cv2.WINDOW_NORMAL就是0,窗体可以自由变换大小
    cv2.namedWindow("raw_pic",0)
    # 指定窗体名称,以及要显示的numpy多维数组;
    cv2.imshow("raw_pic",img_rgb)
    cv2.waitKey()

if __name__ =="__main__":
    raw_dir=r"./ACap_1_184.00_1536X1536.raw"
    read_raw_from_detector(raw_dir)

Run as follows:
insert image description here

3. Download

ACap_1_184.00_1536X1536.raw download path is provided for your practice!
https://download.csdn.net/download/jn10010537/87955410

Guess you like

Origin blog.csdn.net/jn10010537/article/details/131427208