Alpha channel/object matte

Hi Folks,

Is there a straightforward way to generate alpha channel or object matte 8 bit grayscale images in radiance for compositing purposes?

Thanks,

kirk

Kirk Thibault wrote:

Hi Folks,

Is there a straightforward way to generate alpha channel or object matte 8 bit grayscale images in radiance for compositing purposes?

Hi Kirk,

At least not automatically by rpict itself. rayshade (and likely others raytracers too) generate an optional alpha channel, and I nagged Greg to add an optional fourth channel to the image format in ( - hang on, a quick seach in my mail folders..) June 1993. That never made it, since a change of format would have produced various nasty side effects. The main reason for my wish was to paste the image into existing (tpically outside) scenery easily. With fisheye HDRs being on-vogue now, surrounding the model with an HDR source-primitive is a better way to solve that merging problem.

So, you'll have to generate a z-file (-z option), use the z-value to differentiate between an object hit (alpha opaque) and infinity (alpha transparent) and convert that to whatever image format you need. Suitable pcomb/pfilt/pvalue scripts are left as an exercise to the reader ...

-Peter

···

--
pab-opto, Freiburg, Germany, http://www.pab-opto.de
[see web page to check digital email signature]

Thanks for the info. I guess that means I need to know what format the "Z" file is and how the information is arranged. I generated one using the -z option of rpict and then just tried to look at it ("less") and i was given the message - "This file may be a binary file - view anyway?". I said yes and got gobbledyguck.

I also tried the strategy of rendering a background only image (this renders just the HDR image wrapped around my scene) and then a "objects" render that includes the background and the objects. If you use pcomb to take the difference between the two images, you should more or less be left with the objects only and presumably you could then do another pcomb to make the image 2 bit. I tried something like:

pcomb -s -1 background_image object_image > diff_image <<<(takes the difference between the two images)

then

pcomb -e 'ro=if(ri(1)=0,0,1);go=if(gi(1)=0,0,1;b0=if(bi(1)=0,0,1)' > matte_image

the idea being that if the pixel value in the "diff" image was 0 this would be a pixel which was the same in the background image and the object image (i.e., part of the background) versus anything else, which would be an object. This has limitations, but in general I was trying to say "if the pixel in the diff image is black, it is part of the background, keep it black, otherwise if it is not black, make it white.

Needless to say, I got a command line error saying that a ')' was expected. I'm guessing that this means i used the "if" function incorrectly within the context of pcomb, or in general. The obvious shortcoming of this crude method is that if the diff image contains a black pixel value in the object area, it will remain black and thus not be part of the object matte. Definitely not robust. The Z file info sounds like the way to go in this respect so I look forward to an explanation of how to tap into it.

Can you tell I'm learning Radiance and Unix simultaneously? :slight_smile:

Thanks folks!

kirk

···

On Nov 18, 2004, at 6:33 AM, Peter Apian-Bennewitz wrote:

Kirk Thibault wrote:

Hi Folks,

Is there a straightforward way to generate alpha channel or object matte 8 bit grayscale images in radiance for compositing purposes?

Hi Kirk,

At least not automatically by rpict itself. rayshade (and likely others raytracers too) generate an optional alpha channel, and I nagged Greg to add an optional fourth channel to the image format in ( - hang on, a quick seach in my mail folders..) June 1993. That never made it, since a change of format would have produced various nasty side effects. The main reason for my wish was to paste the image into existing (tpically outside) scenery easily. With fisheye HDRs being on-vogue now, surrounding the model with an HDR source-primitive is a better way to solve that merging problem.

So, you'll have to generate a z-file (-z option), use the z-value to differentiate between an object hit (alpha opaque) and infinity (alpha transparent) and convert that to whatever image format you need. Suitable pcomb/pfilt/pvalue scripts are left as an exercise to the reader ...

-Peter

--
pab-opto, Freiburg, Germany, http://www.pab-opto.de
[see web page to check digital email signature]

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

Hi,
I am not really sure which is your question... I missed the 1st
emails...sorry :wink:

But if I am right you are trying to create an alpha channel from a rendered
picture,

I would do this way:

1) generate your rendering: image
2) generate a mask: you can just create an image with only the object and
-av 1 1 1,
then use "pcomb -e 'vo=if(li(1),1,0)' object > mask " to create a BW image
with 0 and 1.

3) apply the mask to the 1st image:
pcomb -e 'ro=if(li(2),ri(1),0);go=if(li(2),gi(1),0);bo=if(li(2),bi(1),0)'
image mask > filtered

in general all the functions are defined in rayinit.cal, into the radiance
libs...

hope it helps/works,
giulio

···

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Kirk
Thibault
Sent: 18 November 2004 17:21
To: Radiance general discussion
Subject: Re: [Radiance-general] Alpha channel/object matte

Thanks for the info. I guess that means I need to know what format
the "Z" file is and how the information is arranged. I generated one
using the -z option of rpict and then just tried to look at it ("less")
and i was given the message - "This file may be a binary file - view
anyway?". I said yes and got gobbledyguck.

I also tried the strategy of rendering a background only image (this
renders just the HDR image wrapped around my scene) and then a
"objects" render that includes the background and the objects. If you
use pcomb to take the difference between the two images, you should
more or less be left with the objects only and presumably you could
then do another pcomb to make the image 2 bit. I tried something like:

pcomb -s -1 background_image object_image > diff_image <<<(takes the
difference between the two images)

then

pcomb -e 'ro=if(ri(1)=0,0,1);go=if(gi(1)=0,0,1;b0=if(bi(1)=0,0,1)' >
matte_image

the idea being that if the pixel value in the "diff" image was 0 this
would be a pixel which was the same in the background image and the
object image (i.e., part of the background) versus anything else, which
would be an object. This has limitations, but in general I was trying
to say "if the pixel in the diff image is black, it is part of the
background, keep it black, otherwise if it is not black, make it white.

Needless to say, I got a command line error saying that a ')' was
expected. I'm guessing that this means i used the "if" function
incorrectly within the context of pcomb, or in general. The obvious
shortcoming of this crude method is that if the diff image contains a
black pixel value in the object area, it will remain black and thus not
be part of the object matte. Definitely not robust. The Z file info
sounds like the way to go in this respect so I look forward to an
explanation of how to tap into it.

Can you tell I'm learning Radiance and Unix simultaneously? :slight_smile:

Thanks folks!

kirk

On Nov 18, 2004, at 6:33 AM, Peter Apian-Bennewitz wrote:

Kirk Thibault wrote:

Hi Folks,

Is there a straightforward way to generate alpha channel or object
matte 8 bit grayscale images in radiance for compositing purposes?

Hi Kirk,

At least not automatically by rpict itself. rayshade (and likely
others raytracers too) generate an optional alpha channel, and I
nagged Greg to add an optional fourth channel to the image format in (
- hang on, a quick seach in my mail folders..) June 1993. That never
made it, since a change of format would have produced various nasty
side effects. The main reason for my wish was to paste the image into
existing (tpically outside) scenery easily. With fisheye HDRs being
on-vogue now, surrounding the model with an HDR source-primitive is a
better way to solve that merging problem.

So, you'll have to generate a z-file (-z option), use the z-value to
differentiate between an object hit (alpha opaque) and infinity (alpha
transparent) and convert that to whatever image format you need.
Suitable pcomb/pfilt/pvalue scripts are left as an exercise to the
reader ...

-Peter

--
pab-opto, Freiburg, Germany, http://www.pab-opto.de
[see web page to check digital email signature]

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

___________________________________________________________________
Electronic mail messages entering and leaving Arup business
systems are scanned for acceptability of content and viruses.

Excellent. I'm starting to realize that there are many different ways to tackle the problem and I will try your technique. Thanks!

kirk

···

On Nov 19, 2004, at 5:48 AM, Giulio Antonutto wrote:

Hi,
I am not really sure which is your question... I missed the 1st
emails...sorry :wink:

But if I am right you are trying to create an alpha channel from a rendered
picture,

I would do this way:

1) generate your rendering: image
2) generate a mask: you can just create an image with only the object and
-av 1 1 1,
then use "pcomb -e 'vo=if(li(1),1,0)' object > mask " to create a BW image
with 0 and 1.

3) apply the mask to the 1st image:
pcomb -e 'ro=if(li(2),ri(1),0);go=if(li(2),gi(1),0);bo=if(li(2),bi(1),0)'
image mask > filtered

in general all the functions are defined in rayinit.cal, into the radiance
libs...

hope it helps/works,
giulio

Hi Kirk,

