[Image-SIG] PIL with dynamic image data?

Georg Mischler schorsch@schorsch.com
Fri, 23 Jul 1999 06:11:24 -0400 (EDT)

Hi all imageneers...

I sent this question allready to the list a few months
ago, and was told that nobody had time to answer it
before the (then) pending next release of PIL was out.
Looks like this might be happening right now again...
Since I have solved most of my non PIL related problems
in the mean time, I still decided to just bother the
list again.

What I need is not a detailed description about every
step (though I wouldn't complain ;), but just a few
pointers about which possible ways I should study more
carefully than others. I'm not a complete newbie to
programming in Python or C (though my real background
is architecture and lighting design), but finding the
right way through a library package like PIL will be
definitively easier with a little expert help.

Thanks in advance for any information!
Here comes the problem:

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

The images are generated by the lighting simulation system
Radiance (http://radsite.lbl.gov), and store luminance
values as seen from a certain view in of 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 first three bytes are the red, green
and blue mantissas, and the fourth byte is a common
exponent (the format also uses run length encoding,
but that should not a problem).

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 format will be best for handling the different
  kinds of data? I guess that RGB (RGBA?) is simplest for
- 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 dynamic
  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
- 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?
- Any other questions I should have asked first? ;)

If I actually manage to implement the functionality as
above with PIL (and your help!), I plan to contribute
the parts of it that are of general interest back to PIL,
though this may still be months away.
Ah, and before I forget, everything should work with NT
and unix.

Thanks for any insights!


Georg Mischler  --  simulation developper  --  schorsch at schorsch.com
+schorsch.com+  --  lighting design tools  --  http://www.schorsch.com/