Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Indecision is the basis of flexibility" -- button at a Science Fiction convention.


devel / comp.protocols.dicom / Encoding of VectorGridData (OF VR)

SubjectAuthor
* Encoding of VectorGridData (OF VR)Cristiano
`* Re: Encoding of VectorGridData (OF VR)David Gobbi
 `- Re: Encoding of VectorGridData (OF VR)Cristiano

1
Encoding of VectorGridData (OF VR)

<bebfe9ac-7c3e-49f6-ab52-7f89b6093fa7n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=126&group=comp.protocols.dicom#126

  copy link   Newsgroups: comp.protocols.dicom
X-Received: by 2002:a05:620a:11ba:: with SMTP id c26mr4164168qkk.497.1621509364250;
Thu, 20 May 2021 04:16:04 -0700 (PDT)
X-Received: by 2002:a37:83c5:: with SMTP id f188mr4252042qkd.271.1621509364034;
Thu, 20 May 2021 04:16:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.protocols.dicom
Date: Thu, 20 May 2021 04:16:03 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2.31.33.204; posting-account=x6rh8AoAAAC8VB6pE42rCIywn6Fz5oRv
NNTP-Posting-Host: 2.31.33.204
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bebfe9ac-7c3e-49f6-ab52-7f89b6093fa7n@googlegroups.com>
Subject: Encoding of VectorGridData (OF VR)
From: ctorti@gmail.com (Cristiano)
Injection-Date: Thu, 20 May 2021 11:16:04 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Cristiano - Thu, 20 May 2021 11:16 UTC

Hi all,

I'm trying to get to grips with the encoding required for VectorGridData:

http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.20.3.html#sect_C.20.3.1.3

The OF VR requires "A stream of 32-bit IEEE 754:1985 floating point words".

As far as I can tell there's no specified encoding required of the standard. Hence I wasn't sure what encoding to use when trying to decode VectorGridData.

Luckily I have a couple of Deformable DICOM Registration Objects (DROs) at my disposal. I'm assuming that they have been properly encoded as they seem to have been generated by a popular system (MIM Software).

I initially tried using the chardet package to determine the encoding:

chardet.detect(vgd1)['encoding']

where

vgd1 = Dro1.DeformableRegistrationSequence[1]\
.DeformableRegistrationGridSequence[0]\
.VectorGridData
and

Dro1 = pydicom.dcmread('filepath_of_DRO.dcm')

but that returned "None". Luckily I was more successful with the json package:

json.detect_encoding(vgd1)

which returned 'utf-8'. But when I tried to decode it using either:

vgd1.decode('UTF-8')

or

str(vgd1, 'UTF-8')

I get errors for both DROs. For vgd1:

print(vgd1[0:20], '\n')
print(vgd1.decode('UTF-8'))

b"(RSA\xf0\x19CAx\xd4\x97\xc1\xd0~'A8\x84AA"
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 4: invalid continuation byte

and vgd2:

print(vgd2[0:20], '\n')
print(vgd2.decode('UTF-8'))

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaa in position 4: invalid start byte

Can someone please help point me in the right direction?

Re: Encoding of VectorGridData (OF VR)

<f6785414-39df-4a9e-9167-77c941516d1fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=127&group=comp.protocols.dicom#127

  copy link   Newsgroups: comp.protocols.dicom
X-Received: by 2002:a37:6084:: with SMTP id u126mr5963077qkb.294.1621523820501;
Thu, 20 May 2021 08:17:00 -0700 (PDT)
X-Received: by 2002:ae9:e40b:: with SMTP id q11mr5527341qkc.101.1621523820317;
Thu, 20 May 2021 08:17:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.protocols.dicom
Date: Thu, 20 May 2021 08:17:00 -0700 (PDT)
In-Reply-To: <bebfe9ac-7c3e-49f6-ab52-7f89b6093fa7n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=198.48.161.196; posting-account=oJk4vAoAAAAuHqwGdLwYUlL776upyWJ3
NNTP-Posting-Host: 198.48.161.196
References: <bebfe9ac-7c3e-49f6-ab52-7f89b6093fa7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f6785414-39df-4a9e-9167-77c941516d1fn@googlegroups.com>
Subject: Re: Encoding of VectorGridData (OF VR)
From: david.gobbi@gmail.com (David Gobbi)
Injection-Date: Thu, 20 May 2021 15:17:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 17
 by: David Gobbi - Thu, 20 May 2021 15:17 UTC

