3

I would like to robustly estimate a polynomial geometric transform with scikit-image skimage.transform and skimage.measure.ransac

The ransack documentation gives a very nice example of how to do exactly that but with a Similarity Transform. Here is how it goes:

from skimage.transform import SimilarityTransform
from skimage.measure import ransac
model, inliers = ransac((src, dst), SimilarityTransform, 2, 10)

I need to use skimage.transform.PolynomialTransform instead of SimilarityTransform, and I need to be able to specify the polynomial order.

But the RANSAC call takes as input the PolynomialTransform(), which does not take any input parameters. The desired polynomial order is indeed specified in the estimate attribute of PolynomialTransform()... So the RANSAC call uses the default value for the polynomial order, which is 2, while I would need a 3rd or 4th order polynomial.

I suspect it's a basic python problem? Thanks in advance!

HBouy
  • 245
  • 3
  • 14

1 Answers1

5

We could provide a mechanism in RANSAC to pass on arguments to the estimator (feel free to file a ticket). A quick workaround, however, would be:

from skimage.transform import PolynomialTransform

class PolyTF_4(PolynomialTransform):
    def estimate(*data):
        return PolynomialTransform.estimate(*data, order=4)

The PolyTF_4 class can then be passed directly to RANSAC.

HBouy
  • 245
  • 3
  • 14
Stefan van der Walt
  • 7,165
  • 1
  • 32
  • 41
  • Fantastic! I knew a simple solution of that style would be possible, but as a beginner programer I just did not know how to do it. Just one little correction: return PolynomialTransform.estimate(*data, order=4) Thank you Stefan! – HBouy Nov 19 '14 at 16:28
  • ps: I'll submit that ticket, other people could be interested in having that feature... – HBouy Nov 19 '14 at 16:30
  • No problem! Note, by the way, that you can pass keyword parameters in Python without specifying the keyword itself. I think your edit makes the example clearer, though! – Stefan van der Walt Nov 20 '14 at 14:58
  • Really? I had to add "order=" because otherwise it was complaining :-( Maybe something else was wrong... – HBouy Nov 21 '14 at 07:41
  • You are right--it's because of the use of ``*args``. – Stefan van der Walt Nov 21 '14 at 13:40