How to convert BMP format into DICOM format

Conversion from DICOM image to BMP image Tuesday, September 06, 2008 1 1:04 Abstract Objective To explore the conversion method from DICOM image to BMP image, so as to facilitate the reading, processing and storage of DICOM image. Methods Analyze the file formats of DICOM images and BMP images, read DICOM image data in BMP format, and display it in the window, vertically mirror and store it. Results This method realized the conversion from DICOM image to BMP image. Conclusion Most computers have no software to read DICOM images, and almost all computers can convert images into BMP images and read them.

Keywords DICOM;; BMP window display

Transformation from DICOM image to BMP image, Wang Shigang, Li Yueqing, Wang Changyuan (Taishan Medical College, Taian 27 1000)

Abstract: Objective: To explore the method of converting DICOM images into BMP images, so as to read, process and store DICOM images. Methods: The structures of DICOM images and BMP images were analyzed. Display window to read DICOM image data; The plumb mirror is converted and stored in BMP image format. Results: DICOM images were transformed into BMP images by this method. Conclusion: Most computers do not provide software that can read DICOM images, but almost any computer can read translated images in BMP format.

Keywords: DICOMBMP window display

The application of DICOM standard promotes the interoperability between medical imaging devices, provides an open data exchange standard for medical information, and makes it possible to archive and communicate images formed by imaging devices from different manufacturers. It accelerates the development of image archiving and communication system (PACS). However, most image processing software does not support DICOM image file format, so it is necessary to convert DICOM image file format, and BMP image file format is the most widely used image file format. Windows operating system has BMP image processing software-drawing. Therefore, it is very necessary to convert DICOM images into BMP images.

1 materials and methods

1. 1 material

Somatom Sensation16 CT DICOM image of Shengli Oilfield Central Hospital, Windows2000 operating system, Microsoft Visual C++ 6.0 programming software.

1.2 method

1.2. 1 DICOM file format DICOM images consist of a file header and at least one image data set. The DICOM file format is shown in Figure 1, and its file header is optional. The preamble is 128 bytes long and has no structure, so it cannot be encoded as a data element. It exists to provide the compatibility of some common computer file formats, and the description information of the file should be put in the preface, such as the file transmission format, the application program that generated the file and so on. When a file is cut into multiple parts (for example, when a file is stored on multiple disks), the file header can store information needed for random access to images. When the file header is not used, it should be set to all zeros, that is,100H of 28 bytes. The prefix is 4 bytes long and is the uppercase character "DICM". According to this value, it can be judged whether a file is a DICOM file [1 ~ 4].

Figure 1 DICOM file format

A data set is composed of data elements, which is an ordered collection of data elements. It includes not only medical image data, but also a lot of information related to medical images, such as patient's name, image size and so on. A data element consists of several fields: data element tag, value representation, VR), data value length and data value body.

Data element labels are 16-bit unsigned integer pairs arranged in sequence. The front is the group number of the data element, followed by the data element number. Data elements are uniquely identified by data element labels, and even array numbers are standard data elements, which are defined in the data dictionary of DICOM. For example, the research date is (0008,0020) and the pixel data is (7fe0,000 00 10/0). Data elements with odd group numbers are private data elements, which are defined by users themselves during use. However, DICOM standard also has detailed rules for user-defined data elements.

The expression of data value type is a 16-bit string, which represents the type of data in data elements and is encoded by DICOM default character set. For example, if the VR of a data element is DA, it means that the data stored in the data element is date data.

The length of the data value is 16 or 32-bit unsigned integer (depending on explicit or implicit VR), which indicates the exact length of the data value body and is recorded in bytes.

The data value body, with even bytes in length, stores the numerical value of the data element, and the data type of this field is determined by the VR of the data element.

1.2.2 BMP file format BMP file consists of four parts: bitmap file, bitmap information, color table or palette, and image data array. 〔5〕

