3

I want to try view the image using spyder python as in:

skydrive share the image is:

  • uint16 (10-bit)
  • width:1376 pixel, height: 960 pixel
  • no header
  • bayer pattern blue-green, green-red

What python script is suitable?

Thanks.

bahgia minhat
  • 33
  • 1
  • 1
  • 3
  • Please have a try on this first and post the code snippet or error if you are facing some issue – RinoTom Feb 25 '13 at 14:35
  • Look [here](http://stackoverflow.com/questions/3397157/how-to-read-a-raw-image-using-pil) – will Feb 25 '13 at 15:22
  • also note that this is about "image processing" not about the "processing" programming language. – Mike 'Pomax' Kamermans Feb 25 '13 at 16:25
  • You could split this into 3 or 4 steps and each would be a question on its own. 1) How to read the image. 2) Bayer demosaicing. 3) Converting from a linear colorspace to something gamma corrected such as sRGB. 4) Applying white balance or color correction. – Mark Ransom Feb 25 '13 at 18:10
  • this is what I get from [link]http://www.kyb.tuebingen.mpg.de/?id=227 fin = open('001.raw', 'rb') s = fin.read() fin.close() arr = array.array('H', s) arr.byteswap() img = numpy.array(arr, dtype='uint16').reshape(960,1376) imshow(img, gray()); – bahgia minhat Feb 26 '13 at 15:58

1 Answers1

4

Here is one way.

Start with imports

from matplotlib import pyplot as plt
import numpy as np

Now allocate the space

image = np.empty((1376,960), np.uint16)

Read the image into your array:

image.data[:] = open('20_1-20ms.raw').read()

Display it:

plt.imshow(image)
luispedro
  • 6,934
  • 4
  • 35
  • 45
  • 4
    As far as I can tell, this doesn't work on color data (i.e., a stack of 3 images, one for each color). Matplotlib's imshow requires either floats or int8s to produce a reasonable RGB image. Attempting to call it with int16s will produce garbled noise. You must either bitshift your 10 bit data to 8 bit data, or convert to float e.g., im_float = im_int / (2**10 - 1.). – KDN Jul 08 '13 at 21:51
  • 1
    I tried this out to read a .raw file but I'm getting this error: NotImplementedError: memoryview slice assignments are currently restricted to ndim = 1. – Raiyan Chowdhury Nov 05 '20 at 02:33