Python's cv2.warpAffine() & MATLAB's imwarp()

I am currently trying to replicate the process of warping an image in Python in MATLAB. I am currently able to use MATLAB's imwarp() to match my warp image in Python that used cv2.warpAffine(). When I look at my tiff files in Python, MATLAB, or imageJ, the two images look the same. But, when I do a more in-depth look at the grayscale values, the grayscale values do not match.
My goal is to warp an image in MATLAB that has the same grayscale values as my warpped Python image. Has anyone come across this issue and know of any solutions to fix the issue.
Bellow are some of the built in functions that I have utilizing in Python & MATLAB.
% Python Code
cv2.getRotationMatrix2D()
cv2.warpAffine()
% MATLAB Code
affine2d()
imref2d()
imwarp()

2 commentaires

Matt J
Matt J le 17 Juin 2026 à 20:56
Modifié(e) : Matt J le 17 Juin 2026 à 21:22
What's the relative magnitude of the difference? Could it just be floating point noise?
What have you done to align the various inputs (e.g. interpolation method, OutputView, etc...)
Raag
Raag le 23 Juin 2026 à 5:34
Hi Greg,
It is my understanding that you are comparing image warping results between Python (OpenCV 'warpAffine') and MATLAB 'imwarp', and observing that while the visual outputs look similar, the underlying grayscale values differ.
I recommend ensuring that the transformation parameters and interpolation settings are aligned across both environments. Differences in results can arise due to:
  • Interpolation method
  • Coordinate system conventions
  • Output grid definition
  • Data type and scaling
  • Border handling / padding strategy
Since even small mismatches here can lead to pixel intensity differences, try explicitly setting the interpolation method and output reference frame in MATLAB to match OpenCV behaviour. Also, comparing results in double precision can help isolate whether differences are due to rounding or interpolation.
You can refer to the following documentations for more information:
  1. imwarp: https://www.mathworks.com/help/images/ref/imwarp.html
  2. affine2d: https://www.mathworks.com/help/images/ref/affine2d.html

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 17 Juin 2026 à 14:40

Commenté :

le 23 Juin 2026 à 5:34

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by