Skip to content

feat: implement perspective warp #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

EscapedGibbon
Copy link
Collaborator

No description provided.

@EscapedGibbon EscapedGibbon linked an issue Jun 6, 2025 that may be closed by this pull request
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 55.55556% with 104 lines in your changes missing coverage. Please review.

Project coverage is 97.50%. Comparing base (bdfff4e) to head (9f63ba7).

Files with missing lines Patch % Lines
src/geometry/getPerspectiveWarp.ts 55.55% 104 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #484      +/-   ##
==========================================
- Coverage   98.48%   97.50%   -0.98%     
==========================================
  Files         245      246       +1     
  Lines       10035    10269     +234     
  Branches     2146     2165      +19     
==========================================
+ Hits         9883    10013     +130     
- Misses        152      256     +104     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EscapedGibbon
Copy link
Collaborator Author

Currently, there is only the test case from the issue but the implementation right now seems to be identical to the openCV implementation when nearest neighbor interpolation is used. Besides adding more test cases, should there be an option that allows the choice of interpolation?

@stropitek
Copy link
Contributor

stropitek commented Jun 6, 2025

The initial idea was to implement a function which returns a transform matrix like OpenCV does, and to use that transform matrix to create the new image using Image.transform (https://image-js.github.io/image-js-typescript/classes/Image.html#transform)

The transform method already supports choosing the interpolation method.

@EscapedGibbon
Copy link
Collaborator Author

There is a function in legacy version that calculates width and height with respect of image's aspect ratio. Is it okay to remove the function that calculates width and height to preserve ratio of the image and just specify desired width and height? openCV version doesn't have one, you need to put destination corner points there. We could do a function with 4 source points and 4 destination points.

@EscapedGibbon
Copy link
Collaborator Author

Also the transform() function currently accepts 2x3 matrices for affine transformations. Should i modify the code so that it accepts only 3x3 matrices or it should accept both, and if input matrix is 2x3 i just add another row? After all, if i understand correcly, affine transformation is perspective transformation with [0,0,1] as last matrix row

@EscapedGibbon
Copy link
Collaborator Author

After discussion with @stropitek we decided to have a getPerspectiveWarp() function that returns a 3x3 transformation matrix. transform() function will be modified to accept 3x3 matrix. If 2x3 matrix is given, it will be considered an affine transformation and additional row [0,0,1] will be added to the matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement perspective warp
2 participants