Ukrainian Journal of Ecology
Ukrainian Journal of Ecology, 2018, 8(4), 195-204
RESEARCH ARTICLE
Usage of the iterative photo-computing method in specifying of bird
egg radiuses curvature
I.S. Mytiai 1, A.V. Matsyura2
1 National University of Life and Environmental Science of Ukraine, GeneralRodimtsevSt. 19, block 1, Kyiv, 03041, Ukraine, e-mail: oomit99@ukr.net 2Altai State University, Barnaul, Russian Federation, e-mail: amatsyura@gmail.com Received: 29.10.2018. Accepted: 01.12.2018
The egg shape, as a description datum about adult bird is an important object for research work closely allied with the bird adaptation to brood under different environmental conditions. Besides, it is possible to use this approach as an additional research instrument for general bird evolution study, ecological proximity, taxonomy, etc. Moreover, at the same time egg shape profile is the mostly suitable characteristic for intravital study above-mentioned aspects. Key words: egg shape, photo-computing method, egg radius, curvature
A plenty of research works devoted to egg shape could be related to the next groups. The first one is represented by the oval curve constructions of coherent to egg profiles with the indication of prospective usage in oology (Cundy, Rollett, 1989; Dixon, 1991; Iwamoto, 2011; Nishiyama, 2010; Mieszkalski, 2014). The second one and most important direction is algebraic description of the curves approximated to the bird egg profiles (Paganelli et al., 1974; Anderson, 1978; Myand, 1988; Hutchinson, 2000; Köller, 2000; Mattas, 2001; Johnson, 2001; Baker, 2002; Führer-Nagy, 2002; Heck, 2010; Möller, 2009; Petrovic, Obradovic, 2010; Avila, 2014, Yamamoto, 2016). In addition, polynomial equation takes up the special place in such a research (Preston, 1968, Todd, Smart, 1984; Barta, Szekely, 1997; Narushin, 2001; Jonson, Leyhe, Werner, 2001; Baker, 2002; Francevich, 2010). Moreover, the last one is the most recent direction in the egg study - geometrical morphometry (Murray, Piller, et al., 2013; Deeming, Ruta, 2014; Stoddard et al., 2017; Deeming, 2018, Biggins, Thompson, Birkhead, 2018). Despite the universality of mentioned methods of approximation and possibility to describe eggs with predetermined accuracy, the majority of oological problems are stay unsolved. In mentioned researches, the egg profile considered as a closed curve without analysis of its parts. The last one performed by infundibular (more round zone where air camera is located), cloacal (more pointed part of the egg, the room for allantois) and interpolar (the central zone of embryo location) zones of the egg (Kostin, 1977).
The size of each zone has obvious meaning for the incubation. Info with parameters related to curvature of the egg flat zones is significant for shape classification and unification of quantitative and geometrical data with names into general system (Mytiai, 2003, 2008; Mytiai, Matsyura, 2017).
Preston firstly paid attention to necessity to make measurements of curvature radiuses of egg polar zones (Preston, 1953, 1968). This author and others offered several appliances for making such a measurements (Preston, 1953; Gemperle, Preston, 1955; Preston, 1957a, 1957b; Reid et al., 1974). Taking into account values of two radiuses of egg poles F. W. Preston offered two indexes (asymmetrical and biconical). However due to complexity the method did not find acceptance. Appearance of digital photography and proper software made simple to obtain additional egg parameters besides the measurement of length and diameter with the help of sliding caliper. At the same time, it has become possible to describe quantitatively each egg zone. This article is devoted to the software aimed to obtain such quantitative figures and touches the questions of their prospective usage.
Materials and methods
Basic egg dimensions - length and diameter (width) were measured with a caliper with precision up to 0.1 mm. To obtain the radiuses of curve, eggs were photographed with a digital camera Pentax K10D on a special holder under balanced illumination and special positioning that provided perpendicular between the egg length and lens optical axis. We used computer photo processing for further shape analysis. All the egg zones names used herein are the same to Y. V. Kostin (1977) (Fig.1).
02
Figure1. Components of the bird egg: R1=Ri - curvature radius of infundibular area, R2=Ri - curvature radius of lateral area, R3=Rc - curvature radius of cloacal area
We performed this study on data from 16.490 bird eggs of 800 species (20 orders). The egg names (according to their shape) we suggested in our previous study (Mytiai, Matsyura, 2017).
Results
Physically the egg as a body of revolution can be considered as a uniformly or non-uniformly compressed ball at two opposite sides. As a result, we have either symmetrical form - polar zones are identical or asymmetrical form where polar zones are different. The magnitudes of radiuses in curved parts we can detect by egg photos. It is possible to find this with the help of compass by making circles equal to curve of appropriate zone and measure radiuses by caliper after. These operations could be implemented using CorelDRAW, Photoshop, and Picture Manager, but during the volumetrical handling it is not effective. That is why the special software was written that allowed to find radiuses of curve, surface area and volume using scaled digital egg photo.
The model of complex ovoid was taken as a principle with postulation that the egg outline (profile) is the combination of arcs of different radiuses that are smoothly transferred one into the other. In addition, the smoothness achieved due to arc conjugation (Fig.2)
Figure 2. Scheme of ovoid arc conjugation
Mathematically it can be solved using equation of smooth piecewise continuous curve. In general view, the egg profile could be obtained rotating a smooth curve that set by equation F(X, Y) = 0, around the certain axis N in Cartesian co-ordinates. Let us suppose some Cartesian co-ordinates Oxy and for simplification accept the condition that the axis of curve rotation (egg form) coincide with the axis Ox. Thus, for egg form reproduction, it is enough to accept F(X, Y) = 0, Y> 0. In addition, surmise curve of rotation as the arches of three circles, which smoothly transferred one into the other. As a result, equation of the curve will be the next:
(X - X, )2 +(7 - Y, )2 - R2, XLefi < X < X! F(X, Y) = J (X - Xl )2 + (Y - Yl )2 - R2l , X! < X < X2
(X -Xc)2 +(Y- Yc)2 -RC,X2 < X < Xmght
(1)
Where:
• (X, Yi)\ Ri, (Xl,Yl)'\ RlTa(Xc; Yc)i Rc- coordinates of the centers and radiuses of corresponding circles of infundibular, lateral (interpolar) and cloacal zones of the egg;
• (XLeft, 0)Ta (XRight, 0)- these are left and right cross points between curve F(X, Y) = 0and abscissa axis;
• Xi Ta X2 - abscissas of junction points of the circles (points of transfer one arch into the other). Without loss of universality and for simplification, we accepted the next limits:
• center of the circle which form lateral (interpolar) zone is located on the Oyaxis, Xl = 0and point (0, D/2)- is the point of maximum;
• centers of the opposite arches are located on the abscissa axis, j = 0'\ Yc=0.
Therefore, taking into account all the stated conditions the equation of the curve, that form the egg profile during rotation, will be the next:
F ( X, Y ) = <
(X - X, )2 + Y2 - Rf, XLeft < Y > 0 X2 +(Y- Yl)2 -R2,X < X < X2,Y > 0 (X - Xc)2 + Y2 - RC,X < X < Xmht, Y > 0
(2)
Taking into account the condition of smoothness
F (X - 0, Y) = F (X + 0, Y) F '(X - 0, Y) = F '(X + 0, Y) F (X 2- 0, Y ) = F (X 2+ 0, Y ) F'(X2 - 0, Y) = F'(X2 + 0, Y)
From equation (2) we find abscissas of junction points of the arches which form curve of rotation.
R
L
Y 2
^r +1 X2
X2 =- Rl
Y 2 yl +1
X
2
Thus, we have parametrical equation of the curve F(X, Y) = 0, which depends on characteristics:
• Xi - abscissa of the circle center of infundibular zone;
• Ri - radius of the circle of infundibular zone;
• Yl - ordinate of the circle center of lateral (interpolar) zone;
• Rl - radius of the circle of lateral (interpolar) zone;
• Xc - abscissa of the circle center of cloacal zone;
• Rc - radius of the circle of cloacal zone;
The next steps of egg parameters analysis are:
a) color image transformation into black-and-white;
b) white and black components definition;
c) iterative computing of all parameters.
It is possible to describe each color of egg photo as a combination of red, green and blue (RGB scheme) with the set of coefficients. We consider the color in each pixel as a:
(R,G,B)0 < R,G,B < 255 GS(R, G, B) - this is the grey representation of color picture (Fig. 3):
Figure 3. RGB to Grayscale
There are several commonly used ways to set a function which transform color pixels into gray tints:
1. GS (R, G, B) = 0.299R + 0.587G + 0.114B
2. GS (R, G, B) = 0.2126R + 0.7152G + 0.0722B
3. GS(R, G,B) =(R+G+B)/3
After color transformation each pixel of a new representation has the value from 0 up to 255, where 0 - completely black and 255 - completely white. Using some threshold value of T, the gray tint image can be transformed into black-and-white picture by a formula where values less than T transform into black and greater than T - into white. As a result we obtain the next picture (see Fig. 4).
Figure 4. Grayscale to Monochrome transformation.
Search algorithm in width could be used to choose connectivity components. The core of the process is - for each pixel, we analyze four nearest one and each of them with the same color has the same connectivity component. Start from any pixel and set the first connectivity component. Then find pixels out of processing and iterate procedure.
Only points, which limit connectivity components, are necessary for egg characteristics processing. Therefore, for each component it is possible to use algorithm of convex shell construction to find only limiting points for each component (Fig. 5).
Figure 5. Connectivity components.
Let us progress to the next. The convex shells of single component connectivity represented at the picture below. The process of iterative calculations is under implementation with assumed contingencies for circle centers and radiuses coordinates without loss of universality:
• radiuses Rc and Ri are located between 0 and D;
• abscissa Xi is located between XLeft and 0;
• abscissa Xc is located between 0 and XRight;
• radius Rl is located between 0 and 4 D.
Now, by changing the meanings with given step it is possible to obtain approximated meanings for coordinates of circle centers and radiuses which determine egg form.
{xi,ri rL,rL,xc,rc} - are the current supposed values for abscissa and radius of the circle which circumscribe infundibular zone, radius of the lateral zone and abscissa and radius of the circle of cloacal zone correspondingly (Fig.6).
-
✓ * * — m ^ ~ * - «s >
s '/Z ✓ ✓ - -e< N X \
✓ ,'s ( Jf '/fj c ; / V ' - - e, ^ A v. \ _ vs. » N
f v P% i? /] \ x 1 i P / ' . h ' N' J ■ta w^ •s V / kM J .J rV
s ' ZA > J J L ' j y J J / V Si 0 / ft u s 1 I 1 » \ \ 2 « v \ N i \m. \ \ •r / ' r
/A* / 1 f ' 1 rK - M -21 s t 1 V\ / T / »/ / I 1 • \
1 1 1 i v 1 s \ v \ / 1 ✓ / '1 , I t i r 1
1 \ \ \ \ \ > \ \ \ A > / ✓ F / / / #
* « X / / H
Figure 6. Suggested iterations.
For each the configuration, we suggested to calculate: D
• = d - rL
+1
\yL
+1
r
L
• x = -
r
L
• x2 =
2
x
C
And denote that:
• F
{xI , rI , rL , XC , rC }
r , Y) - is the function which characterize the egg form in current parameters;
• S
XI ,rI ,rL , XC ,rC }
} 2p{Xk ,Yk )eC
F
XI ,rI ,rL ,XC ,rC
i(Xk, Y ),
Where Cis the specific set of points (which confine the egg form) that we obtained during the previous steps.
To start from the denotation, the value of the function
F{Xlr r ,Xc r}(X'Y) showes how far is the point with
coordinates (X, Y) from the curve which circumscribe the egg form in current configuration, while the value S{xi,n,rL,xc,rc} - is the sum of all distances from the original curve points to the curve in current configuration.
Thus, among the all possible configurations^, Tj , Tl,Xc ,rc } it's necessary to find one with minimal S{xi,ri,rL,xc,rc} value. These will be the values of research parameters for the centers and radiuses of the circles.
On the base of above mentioned equations we created the software "Egg Scanner" (Appendix), which calculates three radiuses, egg surface area, egg volume, and draw egg profiles. All the research data orderly stored at special Access DB. All the info related to the measurements, egg photo, and handmade real measurements of egg length and diameter are entered into the DB. In addition, the last two measurements are necessary for software miscounts monitoring.
Discussion
All the above mentioned existing methods of egg circumscribing have definite approximation towards the real forms. Even the mostly accurate methods of extrapolation (Baker, 2002; Bridge et al., 2007; Frantsevich, 2010; Deeming, Ruta, 2014; Nedomova, Buchar, 2014; Troscianco, 2014; Ban et al., 2011; Stoddard, 2017, Biggins et al., 2018) (polynomial equation) do not permit to conduct the research without egg zones curvature analysis. The rate and values of polar and interpolar zones are informative for quantitative egg assessing and for finding out relationship between morphometric indexes and functional meaning. We believed that the variety of egg forms caused by the mentioned different values of radiuses. Moreover, each radius characterize the definite shell zone, which are the definite conditions for embryo development and they are associated with infundibular zone (the blunt egg end with the air camera inside) responsible for the embrio respiration. The opposite zone, (more pointed end) is the room for allantois that plays the important role in respiration, water exchange and accumulation of metabolism products. This pole curvature makes an influence on egg asymmetry (Mytiai, Matsyura, 2017) degree and form angle of inclination of egg long axis that important to account during incubation (Mao et al., 2007).
Interpolar zone is the place for yolk and the size of this zone is influential for embryo development (Deeming, 2018). The zones, slipping each into other, make up the total egg form with common curvature, surface area and volume that provide mechanical strength of the shell. Its role in the processes of thermoregulation, respiration and transpiration is indisputable.
d e f g
Figure. 7. Asymmetrical oval - ovoid (a) u and its types (b-g)
All the discussed above underlines the importance of radiuses values for mathematical egg form definition. Considering the importance of the parameters of the radii of curvature of the polar zones proposed by Preston (Preston, 1953, 1968), we used their measurement from photographs of eggs using a specially written computer program (Mytiai, 2003, 2008). We also believe that four independent parameters are enough to describe any form of bird eggs. Other authors agree with this (Biggins et al., 2018). However, in addition to the indices, the four parameters mentioned allow us to bring the whole variety of eggs into a single system and introduce an individual standard for each of the forms. We have introduced such a system for the first time (Mytiai, Matsyura, 2017).
Analysis of the 16.490 bird egg's shapes (of 800 species) shows, that the radiuses of polar zones (Ri, Rc), length (L) and diameter (D) are the four independent parameters. Length and diameter are measured by caliper, radiuses of blunt and pointed egg parts are measured according to our method. Using these quantitative parameters and geometric structure we solve the problem of appropriate egg shape naming that additionally gives the possibility in finding relations between the form and functional meaning of each egg zone and of the whole egg too. As a result of our research the egg shape classification with geometrical structure, size indexes and names was originated (Mytiai, Matsyura, 2017). Asymmetrical oval - ovoid with one axis of symmetry was taken as a basic model for measurements and egg shape classification. According to one of definitions (Dixon, 1991; Cundy, Rollett, 1989), ovoid is a flat, closed, convex, smooth curve consisting of conjugated arcs of circles of different radiuses, which form four apexes. This so-called "classical ovoid" has the next parameters: Ri = 0,5D;L = 2-(V2)Rc = 1-(V2)Rl = D (Fig. 7a).
If we accept diameter as a unit (of measurement) and express other three parameters in this units - indexes of the egg form will be found as a result. The egg length divided on diameter gives classical index of longitude (Iel=L/D), radiuses of polar zones - indexes of infundibular (Iiz=Ri/D) and cloacal (Icz=Rc/D) zones.
Indexes of infundibular zone close to 0,5D give an opportunity to specify shapes named as "base ovoids" (Fig. 7, b-g). They grow by lengthening or shortening of initial "classical ovoid" because to changes in radiuses of cloacal and lateral arches. In accordance with the geometry of these ovoids, the names are simply originated: sphere-shaped (b), roundish (c), blunt (d), typical (e), drop-shaped (f), and cone-shaped (g).
The others egg shapes are characterized by polar indexes comparison, which can be equal or not. In the first case, we deal with symmetrical forms named as "symmetrical pseudo-ovoids" because they do not correspond to ovoid specifying. In the second case, the infundibular radius is shorter than 1/2D but longer than cloacal radius. Such ovoids are named as "asymmetrical pseudo-ovoids". "Symmetrical" and "asymmetrical" pseudo-ovoids can be considered geometrically as a combination of similar and different ovoids (Fig. 8).
Figure. 8. "Symmetrical" and "asymmetrical" pseudo-ovoids forming by the combination of base ovoids.
Such a classification is visual, simple in usage and has all the characteristics of natural system. All the egg shapes are interconnected, derived from the base ovoid form and the names correspond to the mathematical terms. It allowed us to make the egg shape standard catalogue (Mytiai, Matsyura, 2017). Exact geometrical pattern, name and quantitative indexes are helpful for the search of relations between egg form and functional meaning.
Conclusions
The proposed geometric system of the composite ovoid allows dividing the ovoid into three zones along the curvature of their surface. This approach allows one to describe all existing egg forms on the basis of four independent parameters (D, L, Ri, Rc). Their use allows, along with the Preston form indexes (Preston, 1953, 1968), to identify more indices that can be used as additional characteristics. Moreover, our approach allowed the creation of a natural system of bird-egg forms in the form of
geometric standards, in which each form has its own name, quantitative parameters, and a geometric figure. Any form of eggs could be associated with their ability to provide the development of bird embryos in various environmental conditions.
Acknowledgements
The authors would like to express deep gratitude to our colleagues who contributed to the article, namely E. Degtyarenko, N. Siliverstov, B. Trotsenko, S. Shelestuk, L. Frantsevich, A. Demchenko, and R. Orlovskyi.
References
Anderson, M. (1978). Optimal egg shape in waders. Ornis Fennica, 55, 105-109.
Avila, D.D. (2014). Aplicaciön de las funciones elipticas de Fourier para la description de la forma de los liuevos de las aves. Rev. Biol. Trop, 62(4), 1469-1480.
Baker, D.E. (2002). A geometric method for determining shape of bird eggs. The Auk, 119, 1179-1186. https://doi.org/10.1642/0004-8038(2Q02)119(1179:AGMFDS)2.Q.CO:2.
Ban, M., Barta, Z., Munoz, A.R., Takasu, F., Nakamura, H., Moskat, C. (2011). The analysis of common cuckoo's egg shape in relation to its hosts' in two geographically distant areas. Journal of Zoology, 284(2), 77-150.
Biggins, J.D., Thompson, J.E., Birkhead, T.R. (2018). Accurately quantifying the shape of birds' eggs. Ecology and Evolution, 1-11. https://doi.org/10.1002/ece3.4412
Barta, Z., Szekely, T. (1997). The optimal shape of avian eggs. Functional Ecol, 11, P. 656-662.
Bridge, E.S., Boughton, R.K., Aldredge, R.A., Harrison, T.E., Bowman, R., Schoech, S.J. (2007). Measuring egg size using digital photography: testing Hoyt's method using Florida Scrub-Jay eggs. Journal of Field Ornithology, 78,109-116. DOI: 10.1111/j.1557-9263.2006.00092.x Cundy, H., Rollett A. (1989). Mathematical Models. Third Edition. Stradbroke, Tarquin Pub. Dixon, R. (1991). Mathographics. New York, Dover.
Deeming, D.C., Ruta, M. (2014). Egg shape changes at the theropod-bird transition, and a morphometric study of amniote eggs. R. Soc. Open Sci, 1. doi:10.1098/rsos.140311
Deeming, D.C. (2018). Effect of composition on shape of bird eggs. Journal of Avian Biology, 49(1), 1-7. doi: 10.1111 /jav.01528.
Frantsevich, L. (2010). Planimetry of the egg shape parameters. Available from: http://www.biometrica.tomsk.ru/planirus.htm/ Accessed on
10.11.2018. (In Russian)
Führer-Nagy, G. (2002). Mathematical modeling of bird egg curves. Aquila, 107/108, 67-73. Heck, A. (2010). Mathematical Brooding over an Egg. Convergence, DOI:10.4169/loci002842.
Johnson, L.S., Leyhe, J.E., Werner, C. (2001). The shape of eggs in different-size clutches of the/ House Wren (Troglodytes aedon). Can. J. Zool, 79, 1527-1531.
Iwamoto, T. (2011). Many Shapes of Bird's Eggs. Available from: http://www.takayaiwamoto.com/Egg Draw/Other Birds Egg.html/ Accessed on 25.10.2018
Hutchinson, J.M.C. (2000). Three into two doesn't go: two-dimensional models of bird eggs, snail shells and plant roots // Biological Journal of the Linnean Society, 70, 161-187. doi:10.1006/bijl.1999.0395
Gemperle, M.E., Preston, F.W. (1955). Variation of shape in the eggs of the common tern in the clutch-sequence. Auk, 72, 184-198. Köller, J. (2000). Mathematische Basteleien. Availble from: http://www.mathematische-basteleien.de/index.htm/ Accessed on 04.10.2018 Kostin, Y.V. (1977). About methodology of oomorphological researches and unification of descriptions of oological material. In Metodiki issledovaniya produktivnosti i struktury vidov ptits v predelakh ikh arealov. (Methods of the study of the productivity and structure of bird species within their areals.) Vilnius (In Russian)
Mao, K.-M., Murakami, A., Iwasawa, A., Yoshizaki, N. (2007). The asymmetry of avian egg-shape: an adaptation for reproduction on dry land. J Anat, 210(6), 741 -748. doi:10.1111/j.1469-7580.2007.00737.x Mattas, M. (2001). Uraovani tvar u ptaaich vajec. Sylvia, 37, 17-25.
Mieszkalski, L. (2014). Method of mathematical modelling Of the surface of the egg shell shape, egg yolk and air chamber of chicken eggs. Agricultural Engineering, 3(151), 93-104.
Mytiai, I.S. (2003). New method for the complex estimation of a form of the egg. Branta, 6, 179-192. (In Russian)
Mytiai, I.S. (2008). Using modern technologies in researching of bird eggs. Zaporozhye National University Journal. Series Biology, 175-183. (In Russian)
Mytiai, I.S., Matsyura, A.V. (2017). Geometrical standards in shapes of avian eggs. Ukrainian Journal of Ecology, 7(3), 264-282. doi: 10.15421/2017_78
Möller, H. (2009). Das 2:3-Ei - ein praktikables Eimodell. Available from: http://www.math.uni-muenster.de/u/mollerh/data/ZweiDreiEi.pdf/ Accessed on 05.11.2018
Myand, R. (1988). Intrapopulational variability of bird eggs. Tallin, Valgu (In Russian)
Murray, C.M., Piller, K.R., Merchant, M. (2013). Salinity and Egg Shape Variation: A Geometric Morphometric Analysis // Journal of Herpetology, 47(1), 15-23.
Narushin, V. G. (2001). Shape geometry of the avian egg. J. Agric. Engin. Res, 79, 441-448. Nedomova, S., Buchar, J. (2014). Goose eggshell geometry. Res. Agr. Eng, 60, 100-106.
Nishiyama, Y. (2010). The Mathematics of Egg Shape. Available from: http://www.osaka-ue.ac.jp/zemi/nishiyama/math2010/egg.pdf Accessed on 15.11.2018
Paganelli, C. V., Olszowka, A., Ar, A. (1974). The avian egg: surface area, volume, and density. The Condor, 76, 319-325.
Petrovic, M., Obradovic, M. (2010). The complement of the hugelschaffer's construction of the egg curve. Avalable from:
https://www.researchgate.net/publication/273139632/ Accessed on 20.11.2018.
Preston, F.W. (1953). The shapes of birds egg. The Auk, 70, 160-182.
Preston, F.W. (1957a). Two New Devices for Measuring the Shapes of Birds' Eggs. The Auk, 74, 386-388. Preston, F.W. (1957b). Two New Devices for Measuring the Shapes of Birds' Eggs. The Auk, 74, 386-388. Preston, F.W. (1968). The shapes of birds eggs: mathematical aspects. The Auk, 85, 454-463.
Reid, W.S. Buckley, D.J., Hunt, J.R., Prices, K.(1974). A digital instrument for egg shape index measurement. Can. J. Anim. Sci, 55, 87-92. Stoddard, M.C., Yong, E.H., Akkaynak, D., Sheard, C., Tobias, J.A., Mahadevan, L. (2017). Avian egg shape: form, function, and evolution. Science, 356, 1249-1254.
Todd, P.H., Smart, I.H.M. (1984). The shape of birds' eggs. J. Theor. Biol, 106, 239-243.
Troscianko, J. (2014). A simple tool for calculating egg shape, volume and surface area from digital images. Ibis, 156(4), 874-878. Yamamoto, N. (2016). We Find an Equation of Egg Shaped Curve. Available from: http://www.geocities.jp/nyjp07/index egg E.html/ Accessed on 02.11.2018
APPENDIX. STEPS OF THE ALGORITHM COMPUTER PROGRAM
using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Imaging; //using System.Runtime.InteropServices; namespace Egg_Scanner_Beta {class BitmapAnalysis
{public static unsafe void SetColor(BitmapData bData, int x, int y, int NewColor) {((int*)((byte*)bData.Scan0 + bData.Stride * y))[x] = NewColor;} public static unsafe int GetColor(BitmapData bData, int x, int y) {return ((int*)((byte*)bData.Scan0 + bData.Stride * y))[x];}
static Component FindAndMarkComponent(BitmapData bData, int x, int y, int[,] ids, int id, int color) {Component res = new Component(); res.IsWhite = color == Color.White.ToArgb();
res.ID = id; res.x = x; res.y = y; Queue<Point> q = new Queue<Point>(); q.Enqueue(new Point(x, y)); int size = 1; ids[x, y] = id; while (q.Count > 0) {Point p = q.Dequeue(); x = p.X; y = p.Y; if (x > 0 && ids[x - 1, y] == 0 & & GetColor(bData, x - 1, y) == color) {ids[x - 1, y] = id;
size++;q.Enqueue(new Point(x - 1, y));}
if (x < bData.Width - 1 && ids[x + 1, y] == 0 && GetColor(bData, x + 1, y) == color)
{ids[x + 1, y] = id; size++; q.Enqueue(new Point(x + 1, y));}
if (y > 0 && ids[x, y - 1] == 0 && GetColor(bData, x, y - 1) == color)
{ids[x, y - 1] = id; size++; q.Enqueue(new Point(x, y - 1));}
if (y < bData.Height - 1 && ids[x, y + 1] == 0 && GetColor(bData, x, y + 1) == color) {ids[x, y + 1] = id; size++; q.Enqueue(new Point(x, y + 1));} } res.size = size; return res;}
public static Components GetComponents(BitmapData bData, int color) {int Width = bData.Width; int Height = bData.Height; List<Component> lRes = new List<Component>(); int[,] ids = new int[Width, Height];
int NewlD = 1; for (int y = 0; y < Height; ++y) for (int x = 0; x < Width; ++x)
if (GetColor(bData, x, y) == color && ids[x, y] == 0) {Component c = FindAndMarkComponent(bData, x, y, ids, NewID++, color); lRes.Add(c);} return lRes.ToArray();}
public static void RepaintComponent(BitmapData bData, int x, int y, int Color, int NewColor) {Queue<Point> q = new Queue<Point>(); q.Enqueue(new Point(x, y)); while (q.Count > 0) {Point p = q.Dequeue(); x = p.X; y = p.Y; if (GetColor(bData, x, y) == NewColor) continue; SetColor(bData, x, y, NewColor); if (x > 0 && GetColor(bData, x - 1, y) == Color) q.Enqueue(new Point(x - 1, y));
if (x < bData.Width - 1 && GetColor(bData, x + 1, y) == Color) q.Enqueue(new Point(x + 1, y)); if (y > 0 && GetColor(bData, x, y - 1) == Color) q.Enqueue(new Point(x, y - 1));
if (y < bData.Height - 1 && GetColor(bData, x, y + 1) == Color) q.Enqueue(new Point(x, y + 1));} }
static void FindMinMaxOpen(BitmapData bData, int x, int y, ref int minX, ref int minY, ref int maxX, ref int maxY) {int Color = System.Drawing.Color.White.ToArgb();int NewColor = System.Drawing.Color.Blue.ToArgb(); Queue<Point> q = new Queue<Point>(); q.Enqueue(new Point(x, y)); while (q.Count > 0)
{Point p = q.Dequeue(); x = p.X; y = p.Y;
minX = Math.Min(minX, x);
minY = Math.Min(minY, y);
maxX = Math.Max(maxX, x);
maxY = Math.Max(maxY, y);
if (GetColor(bData, x, y) == NewColor)
continue; SetColor(bData, x, y, NewColor); if (x > 0 && GetColor(bData, x - 1, y) == Color) q.Enqueue(new Point(x - 1, y));
if (x < bData.Width - 1 && GetColor(bData, x + 1, y) == Color) q.Enqueue(new Point(x + 1, y));
if (y > 0 && GetColor(bData, x, y - 1) == Color) q.Enqueue(new Point(x, y - 1));
if (y < bData.Height - 1 && GetColor(bData, x, y + 1) == Color) q.Enqueue(new Point(x, y + 1));} }
static void FindMinMaxClose(BitmapData bData, int x, int y, int minX, int minY, int[] minXdy, int[] minYdx, int[] maxXdy, int[] maxYdx)
{int Color = System.Drawing.Color.Blue.ToArgb();
int NewColor = System.Drawing.Color.White.ToArgb();
Queue<Point> q = new Queue<Point>();
q.Enqueue(new Point(x, y));
while (q.Count > 0)
{ Point p = q.Dequeue();
x = p.X; y = p.Y;
if (minXdy[y - minY] == -1 || minXdy[y - minY] > x) minXdy[y - minY] = x;
if (minYdx[x - minX] == -1 || minYdx[x - minX] > y) minYdx[x - minX] = y;
if (maxXdy[y - minY] == -1 || maxXdy[y - minY] < x) maxXdy[y - minY] = x;
if (maxYdx[x - minX] == -1 || maxYdx[x - minX] < y) maxYdx[x - minX] = y; if (GetColor(bData, x, y) == NewColor)
continue; SetColor(bData, x, y, NewColor); if (x > 0 && GetColor(bData, x - 1, y) == Color) q.Enqueue(new Point(x - 1, y));
if (x < bData.Width - 1 && GetColor(bData, x + 1, y) == Color) q.Enqueue(new Point(x + 1, y)); if (y > 0 && GetColor(bData, x, y - 1) == Color) q.Enqueue(new Point(x, y - 1));
if (y < bData.Height - 1 && GetColor(bData, x, y + 1) == Color) q.Enqueue(new Point(x, y + 1)); } }
static void ActuallyClose(BitmapData bData, int minX, int minY, int[] minXdy, int[] minYdx, int[] maxXdy, int[] maxYdx)
{int Color = System.Drawing.Color.White.ToArgb();
for (int dx = 0; dx < minYdx.Length; ++dx)
for (int y = minYdx[dx]; y <= maxYdx[dx]; ++y)
SetColor(bData, minX + dx, y, Color);
for (int dy = 0; dy < minXdy.Length; ++dy)
for (int x = minXdy[dy]; x <= maxXdy[dy]; ++x)
SetColor(bData, x, minY + dy, Color);}
public static void CloseComponent(BitmapData bData, int x, int y) {int minX = x, maxX = x; int minY = y, maxY = y; FindMinMaxOpen(bData, x, y, ref minX, ref minY, ref maxX, ref maxY); int[] minXdy = new int[maxY - minY + 1]; int[] maxXdy = new int[maxY - minY + 1]; for (int i = minY; i <= maxY; ++i) minXdy[i - minY] = maxXdy[i - minY] = -1; int[] minYdx = new int[maxX - minX + 1]; int[] maxYdx = new int[maxX - minX + 1]; for (int i = minX; i <= maxX; ++i) minYdx[i - minX] = maxYdx[i - minX] = -1;
FindMinMaxClose(bData, x, y, minX, minY, minXdy, minYdx, maxXdy, maxYdx); ActuallyClose(bData, minX, minY, minXdy, minYdx, maxXdy, maxYdx); } public static void RepaintComponent(BitmapData bData, Component cmp, int NewColor) {int Color = GetColor(bData, cmp.x, cmp.y); if (Color != NewColor) RepaintComponent(bData, cmp.x, cmp.y, Color, NewColor); }}}
Citation:
Mytiai, I.S., Matsyura, A.V. (2018). Usage of the iterative photo-computing method in specifying of bird egg radiuses curvature Ukrainian Journal of Ecology, 8(4), 195-204. GS^^^^^Mlhis work is licensed under a Creative Commons Attribution 4.0. License