Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Good one!</p> <h3>First step:</h3> <p>Compute the size of the rectangle</p> <pre><code> width = sqrt( sum( (b-a).^2 ) ); height = sqrt( sum( (c-b).^2 ) ); </code></pre> <h3>Second step:</h3> <p>Compute an affine transformation from <code>a</code>...<code>d</code> to an upright image</p> <pre><code> Xin = [a(2) b(2) c(2) d(2)]; Yin = [a(1) b(1) c(1) d(1)]; Xout = [width 1 1 width]; Yout = [1 1 height height]; A = [Xin;Yin;ones(1,4)]'; B = [Xout; Yout]'; H = B \ A; % affine transformation </code></pre> <p>Note that despite the fact that we allow fo <code>H</code> to be affine, the choise of corners (depending on <code>width</code> and <code>height</code>) will acertain that <code>H</code> will not distort the cropped rectangle.</p> <p>optionally use <a href="http://www.mathworks.com/help/images/ref/cp2tform.html" rel="nofollow"><code>cp2tform</code></a>:</p> <pre><code> H2 = cp2tform( [Xin;Yin]', [Xout;Yout]', 'nonreflectivesimilarity' ); </code></pre> <h3>Third step</h3> <p>Use the transformation to get the relevant image part</p> <pre><code> thumb = tformarray( img, maketform( 'affine', H' ), ... %//' makeresampler( 'cubic', 'fill' ), ... 1:2, 1:2, ceil( [height width] ), [], 0 ); </code></pre> <p>optionally use <a href="http://www.mathworks.com/help/images/ref/imtransform.html" rel="nofollow"><code>imtransform</code></a>:</p> <pre><code> thumb = imtransform( img, H2, 'bicubic' ); </code></pre> <hr> <h3>A note regarding vectorization:</h3> <p>depends on how the coordinates of the corners are stored (<code>a</code>...<code>d</code>) the first two steps can be easily vectorize.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload