[Image-SIG] how to add floating point color data to PIL ?

Georg Mischler gm@licht.hl-technik.de
Mon, 21 Sep 1998 10:36:14 -0100


Hi all imageneers...

I am considering to use PIL for the image manupulation
module of a larger python application. However, I have
to handle an input image format with is quite a bit
different than most others.

The images are generated by the lighting simulation system
"radiance", and store luminance values as seen from a
given view in a simulated scene.
Due to the high dynamic range of this data the values are
stored in floating point format, represented by 4 bytes
for each pixel (the format also uses run length encoding,
but that should not be a problem). The first three bytes are
the red, green and blue mantissas, and the fourth byte is
a common exponent for all three.

So far everything is fine, routines to read, store and
convert this format exist (in ansi C).
The question that bothers me is how difficult it would
be to use PIL for handling this kind of data, and how
tricky the needed extensions will be to write.

The user should be able to read such a file and the result
will be converted to rgb image brighness values according
to a gamma function for display. Users will want to edit
the gamma value and see the result, as well as the "exposure"
value, which sets an absolute relation between luminance
and brightness. There may be other filters needed, which
reduce the dynamic range of the data according to the way
the human eye would perceive a given scene in reality.

I assume that I will have to keep two sets of data in
memory (unless I want to reread the original file for
every filter operation), one holding the luminance values,
and the other the converted brightness values for display.

Now come the questions:

- What PIL formats will be best for handling the different
  kinds of data? I guess that RGB (RGBA?) is simplest for
  dislpay.
- Is it correct that the F format is currently designed
  for greyscale data only? Would I need to use three sets
  of F data to hold color luminance?
- Could it make sense to "abuse" RGBA and store everything
  in there as it comes from the file?
- Would it be simpler to add a new file format for floating
  point color data? If yes, how simple?
- How difficult will it be to add filters to convert from 
  and to each of the combined F, abused RGBA or new trippleF
  formats?
- Can filters also be implemented as plugins?
- I just realised that I haven't found out yet if plugins
  have to be implemented in python, or if they can also
  be written in C...
- Any simple and obvious solution I may have overlooked?


From the style of my descriptions you might be able to
tell that I am not a CS guy... My background is architecture
and daylighting design, though I do have a few years of
programming experience with (auto)lisp, C, oberon and
of course python.

I plan to sell the result of this project (a GUI to
radiance) commercially. If I actually manage to implement
the functionality as above with PIL (and your help!), I
think I will contribute the generally interesting parts
of it to PIL, though maybe not before I see that my
application actually sells... (don't hold your breath,
this is sill months away). Ah, and before I forget,
everything should work with NT and unix.


Thanks for any insights!

Georg Mischler
schorsch@schorsch.com