Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7543 > unrolled thread

working with raw image files

Started bykafooster <dmozejko@gmail.com>
First post2011-06-13 11:18 -0700
Last post2011-06-15 02:33 +0100
Articles 20 on this page of 22 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-13 11:18 -0700
    Re: working with raw image files Terry Reedy <tjreedy@udel.edu> - 2011-06-13 14:49 -0400
    Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 13:08 -0700
      Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 13:20 -0700
        Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-13 21:36 +0100
        Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-13 13:41 -0700
          Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 13:52 -0700
            Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-13 13:58 -0700
              Re: working with raw image files Wanderer <wanderer@dialup4less.com> - 2011-06-13 14:28 -0700
                Re: working with raw image files Martin De Kauwe <mdekauwe@gmail.com> - 2011-06-14 00:49 -0700
                  Re: working with raw image files Terry Reedy <tjreedy@udel.edu> - 2011-06-14 12:24 -0400
                    Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 13:13 -0700
                      Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-14 21:26 +0100
                        Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 14:20 -0700
                          Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-14 23:06 +0100
                            Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 16:59 -0700
                              Re: working with raw image files MRAB <python@mrabarnett.plus.com> - 2011-06-15 01:24 +0100
                          Re: working with raw image files Dave Angel <davea@ieee.org> - 2011-06-14 19:25 -0400
                            Re: working with raw image files kafooster <dmozejko@gmail.com> - 2011-06-14 17:02 -0700
                              Re: working with raw image files Dave Angel <davea@ieee.org> - 2011-06-14 22:13 -0400
                            Re: working with raw image files Nobody <nobody@nowhere.com> - 2011-06-15 02:29 +0100
                      Re: working with raw image files Nobody <nobody@nowhere.com> - 2011-06-15 02:33 +0100

Page 1 of 2  [1] 2  Next page →


#7543 — working with raw image files

Fromkafooster <dmozejko@gmail.com>
Date2011-06-13 11:18 -0700
Subjectworking with raw image files
Message-ID<0cd64f09-bd32-4b67-9266-46003dbea4b7@m4g2000yqk.googlegroups.com>
I am working on some medical image data, and I try to look into
specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
dimensions are 352*470*96. I checked it in some pro medical image
viewer, it is alright. However, with the code I use, I display just
white noise image.(but worked well for other, 8bit raw image).
 Also, printed size is half the original size, like it was 8 bit. I
read some documentations on PIL, numpy etc but I think I just do not
understand something.
I open image data set, I change it to array, give it dimensions,
dtype, and change it to image, right? I think there is something
messed up in 'binvalues', but dont really know how to write it in
simpler way.

P.S.1
If I want to change data type to e.g. 8 bit uint, is it just change in
scipy.array? or it requires some more changes

P.S.2
Lets say I have my array of image data and want to save it to *.raw
data set. is it array.tofile?

Here is my code

############################

import scipy as sc
from pylab import *
import array
import Image

fileobj = open("hand.raw", 'rb')
binvalues = array.array('B')
binvalues.read (fileobj, 352*470*96)
data1 = sc.array(binvalues, dtype=sc.int16)
data2 = sc.reshape(data1, (352,470,96))
fileobj.close()
print data2.size , data2.dtype

im = Image.fromarray(data2[:,:,40])
im.show()

[toc] | [next] | [standalone]


#7548

FromTerry Reedy <tjreedy@udel.edu>
Date2011-06-13 14:49 -0400
Message-ID<mailman.192.1307990990.11593.python-list@python.org>
In reply to#7543
On 6/13/2011 2:18 PM, kafooster wrote:
> I am working on some medical image data, and I try to look into
> specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
> dimensions are 352*470*96. I checked it in some pro medical image
> viewer, it is alright. However, with the code I use, I display just
> white noise image.(but worked well for other, 8bit raw image).
>   Also, printed size is half the original size, like it was 8 bit. I
> read some documentations on PIL, numpy etc but I think I just do not
> understand something.

You might get a better answer to such a specialized question on the 
scipy list (or PIL list, if there is one) than here.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#7553

FromWanderer <wanderer@dialup4less.com>
Date2011-06-13 13:08 -0700
Message-ID<1f7a452a-8bae-43e0-ab9f-9bfed55ee206@b21g2000yqc.googlegroups.com>
In reply to#7543
On Jun 13, 2:18 pm, kafooster <dmoze...@gmail.com> wrote:
> I am working on some medical image data, and I try to look into
> specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
> dimensions are 352*470*96. I checked it in some pro medical image
> viewer, it is alright. However, with the code I use, I display just
> white noise image.(but worked well for other, 8bit raw image).
>  Also, printed size is half the original size, like it was 8 bit. I
> read some documentations on PIL, numpy etc but I think I just do not
> understand something.
> I open image data set, I change it to array, give it dimensions,
> dtype, and change it to image, right? I think there is something
> messed up in 'binvalues', but dont really know how to write it in
> simpler way.
>
> P.S.1
> If I want to change data type to e.g. 8 bit uint, is it just change in
> scipy.array? or it requires some more changes
>
> P.S.2
> Lets say I have my array of image data and want to save it to *.raw
> data set. is it array.tofile?
>
> Here is my code
>
> ############################
>
> import scipy as sc
> from pylab import *
> import array
> import Image
>
> fileobj = open("hand.raw", 'rb')
> binvalues = array.array('B')
> binvalues.read (fileobj, 352*470*96)
> data1 = sc.array(binvalues, dtype=sc.int16)
> data2 = sc.reshape(data1, (352,470,96))
> fileobj.close()
> print data2.size , data2.dtype
>
> im = Image.fromarray(data2[:,:,40])
> im.show()

Try using numpy arrays.

import numpy as np
import Image

image1 = Image.open("hand.raw", 'rb')
imshape = image1.size
npArray = np.array(image1.getdata())
npArray.shape = imshape

im = Image.fromarray(npArray)
im.show()

[toc] | [prev] | [next] | [standalone]


#7554

FromWanderer <wanderer@dialup4less.com>
Date2011-06-13 13:20 -0700
Message-ID<a4d759a7-02dd-47b9-ba38-0dc947561230@k16g2000yqm.googlegroups.com>
In reply to#7553
On Jun 13, 4:08 pm, Wanderer <wande...@dialup4less.com> wrote:
> On Jun 13, 2:18 pm, kafooster <dmoze...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > I am working on some medical image data, and I try to look into
> > specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
> > dimensions are 352*470*96. I checked it in some pro medical image
> > viewer, it is alright. However, with the code I use, I display just
> > white noise image.(but worked well for other, 8bit raw image).
> >  Also, printed size is half the original size, like it was 8 bit. I
> > read some documentations on PIL, numpy etc but I think I just do not
> > understand something.
> > I open image data set, I change it to array, give it dimensions,
> > dtype, and change it to image, right? I think there is something
> > messed up in 'binvalues', but dont really know how to write it in
> > simpler way.
>
> > P.S.1
> > If I want to change data type to e.g. 8 bit uint, is it just change in
> > scipy.array? or it requires some more changes
>
> > P.S.2
> > Lets say I have my array of image data and want to save it to *.raw
> > data set. is it array.tofile?
>
> > Here is my code
>
> > ############################
>
> > import scipy as sc
> > from pylab import *
> > import array
> > import Image
>
> > fileobj = open("hand.raw", 'rb')
> > binvalues = array.array('B')
> > binvalues.read (fileobj, 352*470*96)
> > data1 = sc.array(binvalues, dtype=sc.int16)
> > data2 = sc.reshape(data1, (352,470,96))
> > fileobj.close()
> > print data2.size , data2.dtype
>
> > im = Image.fromarray(data2[:,:,40])
> > im.show()
>
> Try using numpy arrays.
>
> import numpy as np
> import Image
>
> image1 = Image.open("hand.raw", 'rb')
> imshape = image1.size
> npArray = np.array(image1.getdata())
> npArray.shape = imshape
>
> im = Image.fromarray(npArray)
> im.show()

P.S.1
If you want to change data size from a data buffer, you could use
something like.

 image1 = np.frombuffer(Buffer, np.uint16)

P.S.2
I'm not sure what a *.raw file is but if Image has support for it you
just need to include the extension.

 im = Image.fromarray(npArray)
 im.save(self.resultDir + "\\" + imageName + '.tif')


[toc] | [prev] | [next] | [standalone]


#7555

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-13 21:36 +0100
Message-ID<mailman.195.1307997358.11593.python-list@python.org>
In reply to#7554
On 13/06/2011 21:20, Wanderer wrote:
> On Jun 13, 4:08 pm, Wanderer<wande...@dialup4less.com>  wrote:
>> On Jun 13, 2:18 pm, kafooster<dmoze...@gmail.com>  wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> I am working on some medical image data, and I try to look into
>>> specific slice of   3d  *.raw image. I know voxels are 16 bit int, and
>>> dimensions are 352*470*96. I checked it in some pro medical image
>>> viewer, it is alright. However, with the code I use, I display just
>>> white noise image.(but worked well for other, 8bit raw image).
>>>   Also, printed size is half the original size, like it was 8 bit. I
>>> read some documentations on PIL, numpy etc but I think I just do not
>>> understand something.
>>> I open image data set, I change it to array, give it dimensions,
>>> dtype, and change it to image, right? I think there is something
>>> messed up in 'binvalues', but dont really know how to write it in
>>> simpler way.
>>
>>> P.S.1
>>> If I want to change data type to e.g. 8 bit uint, is it just change in
>>> scipy.array? or it requires some more changes
>>
>>> P.S.2
>>> Lets say I have my array of image data and want to save it to *.raw
>>> data set. is it array.tofile?
>>
>>> Here is my code
>>
>>> ############################
>>
>>> import scipy as sc
>>> from pylab import *
>>> import array
>>> import Image
>>
>>> fileobj = open("hand.raw", 'rb')
>>> binvalues = array.array('B')
>>> binvalues.read (fileobj, 352*470*96)
>>> data1 = sc.array(binvalues, dtype=sc.int16)
>>> data2 = sc.reshape(data1, (352,470,96))
>>> fileobj.close()
>>> print data2.size , data2.dtype
>>
>>> im = Image.fromarray(data2[:,:,40])
>>> im.show()
>>
>> Try using numpy arrays.
>>
>> import numpy as np
>> import Image
>>
>> image1 = Image.open("hand.raw", 'rb')
>> imshape = image1.size
>> npArray = np.array(image1.getdata())
>> npArray.shape = imshape
>>
>> im = Image.fromarray(npArray)
>> im.show()
>
> P.S.1
> If you want to change data size from a data buffer, you could use
> something like.
>
>   image1 = np.frombuffer(Buffer, np.uint16)
>
> P.S.2
> I'm not sure what a *.raw file is but if Image has support for it you
> just need to include the extension.
>
>   im = Image.fromarray(npArray)
>   im.save(self.resultDir + "\\" + imageName + '.tif')
>
A .raw file doesn't contain a header, just the pixel values.

[toc] | [prev] | [next] | [standalone]


#7556

Fromkafooster <dmozejko@gmail.com>
Date2011-06-13 13:41 -0700
Message-ID<e648cf41-9e2c-4acf-b312-7b83be8cd03a@h7g2000yqa.googlegroups.com>
In reply to#7554
Wanderer: by *.raw I mean images with .raw extension, pure pixel data
without header
http://en.wikipedia.org/wiki/Raw_image_format

That is a clear and nice code however I think Image.open cannot
handle .raw since i get error

    image1 = Image.open("hand.raw", "rb")
  File "D:\Python27\lib\site-packages\PIL\Image.py", line 1947, in
open
    raise ValueError("bad mode")
ValueError: bad mode

[toc] | [prev] | [next] | [standalone]


#7557

FromWanderer <wanderer@dialup4less.com>
Date2011-06-13 13:52 -0700
Message-ID<57d6da80-59db-477f-b507-cabf01a2976d@j23g2000yqc.googlegroups.com>
In reply to#7556
On Jun 13, 4:41 pm, kafooster <dmoze...@gmail.com> wrote:
> Wanderer: by *.raw I mean images with .raw extension, pure pixel data
> without headerhttp://en.wikipedia.org/wiki/Raw_image_format
>
> That is a clear and nice code however I think Image.open cannot
> handle .raw since i get error
>
>     image1 = Image.open("hand.raw", "rb")
>   File "D:\Python27\lib\site-packages\PIL\Image.py", line 1947, in
> open
>     raise ValueError("bad mode")
> ValueError: bad mode

Try dropping the "rb". I don't use it in my code. I copied it from the
OP.

[toc] | [prev] | [next] | [standalone]


#7558