When pydicom returns the VectorGridData as a "bytes" object, then those bytes are just the raw raw floating-point data. Asking the json module to figure out the text encoding isn't going to help, because these bytes don't store text, and the answer that json gives will be meaningless.

The reason pydicom returns "bytes" is because the "bytes" type is the most widely compatible buffer type available in Python. In Python, a buffer simply represents a chunk of the computer's memory (search for Python Buffer Protocol for more information).

Are you familiar with numpy? In numpy, you can create an array from a buffer (with the understanding that your "bytes" object is a buffer that stores floats from the DICOM file):

vgd1_array = numpy.frombuffer(vgd1, dtype='f')

All in all, this has very little to do with DICOM itself, it's really a question about pydicom.

Re: Encoding of VectorGridData (OF VR)

<6dfdbe1d-83d3-4c83-855c-24b77be48c78n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=128&group=comp.protocols.dicom#128

  copy link   Newsgroups: comp.protocols.dicom
X-Received: by 2002:ac8:4812:: with SMTP id g18mr7397237qtq.16.1621544006415; Thu, 20 May 2021 13:53:26 -0700 (PDT)
X-Received: by 2002:a37:38d:: with SMTP id 135mr8053459qkd.136.1621544006215; Thu, 20 May 2021 13:53:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.protocols.dicom
Date: Thu, 20 May 2021 13:53:25 -0700 (PDT)
In-Reply-To: <f6785414-39df-4a9e-9167-77c941516d1fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2.31.33.204; posting-account=x6rh8AoAAAC8VB6pE42rCIywn6Fz5oRv
NNTP-Posting-Host: 2.31.33.204
References: <bebfe9ac-7c3e-49f6-ab52-7f89b6093fa7n@googlegroups.com> <f6785414-39df-4a9e-9167-77c941516d1fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6dfdbe1d-83d3-4c83-855c-24b77be48c78n@googlegroups.com>
Subject: Re: Encoding of VectorGridData (OF VR)
From: ctorti@gmail.com (Cristiano)
Injection-Date: Thu, 20 May 2021 20:53:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 27
 by: Cristiano - Thu, 20 May 2021 20:53 UTC

Thanks David. Yes I had come across numpy.frombuffer() (and numpy.tobytes() to go the other way) but had failed to get sensible results due to a misunderstanding in what it was that I was actually doing.

By the way, it seems that the array package can also do this: array.array('f', bytes_object), but I use numpy a fair bit so it makes sense to stick with it.

On Thursday, 20 May 2021 at 16:17:02 UTC+1, david...@gmail.com wrote:
> When pydicom returns the VectorGridData as a "bytes" object, then those bytes are just the raw raw floating-point data. Asking the json module to figure out the text encoding isn't going to help, because these bytes don't store text, and the answer that json gives will be meaningless.
>
> The reason pydicom returns "bytes" is because the "bytes" type is the most widely compatible buffer type available in Python. In Python, a buffer simply represents a chunk of the computer's memory (search for Python Buffer Protocol for more information).
>
> Are you familiar with numpy? In numpy, you can create an array from a buffer (with the understanding that your "bytes" object is a buffer that stores floats from the DICOM file):
>
> vgd1_array = numpy.frombuffer(vgd1, dtype='f')
>
> All in all, this has very little to do with DICOM itself, it's really a question about pydicom.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor