pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

globalbalance - bug?

Open bsdis opened this issue 6 years ago • 4 comments

I am mosaicing (i also tried merge) 2 images and then i want to do globalcontrast:

right = pyvips.Image.rawload(f'{r}/[0017][0015].dump',1920,1200,2).copy(bands=1, format="ushort", interpretation="b-w")<< 6
left = pyvips.Image.rawload(f'{r}/[0017][0016].dump',1920,1200,2).copy(bands=1, format="ushort", interpretation="b-w")<< 6
join = left.mosaic(right, "horizontal", M2.width - 102, 0, 0, 0,harea=15, bandno=0)
balance = join.globalbalance()
balance.pngsave('merged.png')

But it seems that no matter i do i get:

Error: unable to call globalbalance
  im_global_balance: unable to open "temp-6356"

What is going wrong here?

bsdis avatar Jul 25 '19 23:07 bsdis

It's just the way globalbalance works. Images have to come from files that it can reopen, so they need to be tiff / vips / png sources, something like that.

jcupitt avatar Jul 25 '19 23:07 jcupitt

ok - so if i have raw sources it will not work? I tried changing my sources to tiff - and then i dont get the error. I can then actually also merge them and still looks okay (except for the brightness difference in the tiles), but if I use the globalbalance now I just get a blank image (no errors). Am I doing something wrong?

Here is the code:

right = pyvips.Image.tiffload(f'{r}/[0017][0015].tiff')
left  = pyvips.Image.tiffload(f'{r}/[0017][0016].tiff')
join = left.merge(right,'horizontal',1920-102,0,mblend=100)
balance = join.globalbalance()
balance.tiffsave('merged.tiff')

(Also - how do I choose a suitable mblend value?)

bsdis avatar Jul 26 '19 04:07 bsdis

Ok, i managed to make it work, but for some reason the globalbalance is not doing what i expected it will do. Seems like tiles are still varying levels of brightness for some reason.

Screen Shot 2019-07-26 at 11 27 25

Here is how i did

bimg = None
for i in [19,18,17,16]:
    rowtile = None
    for j in [17,16,15,14]:
        fn = f'{r}/[{str(i).zfill(4)}][{str(j).zfill(4)}].tiff'
        tile = pyvips.Image.tiffload(fn)
        rowtile = tile if not rowtile else rowtile.merge(tile, "horizontal",1920-102,0,mblend=-1)
    bimg = rowtile if not bimg else rowtile.merge(bimg, "vertical",0,1200-119,mblend=-1)
balance = bimg.globalbalance()
balance.pngsave('merged.png')

Am I doing something wrong here?

bsdis avatar Jul 26 '19 09:07 bsdis

You've not fixed your vignetting -- global balance just adjusts the overall brightness of tiles, it won't be able to adjust pixel by pixel.

You could possibly take lens-cap black too. It would also be worth testing your camera gamma -- is it sRGB or linear?

jcupitt avatar Jul 26 '19 10:07 jcupitt