Search code examples
pythonbinaryencodedicom

Not able to convert binary data from dicom file with python


I have a Vector Grid Data from a Deformable Registration Grid Sequence whos type is binary.

i'm Trying to convert this data to a list of, i think, signed floating point value elements. but can find the function that allows me perform this operation. Let me show you a piece of the information.

b' dZ=\x00\x90\xb3=\x00\x18\x89\xbd \xe9}=\x00\xc0\xd6=\x00\xa0\xa5\xbd\xe0]\x93=\x00\x10\xfd=\x00\xa8\xc4\xbd\xc0\x8e\xa9=

...

\x95\xf9\xbb\xbc\x00\x80\x06=\xc6\x88(=\xa9\xcb\x82\xbc\x00@\xa6<A\xce\xc6<\xc5\xd5\x19\xbc\x00\x00\x0e<k\xba\x17<\x02\x07i\xbb'

i'll appreciate your help


Solution

  • Vector Grid Data consists of triplets of 4 byte floating point values. Try

    from struct import unpack
    
    data = b"..."
    values = unpack(f"<{len(data) / 4}f", data)