Fromkafooster <dmozejko@gmail.com>
Date2011-06-13 13:58 -0700
Message-ID<720bec5b-4892-4cd7-83e1-f67ce78591be@y30g2000yqb.googlegroups.com>
In reply to#7557
On 13 Cze, 22:52, Wanderer <wande...@dialup4less.com> wrote:
> On Jun 13, 4:41 pm, kafooster <dmoze...@gmail.com> wrote:
>
> > Wanderer: by *.raw I mean images with .raw extension, pure pixel data
> > without headerhttp://en.wikipedia.org/wiki/Raw_image_format
>
> > That is a clear and nice code however I think Image.open cannot
> > handle .raw since i get error
>
> >     image1 = Image.open("hand.raw", "rb")
> >   File "D:\Python27\lib\site-packages\PIL\Image.py", line 1947, in
> > open
> >     raise ValueError("bad mode")
> > ValueError: bad mode
>
> Try dropping the "rb". I don't use it in my code. I copied it from the
> OP.

I tried it, then it cannot identify image file

[toc] | [prev] | [next] | [standalone]


#7559

FromWanderer <wanderer@dialup4less.com>
Date2011-06-13 14:28 -0700
Message-ID<71140671-4273-417d-8d2f-3986663acdb2@k16g2000yqm.googlegroups.com>
In reply to#7558
On Jun 13, 4:58 pm, kafooster <dmoze...@gmail.com> wrote:
> On 13 Cze, 22:52, Wanderer <wande...@dialup4less.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Jun 13, 4:41 pm, kafooster <dmoze...@gmail.com> wrote:
>
> > > Wanderer: by *.raw I mean images with .raw extension, pure pixel data
> > > without headerhttp://en.wikipedia.org/wiki/Raw_image_format
>
> > > That is a clear and nice code however I think Image.open cannot
> > > handle .raw since i get error
>
> > >     image1 = Image.open("hand.raw", "rb")
> > >   File "D:\Python27\lib\site-packages\PIL\Image.py", line 1947, in
> > > open
> > >     raise ValueError("bad mode")
> > > ValueError: bad mode
>
> > Try dropping the "rb". I don't use it in my code. I copied it from the
> > OP.
>
> I tried it, then it cannot identify image file

You're right raw is not a supported file format.

http://www.pythonware.com/library/pil/handbook/index.htm

[toc] | [prev] | [next] | [standalone]


#7594

FromMartin De Kauwe <mdekauwe@gmail.com>
Date2011-06-14 00:49 -0700
Message-ID<2c095413-ea59-4339-8419-ae4b688e219d@17g2000prr.googlegroups.com>
In reply to#7559
what is a .raw file, do you mean a flat binary?

[toc] | [prev] | [next] | [standalone]


#7619

FromTerry Reedy <tjreedy@udel.edu>
Date2011-06-14 12:24 -0400
Message-ID<mailman.223.1308068671.11593.python-list@python.org>
In reply to#7594
On 6/14/2011 3:49 AM, Martin De Kauwe wrote:
> what is a .raw file, do you mean a flat binary?
Perhaps tiff-like.
https://secure.wikimedia.org/wikipedia/en/wiki/Raw_image_format

"Providing a detailed and concise description of the content of raw 
files is highly problematic. There is no single raw format; formats can 
be similar or radically different. Different manufacturers use their own 
proprietary and typically undocumented formats, which are collectively 
known as raw format. Often they also change the format from one camera 
model to the next. Several major camera manufacturers, including Nikon, 
Canon and Sony, encrypt portions of the file in an attempt to prevent 
third-party tools from accessing them.[2]"

A real mess.

'.raw' is used (among others) by Panasonic and Leica. Not clear if .raw 
is the same for both.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#7628

Fromkafooster <dmozejko@gmail.com>
Date2011-06-14 13:13 -0700
Message-ID<bf3f66ae-9b8f-4bd9-8827-bf0cd59bd3e7@j23g2000yqc.googlegroups.com>
In reply to#7619
Ok, I solved the problem with matplotlib

fileobj = open("hand.raw", 'rb')
data = numpy.fromfile(fileobj,dtype=np.uint16)
data = numpy.reshape(data,(96,470,352))
imshow(data[:,:,40],cmap='gray')
show()

the error was caused by different order of data, however it still
reads the dataset as half of it size. whatever.

please leave the part about .raw, lets just start thinking of it from
level of numpy array.

I would like to visualize this data with PIL, but PIL works only with
8bit data. How could I resample my array from 16bit to 8bit?

[toc] | [prev] | [next] | [standalone]


