Gain compensation values making the panorama image bad
I have implemented the Gain Compensation algorithm as mentioned in the paper Automatic Panoramic Image Stitching using Invariant Features. The derivation looks fine, here is the attached one for reference: