Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robustly estimate Polynomial geometric transformation with scikit-image and RANSAC

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!

like image 928
HBouy Avatar asked Dec 30 '25 04:12

HBouy


1 Answers

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.

like image 72
Stefan van der Walt Avatar answered Jan 01 '26 19:01

Stefan van der Walt