I did some more thinking on this and here is my new
opinion on questions from previous mails and a
potential solution:

1. How many channels should the result image have?

Look at this image: http://postimage.org/image/6zokq0ha3/.
Notice that A, B and C have different number of channels,
and channels are selected in arbitrary ways. This would
allow you to take the R channel from some RGB image and
the G channel from another, apply some operation, and store
the result in arbitrary channel in R.

I think the image processing operation should not modify the
number of channels in R, the caller should set that properly.
The image processing operation only takes some input
channels, computes output and stores it in some channel/s in R.

2. Should there be one main function that could take any image
processing operation and apply it selectively to some channels?
In other words, should there be one function that will coordinate
the work with channels masks.

Such function would also need to loop over all pixels and
all channels and call the image processing function in the
innermost loop. No need for that extra complexity.

3. Make ImageBuf iterators aware of channels masks?

Could be done, but I suggest a simpler solution.

4. Example solution for a simple operation:

https://github.com/StefanStavrev/oiio/commit/61f7013f5756018d04c3104b7d87a319b2ff719e

The main thing to notice is that the two loops for looping
over pixels and channels are swapped. What I have is:

foreach channel
    foreach pixel

rather than:

foreach pixel
    foreach channel

Much more efficient to first figure out which channels to
operate on based on the mask, and then loop over
all pixels for that channel.

The mask used in that example {0, 0, 0, 1, 1, 1, 2 ,2 ,2} means:
0, 0, 0 - apply multiply on channel 0 in input images A and B and
              store the result in channel 0 in output image R.
Same reasoning for 1,1,1 and 2,2,2.
A triplet 1,2,0 in this case would mean, apply multiply operation
on channels 1 and 2 from input images A and B, and store the
result in channel 0 in R.

5. Finally, let me point out that not all operations can
be used with channels masks. Well, not in a simple way.
The operations my example code represents, are those
that need only one channel from each input image in order
to produce one result channel.


Stefan
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to