Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to global balance contrast of mosaiced image. #56

Open
shivamchaubey opened this issue Jul 25, 2018 · 6 comments
Open

How to global balance contrast of mosaiced image. #56

shivamchaubey opened this issue Jul 25, 2018 · 6 comments

Comments

@shivamchaubey
Copy link

Hello @jcupitt

I have used merge function to stitch the image. Is there any function to global balance the final mosaiced image. As you can see in the attached image contrast is not balanced in each tile.
image

I know there is a function globalbalance in pyvips but it works with only mosaiced function. Is there any way to do balancing using merge function or any other way?

@jcupitt
Copy link
Member

jcupitt commented Jul 25, 2018

Yes, global balance will work on merged images too.

You might need to run it in sections, so balance 10x10 blocks of tiles, then balance again after final assembly.

@shivamchaubey
Copy link
Author

Can you give please an example to integrate this with merge function?
My code looks like.

1. def stitch(coor):
2.     global onlyfiles,mypath,row,column
3.     onlyfiles=np.array(onlyfiles)
4.     files=onlyfiles.reshape(row,column)
5.     blend=False
6.     for r in tqdm(range(files.shape[0])):    
7.         c=0
8.         if r==0:
9.             tile = pyvips.Image.black(coor[r,c][0],coor[r,c][1])
10.         else:
11.             tile = pyvips.Image.black(coor[r,c][0],coor[r,c][1]-coor[r-1,c][1])        
12.         for c in tqdm(range(files.shape[1])): 
13.             tile1 = pyvips.Image.new_from_file(join(mypath,files[r][c]), access="sequential")
14.             if r==0:
15.                 x,y=coor[r,c]
16.             else:
17.                 x,y=coor[r,c][0],coor[r,c][1]-coor[r-1,0][1]
18.             tile = tile.merge(tile1, 'horizontal', -x, -y, mblend =blend)
19.         if r>0:
20.             y=coor[r-1,0][1]
21.             stitch_img = stitch_img.merge(tile, 'vertical', 0, -y, mblend =blend)    
22.         else :
23.             stitch_img=tile
24.     print (stitch_img.width,stitch_img.height,"width","height")        
25.     stitch_img.dzsave('test_80X80')

I have tried inserting tile=tile.globalbalance() at line number 19 for adjacent contrast adjustment , and also stitch_img=stitch_img.globalbalance() at line number 22 for contrast adjustment between each row. It's not working and I am getting an error.

Error:

raise Error('unable to call {0}'.format(operation_name))
pyvips.error.Error: unable to call globalbalance
im_global_balance: unable to open "temp-0"

Please provide an example for this function.

@jcupitt
Copy link
Member

jcupitt commented Jul 26, 2018

Don't use black, it'll get confused.

You need to start from a set of images on disc, merge them together, then call globalbalance.

@shivamchaubey
Copy link
Author

How those black pixels can be ignored. I have added 255 value to those pixels but it's not working with global balance. I can't remove those black pixel area, however, I can modify them to work for global balance. What kind of modification is needed for global balance?

@jcupitt
Copy link
Member

jcupitt commented Jul 27, 2018

You don't need black to assemble a mosaic, do you? Build it without using black and globalbalance should work.

@shivamchaubey
Copy link
Author

Whenever I am using merge function, I will have some black pixels because my image is shifting in vertical direction also. So, an extra region is padded with a black pixel. I was using a black image for the first merging operation to make coordinates easy otherwise I have to make dynamic coordinates for merging operation, which is related to the input frame of reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants