def ImageBufWeight(weight, inputBuffer, gamma=0.75, clip=0.05, lut=None): ''' Apply a bell / triangular weight function to an Image Buffer ''' (channelType, width, height, channels, orientation, metadata, inputSpec) = ImageAttributes(inputBuffer) temp = ImageBufMakeConstant(width, height, channels, oiio.HALF) grey05 = ImageBufMakeConstant(width, height, channels, oiio.HALF, tuple([0.5] * channels)) if lut: ImageBufAlgo.add(temp, temp, inputBuffer) if 1 in lut: ImageBufAlgo.clamp(temp, temp, tuple([0.5] * channels), tuple([1.0] * channels)) if 2 in lut: ImageBufAlgo.clamp(temp, temp, tuple([0.0] * channels), tuple([0.5] * channels)) #print( "\tLUT application : %s" % result ) ImageBufAlgo.absdiff(temp, grey05, temp) else: ImageBufAlgo.absdiff(temp, grey05, inputBuffer) ImageBufAlgo.sub(temp, grey05, temp) ImageBufAlgo.div(temp, temp, 0.5) ImageBufAlgo.sub(temp, temp, clip) ImageBufAlgo.mul(temp, temp, 1.0 / (1.0 - clip)) ImageBufAlgo.clamp(temp, temp, tuple([0.0] * channels), tuple([1.0] * channels)) ImageBufAlgo.pow(weight, temp, gamma)
def ImageBufWeight(weight, inputBuffer, gamma=0.75, clip=0.05, lut=None): ''' Apply a bell / triangular weight function to an Image Buffer ''' (channelType, width, height, channels, orientation, metadata, inputSpec) = ImageAttributes(inputBuffer) temp = ImageBufMakeConstant(width, height, channels, oiio.HALF ) grey05 = ImageBufMakeConstant(width, height, channels, oiio.HALF, tuple([0.5]*channels) ) if lut: ImageBufAlgo.add(temp, temp, inputBuffer) if 1 in lut: ImageBufAlgo.clamp(temp, temp, tuple([0.5]*channels), tuple([1.0]*channels)) if 2 in lut: ImageBufAlgo.clamp(temp, temp, tuple([0.0]*channels), tuple([0.5]*channels)) #print( "\tLUT application : %s" % result ) ImageBufAlgo.absdiff(temp, grey05, temp) else: ImageBufAlgo.absdiff(temp, grey05, inputBuffer) ImageBufAlgo.sub(temp, grey05, temp) ImageBufAlgo.div(temp, temp, 0.5) ImageBufAlgo.sub(temp, temp, clip) ImageBufAlgo.mul(temp, temp, 1.0/(1.0-clip)) ImageBufAlgo.clamp(temp, temp, tuple([0.0]*channels), tuple([1.0]*channels)) ImageBufAlgo.pow(weight, temp, gamma)
b = ImageBuf() ImageBufAlgo.sub( b, make_constimage(64, 64, 3, oiio.HALF, (.1, .2, .3)), make_constimage(64, 64, 3, oiio.HALF, (.1, .1, .1), 20, 20)) write(b, "sub.exr") # Test --absdiff and --abs # First, make a test image that's 0.5 on the left, -0.5 on the right a = ImageBuf(ImageSpec(128, 128, 3, oiio.HALF)) ImageBufAlgo.fill(a, (0.5, 0.5, 0.5)) ImageBufAlgo.fill(a, (-0.25, -0.25, -0.25), oiio.ROI(0, 64, 0, 128)) b = ImageBuf() ImageBufAlgo.abs(b, a) write(b, "abs.exr", oiio.HALF) b = ImageBuf() ImageBufAlgo.absdiff(b, a, (0.2, 0.2, 0.2)) write(b, "absdiff.exr", oiio.HALF) a = ImageBuf() # mul b = ImageBuf() ImageBufAlgo.mul(b, gray128, 1.5) write(b, "cmul1.exr") b = ImageBuf() ImageBufAlgo.mul(b, gray128, (1.5, 1, 0.5)) write(b, "cmul2.exr") # FIXME -- image multiplication; it's not in testsuite/oiiotool either # b = ImageBuf() # ImageBufAlgo.mul (b, make_constimage(64,64,3,oiio.HALF,(.1,.2,.3)), # make_constimage(64,64,3,oiio.HALF,(.1,.1,.1),20,20)) # write (b, "mul.exr")
# sub b = ImageBuf() ImageBufAlgo.sub (b, make_constimage(64,64,3,oiio.HALF,(.1,.2,.3)), make_constimage(64,64,3,oiio.HALF,(.1,.1,.1),20,20)) write (b, "sub.exr") # Test --absdiff and --abs # First, make a test image that's 0.5 on the left, -0.5 on the right a = ImageBuf (ImageSpec(128,128,3,oiio.HALF)) ImageBufAlgo.fill (a, (0.5,0.5,0.5)) ImageBufAlgo.fill (a, (-0.25,-0.25,-0.25), oiio.ROI(0,64,0,128)) b = ImageBuf() ImageBufAlgo.abs (b, a) write (b, "abs.exr", oiio.HALF) b = ImageBuf() ImageBufAlgo.absdiff (b, a, (0.2,0.2,0.2)) write (b, "absdiff.exr", oiio.HALF) a = ImageBuf() # mul b = ImageBuf() ImageBufAlgo.mul (b, gray128, 1.5) write (b, "cmul1.exr") b = ImageBuf() ImageBufAlgo.mul (b, gray128, (1.5,1,0.5)) write (b, "cmul2.exr") b = ImageBuf() ImageBufAlgo.mul (b, make_constimage(64,64,3,oiio.HALF,(.5,.5,.5)), make_constimage(64,64,3,oiio.HALF,(1.5,1,0.5))) write (b, "mul.exr", oiio.HALF)
write(b, "add.exr") # sub b = ImageBufAlgo.sub( make_constimage(64, 64, 3, oiio.HALF, (.1, .2, .3)), make_constimage(64, 64, 3, oiio.HALF, (.1, .1, .1), 20, 20)) write(b, "sub.exr") # Test --absdiff and --abs # First, make a test image that's 0.5 on the left, -0.5 on the right a = ImageBuf(ImageSpec(128, 128, 3, oiio.HALF)) ImageBufAlgo.fill(a, (0.5, 0.5, 0.5)) ImageBufAlgo.fill(a, (-0.25, -0.25, -0.25), oiio.ROI(0, 64, 0, 128)) b = ImageBufAlgo.abs(a) write(b, "abs.exr", oiio.HALF) b = ImageBufAlgo.absdiff(a, (0.2, 0.2, 0.2)) write(b, "absdiff.exr", oiio.HALF) a = ImageBuf() # mul b = ImageBufAlgo.mul(gray128, 1.5) write(b, "cmul1.exr") b = ImageBufAlgo.mul(gray128, (1.5, 1, 0.5)) write(b, "cmul2.exr") b = ImageBufAlgo.mul(make_constimage(64, 64, 3, oiio.HALF, (.5, .5, .5)), make_constimage(64, 64, 3, oiio.HALF, (1.5, 1, 0.5))) write(b, "mul.exr", oiio.HALF) # mad b = ImageBufAlgo.mad( make_constimage(64, 64, 3, oiio.HALF, (.5, .5, .5)),
make_constimage(64,64,3,oiio.HALF,(.1,.1,.1),20,20)) write (b, "add.exr") # sub b = ImageBufAlgo.sub (make_constimage(64,64,3,oiio.HALF,(.1,.2,.3)), make_constimage(64,64,3,oiio.HALF,(.1,.1,.1),20,20)) write (b, "sub.exr") # Test --absdiff and --abs # First, make a test image that's 0.5 on the left, -0.5 on the right a = ImageBuf (ImageSpec(128,128,3,oiio.HALF)) ImageBufAlgo.fill (a, (0.5,0.5,0.5)) ImageBufAlgo.fill (a, (-0.25,-0.25,-0.25), oiio.ROI(0,64,0,128)) b = ImageBufAlgo.abs (a) write (b, "abs.exr", oiio.HALF) b = ImageBufAlgo.absdiff (a, (0.2,0.2,0.2)) write (b, "absdiff.exr", oiio.HALF) a = ImageBuf() # mul b = ImageBufAlgo.mul (gray128, 1.5) write (b, "cmul1.exr") b = ImageBufAlgo.mul (gray128, (1.5,1,0.5)) write (b, "cmul2.exr") b = ImageBufAlgo.mul (make_constimage(64,64,3,oiio.HALF,(.5,.5,.5)), make_constimage(64,64,3,oiio.HALF,(1.5,1,0.5))) write (b, "mul.exr", oiio.HALF) # mad b = ImageBufAlgo.mad (make_constimage(64,64,3,oiio.HALF,(.5,.5,.5)), make_constimage(64,64,3,oiio.HALF,(1.5,1,0.5)),