Here's my own example of image-based lighting and the commands I used. I have two processors to work with, which is why I run two renderings at the same time:

#!/bin/csh -fex

···

#
# Render our image-based lighting example
#
# Oct 2004 Greg Ward

# Set parameters
set res=(-x 2272 -y 1704)
set vw=(-vf plate.vf -pa 0)
set amb=(-ab 1 -aa 0 -ad 256 -as 0)

# Render synthetic objects
oconv environ.rad railing.rad chess3d.rad \
         > rpict -ps 1 -pj 0 $vw $res $amb \
         > chess3d.hdr &

# Determine foreground objects
oconv chess3d.rad > stencil.oct
vwrays -ff $vw $res \
         > rtrace -fff -oL $res stencil.oct \
         > pvalue -r -df -b \
         > pcomb -e 'lo=if(gi(1)-1e5,0,1)' - \
         > stencil.pic
rm stencil.oct

# Render base for shadows
oconv environ.rad railing.rad \
         > rpict -ps 1 -pj 0 $vw $res $amb \
         > unshadowed.hdr

# Wait for first render
wait

# Composite final image with shadow map and blurred foreground
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
         -e 'f(inp)=inp(1)*(gi(3) + (1-gi(3))*inp(2)/inp(4))' \
         '\!pfilt -1 -r 1.35 chess3d.hdr' \
         -o SunrisePlate.hdr \
         '\!pfilt -1 -r 1.35 stencil.pic' \
         '\!pfilt -1 -r 1.35 unshadowed.hdr' \
         > composite.hdr

---------------------
Resulting image (tone-mapped JPEG and gzip'ped input and picture files):

  http://www.anyhere.com/gward/pickup/chess3d_balcony.jpg
  http://www.anyhere.com/gward/pickup/chess2.tar.gz

Pillo's method works as well, but has problems sometimes for transparent surfaces. The -oL output of rtrace is the only truly reliable method I've found. You also need the -ps 1 -pj 0 rendering options shown to avoid disagreement between boundary pixels in the final composite. My example includes blurring of the IBL objects to simulate depth of field, which you probably don't want in general. (The pfilt -1 -r 1.35 commands in the final pcomb can be replaced by the straight files.)

-Greg

Cool - I was having issues dealing with transparent objects as I was working through my own crude solutions - will try this one too. Once again - Radiance has its own freakin functional language - nice! What a ton I have to learn!

kirk

···

On Nov 19, 2004, at 12:17 PM, Greg Ward wrote:

Hi Kirk,

Here's my own example of image-based lighting and the commands I used. I have two processors to work with, which is why I run two renderings at the same time:

#!/bin/csh -fex
#
# Render our image-based lighting example
#
# Oct 2004 Greg Ward

# Set parameters
set res=(-x 2272 -y 1704)
set vw=(-vf plate.vf -pa 0)
set amb=(-ab 1 -aa 0 -ad 256 -as 0)

# Render synthetic objects
oconv environ.rad railing.rad chess3d.rad \
        > rpict -ps 1 -pj 0 $vw $res $amb \
        > chess3d.hdr &

# Determine foreground objects
oconv chess3d.rad > stencil.oct
vwrays -ff $vw $res \
        > rtrace -fff -oL $res stencil.oct \
        > pvalue -r -df -b \
        > pcomb -e 'lo=if(gi(1)-1e5,0,1)' - \
        > stencil.pic
rm stencil.oct

# Render base for shadows
oconv environ.rad railing.rad \
        > rpict -ps 1 -pj 0 $vw $res $amb \
        > unshadowed.hdr

# Wait for first render
wait

# Composite final image with shadow map and blurred foreground
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
        -e 'f(inp)=inp(1)*(gi(3) + (1-gi(3))*inp(2)/inp(4))' \
        '\!pfilt -1 -r 1.35 chess3d.hdr' \
        -o SunrisePlate.hdr \
        '\!pfilt -1 -r 1.35 stencil.pic' \
        '\!pfilt -1 -r 1.35 unshadowed.hdr' \
        > composite.hdr

---------------------
Resulting image (tone-mapped JPEG and gzip'ped input and picture files):

  http://www.anyhere.com/gward/pickup/chess3d_balcony.jpg
  http://www.anyhere.com/gward/pickup/chess2.tar.gz

Pillo's method works as well, but has problems sometimes for transparent surfaces. The -oL output of rtrace is the only truly reliable method I've found. You also need the -ps 1 -pj 0 rendering options shown to avoid disagreement between boundary pixels in the final composite. My example includes blurring of the IBL objects to simulate depth of field, which you probably don't want in general. (The pfilt -1 -r 1.35 commands in the final pcomb can be replaced by the straight files.)

-Greg

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

I am bowing to the Supreme...
;-))

