RE: Reversing bits in a byte

Discussion in 'Python' started by Robert Flintham, Mar 12, 2013.

  1. 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 oflength (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 havematplotlib 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:
    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=] On Behalf Of Dave Angel
    Sent: 12 March 2013 12:47
    To:
    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), pleasenotify 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.
     
    Robert Flintham, Mar 12, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Angel

    Re: Reversing bits in a byte

    Dave Angel, Mar 12, 2013, in forum: Python
    Replies:
    0
    Views:
    101
    Dave Angel
    Mar 12, 2013
  2. Robert Flintham

    RE: Reversing bits in a byte

    Robert Flintham, Mar 12, 2013, in forum: Python
    Replies:
    0
    Views:
    126
    Robert Flintham
    Mar 12, 2013
  3. Tim Chase

    Re: Reversing bits in a byte

    Tim Chase, Mar 12, 2013, in forum: Python
    Replies:
    0
    Views:
    89
    Tim Chase
    Mar 12, 2013
  4. Oscar Benjamin

    Re: Reversing bits in a byte

    Oscar Benjamin, Mar 12, 2013, in forum: Python
    Replies:
    0
    Views:
    107
    Oscar Benjamin
    Mar 12, 2013
  5. Oscar Benjamin

    Re: Reversing bits in a byte

    Oscar Benjamin, Mar 12, 2013, in forum: Python
    Replies:
    2
    Views:
    120
    88888 Dihedral
    Mar 12, 2013
Loading...

Share This Page