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)
# 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") # pow b = ImageBuf() ImageBufAlgo.pow(b, gray128, 2) write(b, "cpow1.exr") b = ImageBuf() ImageBufAlgo.pow(b, gray128, (2, 2, 1)) write(b, "cpow2.exr") # channel_sum b = ImageBuf() ImageBufAlgo.channel_sum(b, ImageBuf("../oiiotool/tahoe-small.tif"), (0.2126, 0.7152, 0.0722)) write(b, "chsum.tif", oiio.UINT8) # premult/unpremult b = make_constimage(100, 100, 4, oiio.FLOAT, (0.1, 0.1, 0.1, 1)) ImageBufAlgo.fill(b, (0.2, 0.2, 0.2, 0.5), oiio.ROI(50, 80, 50, 80)) ImageBufAlgo.unpremult(b, b) write(b, "unpremult.tif")
# div b = ImageBuf() ImageBufAlgo.div(b, gray64, make_constimage(64, 64, 3, oiio.HALF, (2.0, 1, 0.5))) write(b, "div.exr", oiio.HALF) b = ImageBuf() ImageBufAlgo.div(b, gray64, 2.0) write(b, "divc1.exr", oiio.HALF) b = ImageBuf() ImageBufAlgo.div(b, gray64, (2.0, 1, 0.5)) write(b, "divc2.exr", oiio.HALF) # pow b = ImageBuf() ImageBufAlgo.pow(b, gray128, 2) write(b, "cpow1.exr") b = ImageBuf() ImageBufAlgo.pow(b, gray128, (2, 2, 1)) write(b, "cpow2.exr") # channel_sum b = ImageBuf() ImageBufAlgo.channel_sum(b, ImageBuf("../oiiotool/tahoe-small.tif"), (.2126, .7152, .0722)) write(b, "chsum.tif", oiio.UINT8) # premult/unpremult b = make_constimage(100, 100, 4, oiio.FLOAT, (.1, .1, .1, 1)) ImageBufAlgo.fill(b, (.2, .2, .2, .5), oiio.ROI(50, 80, 50, 80)) ImageBufAlgo.unpremult(b, b)
# div b = ImageBufAlgo.div(gray64, make_constimage(64, 64, 3, oiio.HALF, (2.0, 1, 0.5))) write(b, "div.exr", oiio.HALF) b = ImageBufAlgo.div(gray64, 2.0) write(b, "divc1.exr", oiio.HALF) b = ImageBufAlgo.div(gray64, (2.0, 1, 0.5)) write(b, "divc2.exr", oiio.HALF) # invert a = ImageBuf(OIIO_TESTSUITE_ROOT + "/oiiotool/src/tahoe-small.tif") b = ImageBufAlgo.invert(a) write(b, "invert.tif", oiio.UINT8) # pow b = ImageBufAlgo.pow(gray128, 2) write(b, "cpow1.exr") b = ImageBufAlgo.pow(gray128, (2, 2, 1)) write(b, "cpow2.exr") # channel_sum b = ImageBufAlgo.channel_sum( ImageBuf(OIIO_TESTSUITE_ROOT + "/oiiotool/src/tahoe-small.tif"), (.2126, .7152, .0722)) write(b, "chsum.tif", oiio.UINT8) # color_map b = ImageBufAlgo.color_map(tahoetiny, -1, "inferno") write(b, "colormap-inferno.tif", oiio.UINT8) b = ImageBufAlgo.color_map(tahoetiny, -1, 3, 3, (.25, .25, .25, 0, .5, 0, 1, 0, 0))
# div b = ImageBufAlgo.div (gray64, make_constimage (64, 64, 3, oiio.HALF, (2.0,1,0.5))) write (b, "div.exr", oiio.HALF) b = ImageBufAlgo.div (gray64, 2.0) write (b, "divc1.exr", oiio.HALF) b = ImageBufAlgo.div (gray64, (2.0,1,0.5)) write (b, "divc2.exr", oiio.HALF) # invert a = ImageBuf ("../oiiotool/src/tahoe-small.tif") b = ImageBufAlgo.invert (a) write (b, "invert.tif", oiio.UINT8) # pow b = ImageBufAlgo.pow (gray128, 2) write (b, "cpow1.exr") b = ImageBufAlgo.pow (gray128, (2,2,1)) write (b, "cpow2.exr") # channel_sum b = ImageBufAlgo.channel_sum (ImageBuf("../oiiotool/src/tahoe-small.tif"), (.2126,.7152,.0722)) write (b, "chsum.tif", oiio.UINT8) # color_map b = ImageBufAlgo.color_map (tahoetiny, -1, "inferno") write (b, "colormap-inferno.tif", oiio.UINT8) b = ImageBufAlgo.color_map (tahoetiny, -1, 3, 3, (.25,.25,.25,0,.5,0,1,0,0)) write (b, "colormap-custom.tif", oiio.UINT8)