RE: Reversing bits in a byte

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

  1. Further to my earlier reply to Dave:

    I'd like to either display the image in a GUI, or save it in a format that can be opened easily in Windows (like a PNG or a 24-bit BMP).

    I know the dimensions as it'scoming from the header of a DICOM file. I'm trying to analyse DICOM images where an 'overlay' image is stored as a bitmap in the header information.So the bitmap data is one DICOM tag (6000,3000) and the height and width of the overlay are in two other tags (6000,0010) and (6000,0011).

    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: Tim Chase [mailto:p]
    Sent: 12 March 2013 13:21
    To: Robert Flintham
    Cc: ''
    Subject: Re: Reversing bits in a byte

    On 2013-03-11 15:32, Robert Flintham wrote:

    > 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?


    You'd need todetail
    - how you want to display it (console, GUI, web page)
    - how you know what the dimensions are
    - the bit order

    It could be something as simple as

    HEIGHT = 40
    some_bytes = file('data.bin').read()
    WIDTH = len(some_bytes) // HEIGHT
    for i, byte in enumerate(some_bytes):
    if i and i % WIDTH == 0:
    print # a new line
    for bit in range(8):
    if byte & (1 << bit):
    print '*',
    else:
    print ' ',


    -tkc


    > DISCLAIMER:

    [trim a paragraph of useless junk]
    Please remove these disclaimers if at all possible. You're posting to a public forum, which pretty much waives all credibility to the disclaimer (not that they've held much legal standing in any argument I've heard).






    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.
     
    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:
    118
    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