Read a DICOM dataset stored in accordance with the DICOM File Format
(DICOM Standard Part 10 Section 7). If the dataset is not stored in
accordance with the File Format (i.e. the preamble and prefix are missing,
there are missing required Type 1 File Meta Information Group elements
or the entire File Meta Information is missing) then you will have to
set force to True.

Parameters:

fp:str or file-like

Either a file-like object, or a string containing the file name. If a
file-like object, the caller is responsible for closing it.

defer_size:int or str or None

If None (default), all elements read into memory. If specified, then if
a data element’s stored value is larger than defer_size, the value is
not read into memory until it is accessed in code. Specify an integer
(bytes), or a string value with units, e.g. “512 KB”, “2 MB”.

stop_before_pixels:bool

If False (default), the full file will be read and parsed. Set True to
stop before reading (7FE0,0010) ‘Pixel Data’ (and all subsequent
elements).

force:bool

If False (default), raises an InvalidDicomError if the file is missing
the File Meta Information header. Set to True to force reading even if
no File Meta Information header is found.

specific_tags:list or None

If not None, only the tags in the list are returned. The list
elements can be tags or tag names. Note that the tag Specific
Character Set is always returned if present - this ensures correct
decoding of returned text values.

DICOM files can also be written using pydicom. There are two ways to do this.
The first is to use write_file with a prexisting FileDataset (derived from Dataset) instance.
The second is to use the save_as method on an Dataset instance.

If write_like_original is True then dataset will be written as is
(after minimal validation checking) and may or may not contain all or parts
of the File Meta Information (and hence may or may not be conformant with
the DICOM File Format).
If write_like_original is False, dataset will be stored in the DICOM
File Format in accordance with DICOM Standard Part 10 Section 7. The byte
stream of the dataset will be placed into the file after the DICOM File
Meta Information.

Saving a Dataset requires that the Dataset.is_implicit_VR and
Dataset.is_little_endian attributes exist and are set appropriately. If
Dataset.file_meta.TransferSyntaxUID is present then it should be set to
a consistent value to ensure conformance.

Parameters:

filename:str or file-like

Name of file or the file-like to write the new DICOM file to.

write_like_original:bool

If True (default), preserves the following information from
the Dataset (and may result in a non-conformant file):
- preamble – if the original file has no preamble then none will

be written.

file_meta – if the original file was missing any required File

Meta Information Group elements then they will not be added or
written.
If (0002,0000) ‘File Meta Information Group Length’ is present
then it may have its value updated.

seq.is_undefined_length – if original had delimiters, write them

now too, instead of the more sensible length characters

is_undefined_length_sequence_item – for datasets that belong to

a sequence, write the undefined length delimiters if that is
what the original had.

If False, produces a file conformant with the DICOM File Format,
with explicit lengths for all elements.