Python 3D polynomial surface fit, order dependent

后端 未结 4 1142
不思量自难忘°
不思量自难忘° 2020-12-01 00:52

I am currently working with astronomical data among which I have comet images. I would like to remove the background sky gradient in these images due to the time of capture

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 01:31

    If anyone is looking for fitting a polynomial of a specific order (rather than polynomials where the highest power is equal to order, you can make this adjustment to the accepted answer's polyfit and polyval:

    instead of:

    ij = itertools.product(range(order+1), range(order+1))
    

    which, for order=2 gives [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] (aka up to a 4th degree polynomial), you can use

    def xy_powers(order):
        powers = itertools.product(range(order + 1), range(order + 1))
        return [tup for tup in powers if sum(tup) <= order]
    

    This returns [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (2, 0)] for order=2

提交回复
热议问题