Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:46:34+00:00 2026-06-05T07:46:34+00:00

I have an image file that is a grayscale 8 bit unsigned integer raw

  • 0

I have an image file that is a grayscale 8 bit unsigned integer raw binary file and I need to convert it to a 16 bit file and keep it in raw binary. It is relatively easy to go from 16 to 8 because you are just cutting off information but I am curious how I can go the other way.

To be specific I have an image that is going into a processor written in C++ and the processor only takes 16 bit unsigned integer image files so I need to convert my 8 bit file into a 16 bit one. I have been doing some processing with the Python Imaging Library but haven’t been able to find this specific function.

UPDATE:

I followed cgohlke’s advice and have the following code that seems logical but it is not accepting my ‘final’ variable because of the following error:

Traceback (most recent call last):
  File "C:\Users\Patrick\workspace\colorCorrect\src\editGrayscale.py", line 36, in <module>
    u1 = np.fromfile(final, 'uint8')
TypeError: file() argument 1 must be encoded string without NULL bytes, not str

My code:

import Image
import numpy as np

fileName = raw_input("Enter a file name: ")
saveFile = raw_input("Enter a new save file name: ")

with open(fileName, 'rb') as f:
    im = Image.fromstring('L', (3032, 2016), f.read()) # also try 'L;16B', 'I;16', and 'I;16B'
    changed = im.point(lambda i: i/.4)    

final = changed.tostring()

np.arange(256).astype('uint8').tofile(final)

u1 = np.fromfile(final, 'uint8')
u2 = u1.astype('uint16')
u2 *= 257  # scale to full 16 bit range
u2.tofile(saveFile)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:46:35+00:00Added an answer on June 5, 2026 at 7:46 am
    import numpy as np
    
    # create example file
    np.arange(256).astype('uint8').tofile('uint8_file.bin')
    
    # read example file and convert to uint16
    u1 = np.fromfile('uint8_file.bin', 'uint8')
    u2 = u1.astype('uint16')
    u2 *= 257  # scale to full 16 bit range
    u2.tofile('uint16_file.bin')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an raw image file that is .bin and is composed of 16
I have an image file that has all the character sprites that I will
I have an image (PNG file) that has an alpha channel that is set
I have a single image file in a folder in my Eclipse project that
I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I have a form that accepts image file, i want to be able to
I have some code that loads an image file off the web and puts
I have a program that reads one image file, makes some changes on that
I have a program that loads an image from a file with DirectX using
We suppose that we have the following image (is a single file with 4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.