tags: Medical image processing python dicom
The ultrasound data collected from the hospital is more chaotic because of the large time span, and the equipment difference is more chaotic. If you think about how to find these DICOM formatted files, then aiming at Pydicom. Chinese materials are also mixed, and they simply go to their official documents. The installation method is very simple in Anaconda Pip Install Pydicom
Reference:Pydicom official documentation
version: pydicom 2.0.0
Data readingdmread()
import pydicom
fpath='us13.DCM'
dcm=pydicom.dcmread(fpath)
Sometimes the following error may occur
raise InvalidDicomError("File is missing DICOM File Meta Information "
pydicom.errors.InvalidDicomError: File is missing DICOM File Meta Information header or the 'DICM' prefix is missing from the header. Use force=True to force reading.
This is due to the loss caused by information in the DICOM file or this file is not a DICOM file but contains DICOM data, and if it is confident that this file contains DICOM data, it should call the Force parameter to call the Force parameter to call the Force parameter according to the prompt.
dcm=pydicom.dcmread(fpath,force=True)
After completing the above DICOM file, you can print out the header file information using the Print instruction.
import pydicom
fpath='us13.DCM'
dcm=pydicom.dcmread(fpath)
print(dcm)
Some screenshot of the output

The simplest way can be usedsace_as()Save data
dcm.save_as('out.dcm')
By default,save_as()It is written in the file in the original way. This means that even if your data set does not meet the DICOM file format, it will still be strictly written in a given format. To determine that you are writing a data set in a DICOM file format, you can usewrite_like_originalKeyword parameters:
dcm.save_as('out.dcm', write_like_original=False)
The above operation will automatically add the missing header file information in the file. If it is not possible to successfully complete, it will report an error.
ValueError: Missing required File Meta Information elements from 'file_meta':
(0002, 0010) TransferSyntaxUID
At this time, you need to manually make relevant information, and save it.
dcm.file_meta = FileMetaDataset()
dcm.file_meta.TransferSyntaxUID = '1.2.840.10008.1.2.1'
dcm.save_as('out.dcm', write_like_original=False)
import pydicom
from matplotlib import pyplot as plt
fpath='US6.DCM'
dataset=pydicom.dcmread(fpath)
if 'PixelData' in dataset:
rows = int(dataset.Rows)
cols = int(dataset.Columns)
print("Image size.......: {rows:d} x {cols:d}, {size:d} bytes".format(
rows=rows, cols=cols, size=len(dataset.PixelData)))
if 'PixelSpacing' in dataset:
print("Pixel spacing....:", dataset.PixelSpacing)
plt.imshow(dataset.pixel_array, cmap=plt.cm.bone)
plt.show()
import SimpleITK as sitk import numpy as np import cv2 import os import time from PIL import Image count = 1 path = “dcm/201015” filename = os.listdir(path) print(filename) for i in filena...
1. Download python 2. Download pycharm 3. Configure the path of the .script file in the python directory to the system environment PATH, restart, and you can use the pip command 4. Install the pydicom...
1. Introduction to DICOM DICOM (Digital Imaging and Communications in Medicine): Medical imaging imaging and communications standards. All patient medical images are stored in DICOM file format. This ...
The current requirement is to divide the original DCM file into organ and then save the obtained image data as a new dcm file, and the new dcm file header should retain the basic information of the or...
Article catalog DICOM standard Image Save as DICOM file example Because the item needs, the picture needs to be stored as a DICOM format. There is no particularly good example on the Internet, and Pyd...
pydicom and SimpleITK respectively analyze dicom files in medical images First of all, both pydicom and SimpleITK are libraries that need to be imported into python in advance. If you are using pychar...
Python reads DICOM files and calls with Pydicom library Method 1: Read through Group, Element Method 2: Read through tag Method 3: Get () method Universal The following name is taken as an example. In...
1 Introduction In order to be able to edit Dicom images on Labelme, we have studied the reading of Dicom files under the python environment. The window width and window level of CT in Dicom images is ...
2019 Unicorn Enterprise Heavy Recruitment Standards for Python Engineers >>> background: As mentioned in the previous column, use CGI or FastCGI technology to forward user requests sent by th...