[Image-SIG] Floating point color in PIL?

Georg Mischler schorsch@schorsch.com
Sat, 21 Aug 1999 16:47:39 -0400 (EDT)


Hi again in imaging land,

in my attempts to read Radiance image files into PIL, I
have made some partial progress. I think I understand
how the plugin should look like from the python side (and
I allready had most code needed for this). Now I am trying
to get the data in somehow, and I can't see a way to
store three band floating point images without modifying
(at least) Image.py and Storage.c.

The files store radiance (sic!) values in rgbe format,
with either a simple runlength encoding scheme or another
more complicated one. The values are encoded within four bytes,
the fourth byte holding a common exponent for the three bands.
But this is not the problem, since the encoder/decoder will
handle the peculiarities of the file format transparently.

The result are the floating point RGB radiance pixels.
How should I store those? None of the image types I could
see is big enough to handle this. Should I create a new
"RGBf" (or whatever) image type?

In Storage.c this might look like:

	...
	} else if (strcmp(mode, "RGBf") == 0) {
		/* 3x32-bit floating point images */
		im->bands = 3;
		im->pixelsize = 12; /* ?? */
		im->linesize = xsize * 3
		im->type = IMAGING_TYPE_FLOAT32;
	} ...


In Image.py, _MODEINFO would get an additional entry:

	"RGBf": ("RGB", "F", ("R", "G", "B")),

Did I miss anything that would make this break?
Is there a way to get the same effect without messing with
the PIL sources?

The obvious idea to convert the image data to true color
RGB before storing it is not an option, since I need
the real radiance values, so I can adjust the display
for exposure, and for analysis of the derived luminance
values. The data format I need is *not* intended for
being displayed directly, but will need some conversion
to any of the standard types before that.

This conversion is normally not of the kind of what Filter.c
does, but would be closer to the stuff in Convert.c, though
with a slight difference. The conversions I need usually take
one or more arguments, in the simplest case just an exposure
and a gamma value, but also some more advanced parameters
for adapting the new image in a way that mimicks the way the
human perception would represent the simulated scene in reality.

Since the filter protocol only seems to support matrixes,
and I can't see any way yet to supply additional arguments
to a simple format conversion, where should I look?
Would I have to create completely new interfaces or
am I missing some other possibility? The approach taken by
the enhance classes is only partly helpful, since most
of the needed operations can't be easily represented as
inter/extrapolations.

Could I modify the pixel access routines of my RGBf image,
so that the image object can be configured for the needed
conversions, spitting out the final RGB values as desired
for any combination of parameters?
This could mean to say:
   im.gamma = 2.4
   im.exposure = 2
   new_image = im.convert('RGB')
And the special 'RGBf' image would know how to convert its
radiance values to luminances in the RGB color space given
those settings. Does this make any kind of sense to try?

It may be obvious by now, that I am a bit lost in the dark
here, which is a disastrous feeling for a lighting designer!
I'd appreciate it very much if anyone could shed some light
ont those matters. The result of my struggling will be
contributed straight back into PIL (assuming that my output
passes the pythonware quality checks, which may not be
garanteed yet... ;).


Thanks a lot for your time.

-schorsch

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