#7629

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-14 21:26 +0100
Message-ID<mailman.231.1308083252.11593.python-list@python.org>
In reply to#7628
On 14/06/2011 21:13, kafooster wrote:
> Ok, I solved the problem with matplotlib
>
> fileobj = open("hand.raw", 'rb')
> data = numpy.fromfile(fileobj,dtype=np.uint16)
> data = numpy.reshape(data,(96,470,352))
> imshow(data[:,:,40],cmap='gray')
> show()
>
> the error was caused by different order of data, however it still
> reads the dataset as half of it size. whatever.
>
> please leave the part about .raw, lets just start thinking of it from
> level of numpy array.
>
> I would like to visualize this data with PIL, but PIL works only with
> 8bit data. How could I resample my array from 16bit to 8bit?

Multiply the numpy array by a scaling factor, which is
float(max_8bit_value) / float(max_16bit_value).

[toc] | [prev] | [next] | [standalone]


#7631

Fromkafooster <dmozejko@gmail.com>
Date2011-06-14 14:20 -0700
Message-ID<e62e7c74-6169-42e7-acd4-3bb45c8a875b@p13g2000yqh.googlegroups.com>
In reply to#7629
On 14 Cze, 22:26, MRAB <pyt...@mrabarnett.plus.com> wrote:
>
> Multiply the numpy array by a scaling factor, which is
> float(max_8bit_value) / float(max_16bit_value).

could you please explain it a little? I dont understand it. like
multiplying each element?

[toc] | [prev] | [next] | [standalone]


#7634

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-14 23:06 +0100
Message-ID<mailman.236.1308089164.11593.python-list@python.org>
In reply to#7631
On 14/06/2011 22:20, kafooster wrote:
> On 14 Cze, 22:26, MRAB<pyt...@mrabarnett.plus.com>  wrote:
>>
>> Multiply the numpy array by a scaling factor, which is
>> float(max_8bit_value) / float(max_16bit_value).
>
> could you please explain it a little? I dont understand it. like
> multiplying each element?

Yes. Something like this:

fileobj = open("hand.raw", 'rb')
data = numpy.fromfile(fileobj, dtype=numpy.uint16)
fileobj.close()
data = data * float(0xFF) / float(0xFFFF)
data = numpy.array(data, dtype=numpy.uint8)
data = data.reshape((96, 470, 352))
imshow(data[:, :, 40], cmap='gray')
show()

[toc] | [prev] | [next] | [standalone]


#7648

Fromkafooster <dmozejko@gmail.com>
Date2011-06-14 16:59 -0700
Message-ID<e16f69fb-19ed-440b-93e2-3edaa8e5ff4d@z33g2000yqb.googlegroups.com>
In reply to#7634
On 15 Cze, 00:06, MRAB <pyt...@mrabarnett.plus.com> wrote:

>
> Yes. Something like this:
>
> fileobj = open("hand.raw", 'rb')
> data = numpy.fromfile(fileobj, dtype=numpy.uint16)
> fileobj.close()
> data = data * float(0xFF) / float(0xFFFF)
> data = numpy.array(data, dtype=numpy.uint8)
> data = data.reshape((96, 470, 352))
> imshow(data[:, :, 40], cmap='gray')
> show()

thank you very much, it works and now I can display this data even
with Image.fromarray(). As I understand, it  multiplies data elements
by a fraction, so that when we have less levels (in 8uint), it can fit
there?

[toc] | [prev] | [next] | [standalone]


#7654

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-15 01:24 +0100
Message-ID<mailman.245.1308097451.11593.python-list@python.org>
In reply to#7648
On 15/06/2011 00:59, kafooster wrote:
> On 15 Cze, 00:06, MRAB<pyt...@mrabarnett.plus.com>  wrote:
>
>>
>> Yes. Something like this:
>>
>> fileobj = open("hand.raw", 'rb')
>> data = numpy.fromfile(fileobj, dtype=numpy.uint16)
>> fileobj.close()
>> data = data * float(0xFF) / float(0xFFFF)
>> data = numpy.array(data, dtype=numpy.uint8)
>> data = data.reshape((96, 470, 352))
>> imshow(data[:, :, 40], cmap='gray')
>> show()
>
> thank you very much, it works and now I can display this data even
> with Image.fromarray(). As I understand, it  multiplies data elements
> by a fraction, so that when we have less levels (in 8uint), it can fit
> there?

Correct.

[toc] | [prev] | [next] | [standalone]


#7644

FromDave Angel <davea@ieee.org>
Date2011-06-14 19:25 -0400
Message-ID<mailman.241.1308093964.11593.python-list@python.org>
In reply to#7631
On 01/-10/-28163 02:59 PM, kafooster wrote:
> On 14 Cze, 22:26, MRAB<pyt...@mrabarnett.plus.com>  wrote:
>>
>> Multiply the numpy array by a scaling factor, which is
>> float(max_8bit_value) / float(max_16bit_value).
>
> could you please explain it a little? I dont understand it. like
> multiplying each element?
>

