Reversing bits in a byte

Robert Flintham Robert.Flintham at uhb.nhs.uk
Tue Mar 12 14:28:28 CET 2013


Sorry, the subject line was for a related question that I decided not to ask, I forgot to change it when I changed my email.  I've changed it now!

I'm using Python 3.3 on Windows with the pydicom module (http://code.google.com/p/pydicom/).  Using pydicom, I've ended up with a "bytes" object of length (512*512/8 = 32768) containing a 512x512 1-bit bitmap (i.e. each byte represents 8 pixels of either 1 or 0).  When I print this to screen I get:
'b\x00\x00\x00.....'

I can unpack this to a tuple of the integer representations of binary data, but that doesn't really help as presume I need the binary (8 digit) representation to be able to translate that into an image.

I wasn't sure which GUI library to use, so haven't specified one.  As it's Python 3, Tkinter is available.  I also have matplotlib and numpy installed, and PIL.

Ideally, I'd like to be able to access the pixel data in the form of a numpy array so that I can perform image-processing tasks on the data.

So now that I've explained myself slightly more fully, does anyone have any thoughts on how to do this?

All the best,
Rob

Robert Flintham
Trainee Clinical Scientist - MRI

Tel:      +44 (0)121 371 7000
Email:       Robert.Flintham at uhb.nhs.uk
Web:      http://www.uhb.nhs.uk

We're bringing the world's most advanced cancer treatments to Birmingham.
Find out more at www.qecancerappeal.org or text QEHB01 £5 to 70070 to donate £5 to our appeal.

RRPPS
Medical Physics - University Hospitals Birmingham NHS Foundation Trust
63 Melchett Road, Kings Norton,
Birmingham, B30 3HP


ð Delivering the best in care



-----Original Message-----
From: Python-list [mailto:python-list-bounces+robert.flintham=uhb.nhs.uk at python.org] On Behalf Of Dave Angel
Sent: 12 March 2013 12:47
To: python-list at python.org
Subject: Re: Reversing bits in a byte

On 03/11/2013 11:32 AM, Robert Flintham wrote:
> Hi,
>
> I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per pixel).  I can't work out how I would go about displaying this image.  Does anyone have any thoughts?
>
> All the best,
> Rob
>
>

How does your subject line relate to your question?

But more importantly, what version of Python, what OS, and which GUI library (wxpython, qt, etc.) are you used to?  Specify those, and somebody familiar with that particular library will probably pop up with an answer.



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.




More information about the Python-list mailing list