[Neuroimaging] Can it be used to make npy files from dcom?
Matthew Brett
matthew.brett at gmail.com
Wed Jul 22 05:16:00 EDT 2020
Hi,
On Wed, Jul 22, 2020 at 9:58 AM Bjarni J <bjarnijo90 at gmail.com> wrote:
>
> Hi can nibabel be used to create npy files from a dicom image? I have a bunch of dicom's that I want converted to numpy arrays but I can't seem to find a good solution.
>
Can you just use the pydicom package for this?
[ins] In [1]: import pydicom
[ins] In [2]: dcm = pydicom.read_file('1.dcm')
[ins] In [3]: arr = dcm.pixel_array
[ins] In [4]: arr
Out[4]:
array([[ 0, 1, 2, ..., 253, 254, 255],
[ 256, 257, 258, ..., 509, 510, 511],
[ 512, 513, 514, ..., 765, 766, 767],
...,
[3328, 3329, 3330, ..., 3581, 3582, 3583],
[3584, 3585, 3586, ..., 3837, 3838, 3839],
[3840, 3841, 3842, ..., 4093, 4094, 4095]], dtype=uint16)
Cheers,
Matthew
More information about the Neuroimaging
mailing list