Pixel Iterator


max.shooster@...
 

Hi! I am writing an application in Python. I have a function that normalizes pixel values in an image to ensure the values do not exceed 1 or are below 0. At the moment I am using OpenImageIO's get_pixels() and set_pixels(), but it is very slow. Are there any pixel iterators in OCIO that may have better performance?
 
Thanks!


Larry Gritz
 

Not sure if maybe this was meant for the OIIO list rather than OCIO, but if you already have OpenImageIO in the mix, then I think you can very efficiently do this using a combination of ImageBufAlgo.computePixelStats (to find the per-channel min and max values) and ImageBufAlgo.contrast_remap (to stretch the input range to [0,1]).

I guess, actually, I'm not sure from your description whether you want to normalize (stretch or shrink the range to [0,1]) or simply to clamp (make sure no values are outside [0,1] but not change any values that were already ok). If you really meant clamping, then there is also ImageBufAlgo.clamp should do what you want.


On Aug 12, 2022, at 11:16 AM, max.shooster@... wrote:

Hi! I am writing an application in Python. I have a function that normalizes pixel values in an image to ensure the values do not exceed 1 or are below 0. At the moment I am using OpenImageIO's get_pixels() and set_pixels(), but it is very slow. Are there any pixel iterators in OCIO that may have better performance?
 
Thanks!

--
Larry Gritz






max.shooster@...
 

Great, thanks!


max.shooster@...
 

I am just trying to clamp the values so they do not go outside of the range 0 to 1. I tried using ImageBufAlgo.clamp() but it does not seem to clamp all of the pixel values. In particular, the blue channel seems to not be affected by this clamp call.
This is the call I run: oiio.ImageBufAlgo.clamp(imgBuf, imgBuf, min=0, max=1, clampalpha01=True).


Larry Gritz
 

That doesn't sounds right.

Max, can you forward me an example image (that is safe to share) and the shortest possible python script that reproduces the problem?

Let's transfer this discussion to the oiio-dev mail list, we don't need to make noise on ocio-dev.


On Aug 12, 2022, at 2:24 PM, max.shooster@... wrote:

I am just trying to clamp the values so they do not go outside of the range 0 to 1. I tried using ImageBufAlgo.clamp() but it does not seem to clamp all of the pixel values. In particular, the blue channel seems to not be affected by this clamp call.
This is the call I run: oiio.ImageBufAlgo.clamp(imgBuf, imgBuf, min=0, max=1, clampalpha01=True).

--
Larry Gritz