···

-----Original Message-----
From: Greg Ward [mailto:[email protected]]
Sent: 19 November 2004 17:18
To: Radiance general discussion
Subject: Re: [Radiance-general] Alpha channel/object matte

Hi Kirk,

Here's my own example of image-based lighting and the commands I used.
I have two processors to work with, which is why I run two renderings
at the same time:

#!/bin/csh -fex
#
# Render our image-based lighting example
#
# Oct 2004 Greg Ward

# Set parameters
set res=(-x 2272 -y 1704)
set vw=(-vf plate.vf -pa 0)
set amb=(-ab 1 -aa 0 -ad 256 -as 0)

# Render synthetic objects
oconv environ.rad railing.rad chess3d.rad \
         > rpict -ps 1 -pj 0 $vw $res $amb \
         > chess3d.hdr &

# Determine foreground objects
oconv chess3d.rad > stencil.oct
vwrays -ff $vw $res \
         > rtrace -fff -oL $res stencil.oct \
         > pvalue -r -df -b \
         > pcomb -e 'lo=if(gi(1)-1e5,0,1)' - \
         > stencil.pic
rm stencil.oct

# Render base for shadows
oconv environ.rad railing.rad \
         > rpict -ps 1 -pj 0 $vw $res $amb \
         > unshadowed.hdr

# Wait for first render
wait

# Composite final image with shadow map and blurred foreground
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
         -e 'f(inp)=inp(1)*(gi(3) + (1-gi(3))*inp(2)/inp(4))' \
         '\!pfilt -1 -r 1.35 chess3d.hdr' \
         -o SunrisePlate.hdr \
         '\!pfilt -1 -r 1.35 stencil.pic' \
         '\!pfilt -1 -r 1.35 unshadowed.hdr' \
         > composite.hdr

