(a) (b) (c) (d)
Figure 2. Grid rotation and metrics extraction from the rotated ROI: (a)
geometry of a rectangle in a circle that keeps right angles at four
corners when the inner rectangle is rotated and reshaped within a circle
by pivoting two diagonal corners A and B, (b) a rotated
grid drawn by connecting two edge points along the horizonal (H)
and vertical (V) directions created by the number of rows
(R) and columns (C), (c) geometry of the rotated ROI, and
(d) geofencing of the rotated ROI to locate pixels only inside the ROI
for metrics extractions.
\(B\left(i_{3},j_{3}\right)=(i,\pm\sqrt{r^{2}-\left(i-a\right)^{2}}+b)\)(1)
\(D\left(i_{4},j_{4}\right)=(a+\left(a-i_{3}\right),\ b+\left(b-j_{3}\right))\)(2)
where r is a radius and the center (a, b ) of the rectangle
is defined by
\(a=\frac{i_{2}-i_{1}}{2}+i_{1}\),\(b=\frac{j_{2}-j_{1}}{2}+j_{1}\) (3)
and the circle is formulated in i -j image coordinate
system in Eq. (4).
\(j=\pm\sqrt{r^{2}-{(i-a)}^{2}}+b\) (4)
When all four corners of a rotated rectangular ROI are calculated by
Eqs. (1) and (2), a rotated grid is drawn by connecting two edge points
along the horizonal (H ) and vertical (V ) directions (Fig
2b) created by the number of rows (R ) and columns (C ) as
shown in Eqs. (5) and (6).
\(H=\left[\left(\frac{i_{4}-i_{1}}{R}\mathrm{+}i_{1}\mathrm{,\ }\frac{j_{4}-j_{1}}{R}\mathrm{+}j_{1}\right)\mathrm{,}\left(\frac{i_{2}-i_{3}}{R}\mathrm{+}i_{3}\mathrm{,\ }\frac{j_{2}-j_{3}}{R}+j_{3}\right)\right]\)(5)
\(V=\left[\left(\frac{i_{3}-i_{1}}{C}\mathrm{+}i_{1}\mathrm{,}\mathrm{\ }j_{1}-\frac{j_{1}-j_{3}}{C}\right)\mathrm{,}\left(\frac{i_{2}-i_{4}}{C}\mathrm{+}i_{4}\mathrm{,}\mathrm{\ }\mathrm{j}\mathrm{4}-\ \frac{j_{4}-j_{2}}{C}\right)\right]\)(6)
To visualize the grid rotation in GUI, the grid is validated in a full
range of the rotation angle (θ ) until the maximum angle
(θmax ) calculated by
\(\theta=\operatorname{}\left(\frac{j_{3}-j_{1}}{i_{3}-i_{1}}\right)\),\(\mathrm{\theta}_{\max}=90+\mathrm{\theta}\mathrm{\min}\) (7)
In completing the full range of the grid rotation, when the rotation
brings the corner B (i 3,j 3) crossed at (a +r , b ),
i.e., at a crossing angle (θ cross) (Eq. 8), the
sign of \(\sqrt{r^{2}-\left(i-a\right)^{2}}\) inj 3 must be reversed due to the change of the
direction from b in j -coordinate (Fig. 2a). This critical
point is detected by formulating i 3 using Eq.
(10) from the interaction of a circle (Eq. 6) and a line (Eq. 9).
\(\theta_{\text{cross}}=\operatorname{}\left(\frac{a+r-i_{1}}{b-j_{1}}\right)\)(8)
\(j=s*i+\left(j_{1}-s*i_{1}\right)\) (9)
\(i_{3}=\left[-(2K*s-2a)+sqrt\left(-{(2K*s-2a)}^{2}+4(s^{2}+1)(K^{2}-r^{2}+a^{2})\right)\right]/2(s^{2}+1)\)(10)
where s is a slop that is calculated by tan (θ ) andK is
\(K=\left(j_{1}-s*i_{1}\right)-b\) (11)
2.2 Metrics from rotated
ROI
Metrics of the rotated grid is calculated by geofencing pixels within
the rotated sub-ROIs for segmentation, filtering, masking, and
clustering. Figure 3 illustrates how the rotated ROI is positioned and
geofenced to process only pixels inside the ROI for metrics extractions.
When the grid is rotated, each rotated sub-ROI is defined with four
corners (i 1, j 1),
(i 2, j 2),
(i 3, j 3), and
(i 4, j 4) that are
intersections of the four rotated edge lines, whereas an outer upright
rectangle is formed by (i 4,j 1), (i 2,j 1), (i 2,j 3), and (i 4,j 3) (Fig. 2c). Geofencing is to register pixels
within the inner rotated ROI among all pixels in the outer rectangle.
The slop (a 1) and j -intercept
(b 1) of the first edge line
(j =a 1i +b 1)
are calculated from (i 1,j 1), (i 2,j 2) by (j 2-j 1)/(i 2 -i 1) and
(j 1-a 1i ),
respectively. When all four edge lines are similarly formulated, each
pixel is compared with four lines and selected if j -coordinate
falls within four lines. When i is plugged into the line
equations, four j -values on the lines are calculated. The pixel
(i, j ) is selected as an ROI pixel, if j falls within fourj -values ranged by a minimum and a maximum in each of vertical
(min V, max V) and
horizontal (min H, max H)
directions (Eqs. 15 and 16).
min V, max V =min(a 1*i +b 1,
a 3*i +b 3),
max(a 1*i +b 1,a 3*i +b 3) (15)
min H, max H =min(a 2*i +b 2,
a 4*i +b 4),
max(a 2*i +b 2,a 4*i +b 4) (16)
Assuming an origin at the left top corner, for instance, wheni -coordinate 1 of pixel at (1, 0) is tested with the lines,
fourth j -valuea 4+b 4 becomes a minimum in
the vertical direction which is greater than j -coordinate 0 and
makes the pixel beyond the ROI, whereas when i -coordinate 2 of
pixel at (2, 2) is tested with the lines, fourth j -value
2a 4+b 4 as a minimum is
equal to j -coordinate 2 and thus makes the pixel in the ROI (Fig.
2d).
RESULTS AND DISCUSSION
The algorithm was tested on a sample field image that contains a field
orientation misaligned with north. Open-source software, image mapping
and analytics for phenotyping (IMAP) [3], was successfully upgraded
with adaptive gridding method. Figure 3a illustrates a screenshot of the
IMAP software that demonstrates a rotated grid (10×28) in a circle and a
vegetation segmentation within the grid of 10 rows and 28 columns.
Phenotypic metrics of total 280 plots is exported to a csv file (Fig.
3b) and plotted in a graph (Fig. 3c).