Eric-Canas / Homography.js

Lightweight, High-Performance and easy-to-use library for performing Affine, Projective or Piecewise Affine transformations over any Image or HTMLElement from only a set of reference points. In Javascript.
MIT License
51 stars 8 forks source link

extract tile (output image cropped to destiny points) #4

Open jcphill opened 1 year ago

jcphill commented 1 year ago

I would like to extract a rectangular tile from a source image via a projective transformation based on mapping the corners of the tile to points in the source image, i.e., destiny points [[0, 0], [0, h], [w, 0], [w, h]].

The current implementation will return an output image that contains the entire input image with dimensions based on the input image dimensions. What I want is a output image of h rows by w pixels that matches the bounding box of the destiny points.

This behavior is already provided for piecewise affine transformations by the second case of _induceBestObjectiveWidthAndHeight() at https://github.com/Eric-Canas/Homography.js/blob/1200c41d713cc40007b3b71c8ab9b4214d837e84/Homography.js#L706C1-L710

Xiione commented 3 months ago

I need this as well!

Xiione commented 3 months ago

I made a fork and copied some lines to the behavior for projective and affine transformations. There is some repeated code, but this should make it so that the output is properly cropped. This doesn't affect the behavior of transformHTMLElement, though. https://github.com/Xiione/Homography.js