You said in an earlier message to ignore the RAW format.  However, if 
your file matches a typical camera's raw file, there are several problems:

1) the data is typically 12 to 14 bits per pixel, only rarely 16 (very 
expensive cameras)
2) the data does not have R, G and B values for each pixel, but only one 
of these.  The others are generated by Bayer interpolation.
3) the data is linear (which is what the hardware produces), and 
traditional image data wants to be in some non-linear color space.  For 
example, most jpegs are sRGB 8*3 bits per pixel.

The first would mean that you'd need to do a lot of shifting and 
masking.  The second would mean a pretty complex interpolation 
algorithm.  And the third would require an exponential function at the 
very least.

DaveA

[toc] | [prev] | [next] | [standalone]


#7649

Fromkafooster <dmozejko@gmail.com>
Date2011-06-14 17:02 -0700
Message-ID<3c42b351-4745-4b35-aa9f-cefb53f846e1@t14g2000yqc.googlegroups.com>
In reply to#7644
On 15 Cze, 01:25, Dave Angel <da...@ieee.org> wrote:
> On 01/-10/-28163 02:59 PM, kafooster wrote:
>
> > On 14 Cze, 22:26, MRAB<pyt...@mrabarnett.plus.com>  wrote:
>
> >> Multiply the numpy array by a scaling factor, which is
> >> float(max_8bit_value) / float(max_16bit_value).
>
> > could you please explain it a little? I dont understand it. like
> > multiplying each element?
>
> You said in an earlier message to ignore the RAW format.  However, if
> your file matches a typical camera's raw file, there are several problems:
>
> 1) the data is typically 12 to 14 bits per pixel, only rarely 16 (very
> expensive cameras)
> 2) the data does not have R, G and B values for each pixel, but only one
> of these.  The others are generated by Bayer interpolation.
> 3) the data is linear (which is what the hardware produces), and
> traditional image data wants to be in some non-linear color space.  For
> example, most jpegs are sRGB 8*3 bits per pixel.
>
> The first would mean that you'd need to do a lot of shifting and
> masking.  The second would mean a pretty complex interpolation
> algorithm.  And the third would require an exponential function at the
> very least.
>
> DaveA

well, I am only working with grayscale MRI medical images(mainly 8 or
16bits), saved as .raw. I do not need to worry about rgb.

[toc] | [prev] | [next] | [standalone]


#7664

FromDave Angel <davea@ieee.org>
Date2011-06-14 22:13 -0400
Message-ID<mailman.250.1308104044.11593.python-list@python.org>
In reply to#7649
On 01/-10/-28163 02:59 PM, kafooster wrote:
> On 15 Cze, 01:25, Dave Angel<da...@ieee.org>  wrote:
>> On 01/-10/-28163 02:59 PM, kafooster wrote:
>>
>>> On 14 Cze, 22:26, MRAB<pyt...@mrabarnett.plus.com>    wrote:
>>
>>>> Multiply the numpy array by a scaling factor, which is
>>>> float(max_8bit_value) / float(max_16bit_value).
>>
>>> could you please explain it a little? I dont understand it. like
>>> multiplying each element?
>>
>> You said in an earlier message to ignore the RAW format.  However, if
>> your file matches a typical camera's raw file, there are several problems:
>>
>> 1) the data is typically 12 to 14 bits per pixel, only rarely 16 (very
>> expensive cameras)
>> 2) the data does not have R, G and B values for each pixel, but only one
>> of these.  The others are generated by Bayer interpolation.
>> 3) the data is linear (which is what the hardware produces), and
>> traditional image data wants to be in some non-linear color space.  For
>> example, most jpegs are sRGB 8*3 bits per pixel.
>>
>> The first would mean that you'd need to do a lot of shifting and
>> masking.  The second would mean a pretty complex interpolation
>> algorithm.  And the third would require an exponential function at the
>> very least.
>>
>> DaveA
>
> well, I am only working with grayscale MRI medical images(mainly 8 or
> 16bits), saved as .raw. I do not need to worry about rgb.
>

Well, since you've already gotten results you like (per another msg from 
you), the gamma adjustment must already be made.  So they're an entirely 
different meaning of raw than used by DSLR's, for example.

Glad it's working for you.

DaveA

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web