---------------------
Resulting image (tone-mapped JPEG and gzip'ped input and picture files):

  http://www.anyhere.com/gward/pickup/chess3d_balcony.jpg
  http://www.anyhere.com/gward/pickup/chess2.tar.gz

Pillo's method works as well, but has problems sometimes for
transparent surfaces. The -oL output of rtrace is the only truly
reliable method I've found. You also need the -ps 1 -pj 0 rendering
options shown to avoid disagreement between boundary pixels in the
final composite. My example includes blurring of the IBL objects to
simulate depth of field, which you probably don't want in general.
(The pfilt -1 -r 1.35 commands in the final pcomb can be replaced by
the straight files.)

-Greg

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

___________________________________________________________________
Electronic mail messages entering and leaving Arup business
systems are scanned for acceptability of content and viruses.

The functional language in Radiance probably falls into the "write-only" category, because it's so difficult to comprehend what's been written. I probably spend more time trying to figure out what I did later than I spent doing things in the first place with it. Oh, well. At least it was easy to code....

-Greg

···

From: Kirk Thibault <[email protected]>
Date: November 19, 2004 9:35:52 AM PST

Cool - I was having issues dealing with transparent objects as I was working through my own crude solutions - will try this one too. Once again - Radiance has its own freakin functional language - nice! What a ton I have to learn!

kirk

It was frustratingly hilarious trying to reverse engineer the "if" statement in the pcomb manual example that draws the dot. I tried several times to put a conditional statement in the "if "like,'if(ri(1)<0.05,0,1)' and kept getting errors associated with a ')' expected. Finally I realized that the condition was an expression implicitly compared to 0. Then i realized that there was a built-in functional language and that this was not standard Unix syntax. Then I realized there were whole reference sections devoted to the functional language in the book and on the website. The knowledge base just keeps expanding... too bad my little brain can't oftentimes keep up. Thankfully this forum is here and I hope I am not testing people's patience with my inane questions. Thanks folks.

kirk

···

On Nov 19, 2004, at 12:41 PM, Greg Ward wrote:

The functional language in Radiance probably falls into the "write-only" category, because it's so difficult to comprehend what's been written. I probably spend more time trying to figure out what I did later than I spent doing things in the first place with it. Oh, well. At least it was easy to code....

-Greg

From: Kirk Thibault <[email protected]>
Date: November 19, 2004 9:35:52 AM PST

Cool - I was having issues dealing with transparent objects as I was working through my own crude solutions - will try this one too. Once again - Radiance has its own freakin functional language - nice! What a ton I have to learn!

kirk

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general

Kirk Thibault wrote:

again - Radiance has its own freakin functional language - nice! What a ton I have to learn!

Yup, yup.

Radiance is an amazing collection of tools, and its depth is only rivaled by the astonishing scope of generosity, knowledge, creativity and intellect of this Radiance user community, led by Radiance's author.

By participating on this list and attending a couple of the Workshops, I have achieved a general understanding of how to use this most wondorous tool, Radiance. As an added bonus -- and more importantly -- I have also gained some very good friends.

Welcome, have fun, share, etcetera and so forth.

Just out of interest, what brings you to the Radiance world? Research, lighting design, sustainability? Art? This list attracts all kinds. How did you find us, and what are you doing with Radiance?

···

-------------------
    Rob Guglielmetti
www.rumblestrip.org

Rob-

I'm a biomechanical engineer who, for my job and as a hobby, has been into 3d graphics, modeling, etc. for a while. I primarily use Light Wave and started getting into global illumination techniques in Light Wave and the use of HDR images about 6 months ago. I found Paul Debevec's site and learned a lot about image-based lighting techniques - on his site and in his work he frequently cites and uses Radiance. Once I realized the limitations of Light Wave wrt image-based lighting, i started looking into Radiance. Wow. The differences are obvious, even to a new user like me. Learning Radiance has made me very acutely aware of the fact that I wasn't really thinking about the physics and quantitative aspects of my modeling and rendering when using LightWave, more just concentrating on the rendered output. With Radiance, considering the physical aspects of light and its interaction with objects, etc. gives me a while new appreciation for composing a scene, rendering it and compositing it. The fact that the Radiance environment is a collection of tools in the Unix setting is a new way of problem solving for me, having been used to a single package that does it all. Understanding the tools and the way they interact is presenting me with the steepest part of the learning curve currently, as I imagine you can appreciate. However, as I am beginning to find out, this system leads to extremely robust and flexible solution techniques. I'm a Mac user, so I really appreciate the fact that now I have an excuse to dust off and expand my Unix abilities.

I really am interested in photo-real combinations of synthetic objects and "real" photographic environments. I have been making my own "Light Probe" images and rending Radiance scenes with them - mostly just test scenes. Now I am using the context of compositing synthetic objects into "real" photographic plates as the basis for expanding my knowledge of Radiance. So, in short, it's more art-related than quantitative analysis of lighting, but i am realizing that appreciating the quantitative physical aspects of the lighting will give my scenes much more realism and robustness. The first time I emailed Greg he suggested that I join the forum - there you have it.

Besides that, I can't think of any other software I've used where I can email the author and get answers at all, let alone in a friendly and nurturing manner. That attitude is also evident in this forum's community and i really appreciate it. Thanks to all the folks on the list who have helped me already and thanks in advance to those who will answer my future questions - believe me, there will be more. :slight_smile:

kirk

···

On Nov 19, 2004, at 1:16 PM, Rob Guglielmetti wrote:

Kirk Thibault wrote:

again - Radiance has its own freakin functional language - nice! What a ton I have to learn!

Yup, yup.

Radiance is an amazing collection of tools, and its depth is only rivaled by the astonishing scope of generosity, knowledge, creativity and intellect of this Radiance user community, led by Radiance's author.

By participating on this list and attending a couple of the Workshops, I have achieved a general understanding of how to use this most wondorous tool, Radiance. As an added bonus -- and more importantly -- I have also gained some very good friends.

Welcome, have fun, share, etcetera and so forth.

Just out of interest, what brings you to the Radiance world? Research, lighting design, sustainability? Art? This list attracts all kinds. How did you find us, and what are you doing with Radiance?

-------------------
   Rob Guglielmetti
www.rumblestrip.org

_______________________________________________
Radiance-general mailing list
[email protected]
http://www.radiance-online.org/mailman/listinfo/radiance-general