Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

feat: implement perspective warp#484

Merged
EscapedGibbon merged 17 commits into
mainfrom
461-implement-perspective-warp
Jun 24, 2025
Merged

feat: implement perspective warp#484
EscapedGibbon merged 17 commits into
mainfrom
461-implement-perspective-warp

Conversation

@EscapedGibbon

Copy link
Copy Markdown
Collaborator

No description provided.

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

codecov Bot commented Jun 6, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.66%. Comparing base (798d40d) to head (f0dae9b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #484      +/-   ##
==========================================
+ Coverage   98.62%   98.66%   +0.03%     
==========================================
  Files         244      246       +2     
  Lines       10347    10645     +298     
  Branches     2141     2170      +29     
==========================================
+ Hits        10205    10503     +298     
  Misses        142      142              

☔ 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
Copy Markdown
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

stropitek commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@EscapedGibbon EscapedGibbon force-pushed the 461-implement-perspective-warp branch from 056803f to 04520ab Compare June 13, 2025 12:42
@EscapedGibbon EscapedGibbon marked this pull request as ready for review June 16, 2025 23:31
@EscapedGibbon EscapedGibbon force-pushed the 461-implement-perspective-warp branch from 073c889 to be89641 Compare June 17, 2025 06:48

@stropitek stropitek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the script which generated the images transformed by opencv to generate.py?


What are the new exported APIs? It does not seem that you export the new functionalities.

Comment thread src/geometry/getPerspectiveWarp.ts
@EscapedGibbon EscapedGibbon force-pushed the 461-implement-perspective-warp branch from 57e7b56 to e03ad0b Compare June 23, 2025 14:17
@EscapedGibbon EscapedGibbon force-pushed the 461-implement-perspective-warp branch 2 times, most recently from 3c38dcb to d77815e Compare June 23, 2025 15:57
@EscapedGibbon EscapedGibbon force-pushed the 461-implement-perspective-warp branch from 38b9a28 to 193a8d8 Compare June 23, 2025 16:10
Comment thread src/geometry/getPerspectiveWarp.ts Outdated
Comment thread src/geometry/getPerspectiveWarp.ts Outdated
Comment thread test/img/opencv/generate.py
@EscapedGibbon EscapedGibbon force-pushed the 461-implement-perspective-warp branch from 85bef08 to 2469e0c Compare June 24, 2025 08:07
@EscapedGibbon EscapedGibbon merged commit 1a96bf3 into main Jun 24, 2025
11 checks passed
@EscapedGibbon EscapedGibbon deleted the 461-implement-perspective-warp branch June 24, 2025 08:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement perspective warp

2 participants