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

  • SEARCH
  • Home
  • 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 7713165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:48:15+00:00 2026-06-01T01:48:15+00:00

I have a folder containing over 200 raw images, i want to convert all

  • 0

I have a folder containing over 200 raw images, i want to convert all of them to png or any other format, In C it’s pretty easy but in python i don’t know how it’s done

I found this snippet

#import struct
import numpy, array, PIL, Image
from struct import *

#declarations
arr1D   =   array.array('H') #H is unsigned short

#------------------------------------
#read 16 bit unsigned raw depth image
#------------------------------------
w           =   640
h           =   480
fid        =   open('/home/salman/salman/NiSimpleRead_salman/data/200.raw')
#fid         =   open('/home/salman/test.raw')
numBytes    =   w*h
arr1D.read(fid, numBytes)
fid.close()

#----------------------------------------------------
#convert to float numpy array -> scale -> uint8 array
#----------------------------------------------------
numarr = numpy.array(arr1D, dtype='float');
numarr = 255 - (numarr*255.0/numarr.max())
numarr.shape = (h,w)
numarr = numarr.astype('uint8')

#======================
#IMAGES
#======================

#2D numpy array -> image 
#-----------------------
img        =   Image.fromarray(numarr); #print data.dtype.name

#image view and save
#-------------------
#img.show()
img.save('/home/salman/test.png')

This is the only snippet that I can find, is this the proper way to do it?

  • 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-01T01:48:17+00:00Added an answer on June 1, 2026 at 1:48 am

    It should be something like:

    rawData = open("foo.raw" 'rb').read()
    imgSize = (x,y)
    # Use the PIL raw decoder to read the data.
    # the 'F;16' informs the raw decoder that we are reading 
    # a little endian, unsigned integer 16 bit data.
    img = Image.fromstring('L', imgSize, rawData, 'raw', 'F;16')
    img.save("foo.png")
    

    Using the handbook and another SO question.

    The First argument is the image mode and can be any from:

    • 1 (1-bit pixels, black and white, stored with one pixel per byte)
    • L (8-bit pixels, black and white)
    • P (8-bit pixels, mapped to any other mode using a colour palette)
    • RGB (3×8-bit pixels, true colour)
    • RGBA (4×8-bit pixels, true colour with transparency mask)
    • CMYK (4×8-bit pixels, colour separation)
    • YCbCr (3×8-bit pixels, colour video format)
    • I (32-bit signed integer pixels)
    • F (32-bit floating point pixels)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder containing images. I want to have an image slider, like
i want to download folder containing files like pdf,jpg,png etc from web services.I have
I have a folder containing thousand of html files. I want initially all these
Is there any way, with the Eclipse IDE, to have a master folder containing
I have some directories containing test data, typically over 200,000 small (~4k) files per
Background I have a secured folder containing secret report files (in pdf format). Each
In my Rails 3.2 models directory, I have a folder foo containing two classes:
I have a bash script set that executes in a folder containing a number
I have a zip file containing a folder and inside the folder I have
I have an asp.net application containing pages that lie in multiple folder. I have

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.