BITMAPFILEHEADER contains information such as file type, file size and storage location. It is defined by the bitmap file header structure in Windows. The length of this structure is fixed, which is 14 bytes. Bitmap header BITMAPINFOHEADER is also a fixed-length structure, 40 bytes; ; The color palette is optional. If there is a palette, it is actually an array, and the corresponding relationship between array and color is established. This number is several elements of the color used in the bitmap. The type of each element in the array is an RGB quad structure, accounting for 4 bytes, which is defined as follows: blue component 1 byte, green component 1 byte, and red component 1 byte. Image data is located at the back of the palette. If there is no palette, it is after BITMAPINFOHEADER.

1.2.3 Different DICOM images with two image file formats are quite different from BMP images in file header and data structure. DICOM images not only have the necessary information of ordinary images such as image size, height, width and bytes per pixel, but also store a lot of medical information such as patient's name, age, hospital name, imaging time and examination site in the data elements of the data set.

The image data sets of the two images are also very different. DICOM images are stored sequentially. The first byte in the array represents the pixel in the upper left corner of the image, and the last byte represents the pixel in the lower right corner of the image. BMP images are stored from bottom to top, that is, the first byte in the array represents the pixel in the lower left corner of the image, and the last byte represents the pixel in the upper right corner of the image, so image conversion needs mirror transformation.

Read DICOM and BMP files, analyze and compare their image storage formats, program to read DICOM image file information, carry out mirror image transformation and window display technology, and write BMP files to realize image format conversion.

1.2.4 mirror image transformation is a means of medical image processing, which can be divided into horizontal mirror image transformation, vertical mirror image transformation and diagonal mirror image transformation. Horizontal mirror image switches column pixels with the vertical central axis of the image as the symmetry axis; Vertical mirror transformation switches pixels with the horizontal central axis of the image as the symmetry axis, while diagonal mirror transformation switches pixels with the diagonal axis of the image as the symmetry axis.

1.2.5 Window display technology The so-called window display is to linearly convert the image in the window area into the maximum display range of the display through a window, and set the image data above or below the upper and lower limits of the window as the highest or lowest display value respectively. In this way, by dynamically adjusting the window width (the range of image data to be displayed) and the window level (the central value of image data to be displayed), more information of medical images can be observed. 〔6〕

1.2.6 The flow chart of the image conversion program in the image conversion process is shown in Figure 2. In fig. 2, cb stands for the size of image file, DICOM stands for array, Rows stands for the number of image rows, Columns stands for the number of image columns, WC stands for the image window level, WW stands for the image window width, and PixData stands for the starting position of image data.

Bear fruit

The image format conversion results realized by the program are shown in Figure 3 and Figure 4.

Fig. 4 is an image converted from fig. 3. The functions realized by this program do not read information (such as name, gender, age, etc.). ) and scanning parameters (such as kV, mA, slice thickness, etc. ), but only the image data is obtained.

3 discussion

Because the number of bytes in each line of BMP image must be an integer multiple of 4, it needs to be filled during conversion; In addition, the data of BMP file is stored from bottom to top and from left to right, so pixels written with BMP need to be vertically mirrored.

In a BMP image, the blue, green and red bytes of the stored pixels are equal to form a black-and-white gray image, so when displaying a black-and-white gray image, these three bytes only contain 1 byte information, so the BMP image can only contain 256 gray levels; DICOM format image data can be stored as 8 bits, 12 bits, 16 bits or 24 bits. For 8-bit data, it can be directly filled into the BMP image according to the coordinate position. For the other three cases, it can be converted into an 8-bit BMP image by window display technology, or refilled to make the values of blue, green and red equal to form a 24-bit black and white gray image.

The somatom sensing16ct DICOM image of Shengli Oilfield Central Hospital occupies 2 bytes per pixel, and the effective information is 12Bits, that is, the black-and-white gray-scale image of 12Bits. Fig. 3 is an initial DICOM image with a size of 5 14K, and fig. 4 is a BMP image converted from fig. 3 with a size of 257K, which is half of the original image, because each pixel of the DICOM image occupies 2 bytes, while each pixel of the converted BMP image occupies 1 byte.

I found it online, but I didn't understand it. I hope it helps you. .