An Algorithm for Obtaining 3D Egg Models from Visual Images

: Mathematical models for describing the shape of eggs ﬁnd application in various ﬁelds of practice. The article proposes a method and tools for a detailed study of the shape and peripheral contours of digital images of eggs that are suitable for grouping and sorting. A scheme has been adapted to determine the morphological characteristics of eggs, on the basis of which an algorithm has been created for obtaining their 3D models, based on data from color digital images. The deviation from the dimensions of the major and minor axes measured with a caliper and the proposed algorithm is 0.5–1.5 mm. A model of a correction factor has been established by which the three-dimensional shape of eggs can be determined with sufﬁcient accuracy. The results obtained in this work improve the assumption that the use of algorithms to determine the shape of eggs strongly depends on those of the bird species studied. It is approved with data for Mallard eggs which have a more elliptical shape and correspondingly lower values of correction coefﬁcient ‘c’ (c = 1.55–4.96). In sparrow (c = 9.55–11.19) and quail (c = 11.71–13.11) eggs, the form tends to be ovoid. After testing the obtained model for eggs from three bird species, sparrow, mallard, and quail, the coefﬁcient of the determination of proposed model was R 2 = 0.96. The standard error was SE = 0.08. All of the results show a p-value of the model less than α = 0.05. The proposed algorithm was applied to create 3D egg shapes that were not used in the previous calculations. The resulting error was up to 9%. This shows that in the test, the algorithm had an accuracy of 91%. An advantage of the algorithm proposed here is that the human operator does not need to select points in the image, as is the case with some of the algorithms developed by other authors. The proposed methods and tools for three-dimensional transformation of egg images would be applicable not only for the needs of poultry farming, but also in ornithological research when working with different shaped varieties of eggs. Experimental results show that the proposed algorithm has sufﬁcient accuracy.


Introduction
The application of mathematical models for describing the shape of eggs is in both poultry and ornithology, as well as in industrial technology, mathematics, art, architecture, religion, and philosophy. Examples are egg-shaped sludge mills; egg-shaped water channels; compartments of cars with ovate shape; egg-shaped cell phones; and speakers; refrigerators and washing machines of this form have been developed. The mathematical models of eggs are applied to the design of buildings, the elements of infrastructure that have high energy efficiency, high aerodynamic qualities, and minimal material consumption [1,2].
Determining the geometric dimensions of eggs and their relationship is important for poultry and ornithology studies. The results obtained can be used in population analysis, environmental morphology, predicting the weight of chickens, and assessing the quality characteristics of eggs. Size of the egg is related to important aspects in the study of bird Egg models have been developed both in two-dimensional [6,7] and in three-dimensional form [8].
Current research relating to model definition and classification of eggs has focused on the use of simplified analysis procedures. Studies and analyses are directed to the use of contactless measurement methods, including systems for image acquisition, processing and analysis, spectral, and dielectric characteristics. The mathematical description of the shape of the eggs is applied to these methods.
Techniques for automating the inspection of products in various fields of application have been proposed by researchers in recent years. Research in this area is focused on the use of systems for obtaining, processing, and analyzing color digital images.
One of the main applications of digital image processing is to determine the number and type of objects in them. The variety of objects creates many problems in this process as each object has its own characteristics and features. Difficulties in solving this task arise from various factors such as the contrast between objects and the background, the degree of separability and grouping of objects, their texture and variety, and size. These features are evident in organic products such as eggs, as they are too complex and the images obtained from them include all the listed factors.
The purpose of the article is to propose a method and tool for detailed examination of the shape and peripheral contours of digital images of eggs that are suitable for grouping and sorting.
The contributions in this paper include: image processing and analysis techniques are valuable for analysis of the external characteristics of eggs. A method of geometrical transformation of an egg contour into a three-dimensional surface was examined. Twodimensional image processing and analysis techniques were applied for obtaining a 3D model of egg shapes. The proposed algorithm showed appropriate accuracy and low error rates.

Related Works
Eggs have the shape of an irregular ellipse. This can be determined visually, but the assessment in these cases is too subjective [9]. According to Narushin et al. [10], the judicious assessment of the shape of the eggs can be used only in cases where the requirements for the accuracy of the assessment are not very high. A more accurate idea of the shape can be obtained by measuring the diameters of the egg and calculating the index of the shape as a percentage between the small and large diameters of the egg [11,12].
Optimal hen eggs have an index of 73-75%, and this trait varies both depending on the age of the laying hens and depending on the genotype (breed or hybrid affiliation). The lower the value of the shape index, the longer the shape of the egg, and vice versa-high values indicate an oval shape [13].
According to Panda and Singh [14], the quail egg shape index is in the range of 78-79%, while Polat et al. [15] report slightly lower values (75%). According to the authors, the average sizes of quail eggs are 34.9 mm large and 26.2 mm smaller in diameter. Sezer [16] found a positive relationship between the shape index and the mass of eggs, and according to the author, the determination of mass is more strongly influenced by the small diameter of the egg. The shape of the egg affects the resistance of the egg to breakage. Richards and Swanson [17] found that the shape index explains 15 to 35% of shell breakage cases. According to Bain [18], a more rounded shape is more desirable because it makes the egg more resistant to manipulation without compromising the integrity of the eggshell. This conclusion is supported by later studies by Altuntas and Sekeroglu [19]. By analyzing the shape and its main characteristics, it is possible to create patterns of the shape of some elements of the eggs, for which it is possible to create patterns in which there is a certain stylization of the shape.
The main indicators of the shape of eggs by which classification is made are asymmetry, elongation, and pointedness [20], large and small axis [21], as for the division of eggs, eggs of different bird species, and to take into account the factors that influence the formation of the egg fossa. Although for the presentation of these shape indices by transformation of the feature space by the Principal Component Analysis (PCA) method [22], egg separation is not sufficiently accurate and a strong overlap is observed between data on different bird species.
The disadvantage of the methods used so far is that only the external shape of eggs is taken into account, without taking into account their internal characteristics [23], which depend on factors such as bird habitat, feeding, and age.
From the first definition of the problem with Preston [6], at the current level of science and technology, the problem of describing the shape of eggs still remains partially solved. The proposed solutions are both at the technological level, for example Duursma et al. [21], as well as with modern software and hardware tools, as indicated in the review article by Nyalala et al. [12]. According to the descriptions in the introduction and related works sections of this paper, the shape is the main physical indicator for identifying a large part of the elements of the eggs, during their incubation, packaging, sorting, and transportation. Such studies are also important for ornithology, where analyses of the change in egg shape depending on the bird's habitat are performed. It is mentioned in the technological research, but also in the technical papers in the available literature cited.
Using techniques of computer graphics and image analysis, dielectric and ultrasonic characteristics, and spectral and hyperspectral analysis, it is possible to determine freshness, irregular shape, mechanical damage, internal and external defects, bird status, ecology, and sorting and grouping of eggs. The issue of the practical application of the developed models and methods for egg analysis remains insufficiently clear.
Therefore, the present study focuses on the development and research of effective approaches, including descriptions, models, and tools for the recognition of egg elements, in terms of their shape. In this paper, a study was carried out on methods and algorithms used for the geometric transformation of the contour of real eggs of different bird species, based on 3D transformation based on the digital image data. This approach has been shown to be suitable for further research to develop appropriate technical tools that can be used for research in the field of analysis of the external characteristics of eggs.

Material and Methods
Basic egg shapes were used as well as color digital images of eggs from sparrow (Passer domesticus L.), mallard (Anas platyrhynchos L.), and quail (Coturnix coturnix L.) grown free (semi-wild). The eggs were collected in the region of Yambol, Bulgaria. Images of the eggs were obtained with a Digimax D250 digital camera (Samsung Electronics Co., Ltd., Samsung Digital City, Samsungno 129, Maetan-dong, Yeongtong District, Suwon, Korea), serial number 34603308. The images used were 640 × 480 pix resolution. The size adjustment was made with a digital caliper, with an accuracy of 0.02 mm.
The following abbreviations were used: D, D1-long axis of the egg; d, d1-short axis of the egg; MC-mass center of the egg; h 1 -length of the obtuse end of the egg; h 2 -length of the acute part of the egg; α-angle at the acute end of the egg; β-angle at the obtuse end of the egg; f -segment between mass center of the egg and intersection of its major and minor axes; α = 0.05-level of significance; p-value; g and h-lengths of sections; c-correction factor; R 2 -coefficient of determination; X, X1-parameters used for determination of coordinates needed for calculation of h 1 and h 2 ; SE-standard error. 2D-two-dimensional; 3D-three-dimensional.
The improvement of classic schemes in recognition of image form is proposed by Narushin et al. [13]. In this work, the scheme was used for determining the morphological characteristics of eggs proposed by Genchev et al. [24]. The scheme has been used with some modifications related to its application in conjunction with the proposed 3D egg models. Figure 1 shows a diagram for obtaining basic morphological characteristics of eggs. D, mm denotes the long axis of the egg; d, mm is the short axis of the egg; MC is a mass center; h 1 , mm is the length of the obtuse end of the egg; h 2 , mm is the length of the acute part of the egg; α is the angle at the acute end of the egg; β is the angle at the obtuse end of the egg. h1-length of the obtuse end of the egg; h2-length of the acute part of the egg; α-angle at the acute end of the egg; β-angle at the obtuse end of the egg; f-segment between mass center of the egg and intersection of its major and minor axes; α = 0.05-level of significance; p-value; g and h-lengths of sections; c-correction factor; R 2 -coefficient of determination; X, X1-parameters used for determination of coordinates needed for calculation of h1 and h2; SE-standard error. 2D-two-dimensional; 3D-three-dimensional.
The improvement of classic schemes in recognition of image form is proposed by Narushin et al. [13]. In this work, the scheme was used for determining the morphological characteristics of eggs proposed by Genchev et al. [24]. The scheme has been used with some modifications related to its application in conjunction with the proposed 3D egg models. Figure 1 shows a diagram for obtaining basic morphological characteristics of eggs. D, mm denotes the long axis of the egg; d, mm is the short axis of the egg; MC is a mass center; h1, mm is the length of the obtuse end of the egg; h2, mm is the length of the acute part of the egg; α is the angle at the acute end of the egg; β is the angle at the obtuse end of the egg. The angles in the obtuse and acute edges of the egg are determined by the following formulas: The two-dimensional contour of an egg can be described by equations in a Cartesian coordinate system. A two-dimensional egg contour is used from Yamamoto [25], which is The angles in the obtuse and acute edges of the egg are determined by the following formulas: The two-dimensional contour of an egg can be described by equations in a Cartesian coordinate system. A two-dimensional egg contour is used from Yamamoto [25], which is modification of the model, proposed by Todd et al. [26]. In the present work, it is adapted to the 3D model: where d, mm is the short axis of the egg; D, mm is the long axis of the egg; correction factor c = 0-1; angle ϕ ≤ |π|. To determine the mass center, large and small axis of eggs in their digital images, the "regionprops" function in the Matlab programming environment (The mathworks Inc., Natick, MA, USA) was used. The algorithm proposed in this work is implemented in this program.
All data were processed at a level of significance α = 0.05.

Results and Discussion
The change in the basic scheme for determining the morphological characteristics of eggs is related to the use of the mass center of the egg as a starting point for further calculations. The intersection of the long and short axis of the egg does not coincide with its mass center in all cases. This modification is necessitated by the fact that in computer programs for object analysis in images, there are ready-to-use functions for finding the long axis, short axis, and mass center of the object. The adapted 3D model of an egg is: where d, mm is the short axis of the egg; D, mm-long axis of the egg; c-correction factor determining the shape of the egg. Figure 2 shows a diagram for obtaining a 3D model of an egg. Two sections were added X-Z and Y-Z, with description of the egg dimensions used in the developed algorithm.
where d, mm is the short axis of the egg; D, mm is the long axis of the egg; correction factor c = 0-1; angle φ ≤ |π|.
To determine the mass center, large and small axis of eggs in their digital images, the "regionprops" function in the Matlab programming environment (The mathworks Inc., Natick, MA, USA) was used. The algorithm proposed in this work is implemented in this program.
All data were processed at a level of significance α = 0.05.

Results and Discussion
The change in the basic scheme for determining the morphological characteristics of eggs is related to the use of the mass center of the egg as a starting point for further calculations. The intersection of the long and short axis of the egg does not coincide with its mass center in all cases. This modification is necessitated by the fact that in computer programs for object analysis in images, there are ready-to-use functions for finding the long axis, short axis, and mass center of the object. The adapted 3D model of an egg is: where d, mm is the short axis of the egg; D, mm-long axis of the egg; c-correction factor determining the shape of the egg. Figure 2 shows a diagram for obtaining a 3D model of an egg. Two sections were added X-Z and Y-Z, with description of the egg dimensions used in the developed algorithm. The lengths of sections 'g' and 'h' are determined relative to the mass center of the egg. The segment 'g' has a length equal to the distance between the center of mass and the minimum value along the y axis-the point Y2. In the same way, segment 'h' has a length equal to the distance between the center of mass and the maximum value along the y axis-the point Y1. The length of section 'f', between the center of mass MC and the intersection of the long and short axes of the egg, is determined. The segment 'e' is the distance between the center of mass MC and the maximum value along the Z axis-the point Z1 of the egg. According to Pythagoras' theorem, the segment 'f' has a length: The lengths of sections 'g' and 'h' are determined relative to the mass center of the egg. The segment 'g' has a length equal to the distance between the center of mass and the minimum value along the y axis-the point Y 2 . In the same way, segment 'h' has a length equal to the distance between the center of mass and the maximum value along the y axis-the point Y 1 . The length of section 'f ', between the center of mass MC and the intersection of the long and short axes of the egg, is determined. The segment 'e' is the distance between the center of mass MC and the maximum value along the Z axis-the point Z 1 of the egg. According to Pythagoras' theorem, the segment 'f ' has a length: After determining the lengths of the segments, those of the acute and obtuse end of the egg are determined as: After preliminary analyses, it was found that the correction factor 'c' in the adapted three-dimensional model has a linear relationship with the ratio between the angles of the egg in the obtuse and its acute end c = f (β/α). The resulting model, describing with sufficient accuracy this relationship, is of the form: Using the model to describe the three-dimensional shape of eggs in their basic forms Mytiai et al. [27], the correction coefficient assumes values of c = 1-22.
The developed algorithm for obtaining three-dimensional egg models from color digital images is linear. Table 1 shows the steps of the algorithm in descriptive form and in pseudocode. The loaded image has been converted to RGB by HSV. The S(HSV) color component was used. After removing the openings and filtering, the coordinates of the egg center, large and small axis, were obtained with the regionprops function. H 1 , h 2 were determined and the angles at the acute and obtuse ends of the egg α, β were calculated. Based on the model obtained, the correction factor 'c' was calculated. D1, d1 are the long and short axes of the egg, X, X1 are used for determination of coordinates needed for calculation of h1 and h2. The coordinates of the 3D model of the egg were determined and it was rendered. x = (a+D1*cos(ph).*sin(th)) y = (a+D1.*cos(th)) z = (b+(d1+c1*cos(th)).*sin(th).*sin(ph)) %(in this case "a" and "b" are the start point coordinates of the coordinate system) K 3D Model Preview surf(x,y,z, 'FaceColor', c, 'EdgeColor', 'k'); As a result of the visualization (Figure 3), the influence of coefficient 'c' on the surface formation of egg models was established. The low values of this coefficient result in an elliptical and oval shape. As the values of this coefficient increase, the ovoid shape of the obtained three-dimensional objects is observed. It can be assumed that for different species of birds, it would be more appropriate to apply a model for spherical eggs and those with a more rounded shape. Moreover, the ovoid model would be appropriate if the eggs examined are more conical. As a result of the visualization (Figure 3), the influence of coefficient 'c' on the surface formation of egg models was established. The low values of this coefficient result in an elliptical and oval shape. As the values of this coefficient increase, the ovoid shape of the obtained three-dimensional objects is observed. It can be assumed that for different species of birds, it would be more appropriate to apply a model for spherical eggs and those with a more rounded shape. Moreover, the ovoid model would be appropriate if the eggs examined are more conical.    Figure 5 shows the basic forms of eggs and those of sparrow, mallard, quail. The data presented are for the function = ( / ). It can be seen that the coefficient 'c' can be used to distinguish eggs from the three species of birds tested. Clearly distinguished are eggs from Mallard, which have a tendency to be elepsoid. Sparrow and quail eggs are close in value ( / ), but differ by a factor of 'c'. When analyzing the residuals, there is a lack of  As a result of the visualization (Figure 3), the influence of coefficient 'c' on the surface formation of egg models was established. The low values of this coefficient result in an elliptical and oval shape. As the values of this coefficient increase, the ovoid shape of the obtained three-dimensional objects is observed. It can be assumed that for different species of birds, it would be more appropriate to apply a model for spherical eggs and those with a more rounded shape. Moreover, the ovoid model would be appropriate if the eggs examined are more conical.    Figure 5 shows the basic forms of eggs and those of sparrow, mallard, quail. The data presented are for the function = ( / ). It can be seen that the coefficient 'c' can be used to distinguish eggs from the three species of birds tested. Clearly distinguished are eggs from Mallard, which have a tendency to be elepsoid. Sparrow and quail eggs are close in value ( / ), but differ by a factor of 'c'. When analyzing the residuals, there is a lack of  Figure 5 shows the basic forms of eggs and those of sparrow, mallard, quail. The data presented are for the function c = f (β/α). It can be seen that the coefficient 'c' can be used to distinguish eggs from the three species of birds tested. Clearly distinguished are eggs from Mallard, which have a tendency to be elepsoid. Sparrow and quail eggs are close in value (β/α), but differ by a factor of 'c'. When analyzing the residuals, there is a lack of systematic deviation of the actual data from the theoretical data, which is a sign of their normal distribution. Residuals analysis shows that the model is adequate. The analysis of the standardized coefficients shows that the relationship between angles α and β influence in predicting the 'c' coefficient. The coefficient of the determination of the proposed model is R 2 = 0.96. The standard error is SE = 0.08. All of the results show p-value of the model, less than α = 0.05. It can be considered that the prerequisites of the regression analysis are fulfilled. systematic deviation of the actual data from the theoretical data, which is a sign of their normal distribution. Residuals analysis shows that the model is adequate. The analysis of the standardized coefficients shows that the relationship between angles α and β influence in predicting the 'c' coefficient. The coefficient of the determination of the proposed model is R 2 = 0.96. The standard error is SE = 0.08. All of the results show p-value of the model, less than α = 0.05. It can be considered that the prerequisites of the regression analysis are fulfilled. The proposed algorithm was applied to create 3D egg shapes that were not used in the previous calculations. The resulting error was up to 9%. This shows that in the test, the algorithm had an accuracy of 91%.
The results obtained in this paper improve the assumption of Narushin et al. [10] that the use of algorithms to determine the shape of eggs strongly depends on those of the bird species studied. Mallard eggs have a more elliptical shape and correspondingly lower values of coefficient 'c' (c = 1.55-4.96). In sparrow eggs (c = 9.55-11.19) and quail (c = 11.71-13.11), the form tends to ovoid.
In the present work it is proven that the proposed methods and algorithm for 3D geometric transformations of color digital images of eggs is suitable for application in technical systems, because the accuracy is above 90%.
It can be assumed that for different bird species, the correction factor 'c' may not correspond to the values indicated in this paper. This may be due to defects in the shell of the egg, abnormal shape, or immature eggs.
An advantage of the algorithm proposed here is that the human operator does not need to select points in the image, as is the case with some of the algorithms developed so far [4,7].
The problem with the orientation of the egg in the image remains unresolved. This problem was pointed out by Biggins et al. [20]. According to the authors, the egg should be horizontal when its image is received, as otherwise the size and shape of the created three-dimensional model will be compromised. This was also proven by Titova et al. and Alikhanov et al. [11,28].
In the present work, it was found that the deviation from the horizontal axis of the egg in the image ±10% leads to an error in determining the parameters of the eggs up to 5%. Further analysis is needed about the working speed of the proposed algorithm and the possibilities for its direct implementation in real recognition systems. In addition, the The proposed algorithm was applied to create 3D egg shapes that were not used in the previous calculations. The resulting error was up to 9%. This shows that in the test, the algorithm had an accuracy of 91%.
The results obtained in this paper improve the assumption of Narushin et al. [10] that the use of algorithms to determine the shape of eggs strongly depends on those of the bird species studied. Mallard eggs have a more elliptical shape and correspondingly lower values of coefficient 'c' (c = 1.55-4.96). In sparrow eggs (c = 9.55-11.19) and quail (c = 11.71-13.11), the form tends to ovoid.
In the present work it is proven that the proposed methods and algorithm for 3D geometric transformations of color digital images of eggs is suitable for application in technical systems, because the accuracy is above 90%.
It can be assumed that for different bird species, the correction factor 'c' may not correspond to the values indicated in this paper. This may be due to defects in the shell of the egg, abnormal shape, or immature eggs.
An advantage of the algorithm proposed here is that the human operator does not need to select points in the image, as is the case with some of the algorithms developed so far [4,7].
The problem with the orientation of the egg in the image remains unresolved. This problem was pointed out by Biggins et al. [20]. According to the authors, the egg should be horizontal when its image is received, as otherwise the size and shape of the created three-dimensional model will be compromised. This was also proven by Titova et al. and Alikhanov et al. [11,28].
In the present work, it was found that the deviation from the horizontal axis of the egg in the image ±10% leads to an error in determining the parameters of the eggs up to 5%. Further analysis is needed about the working speed of the proposed algorithm and the possibilities for its direct implementation in real recognition systems. In addition, the work can be continued with comparison of the results with public available datasets, as mention in Manzo et al. [29].

Conclusions
Methods and tools for analyzing and evaluating bird eggs have been developed based on the analysis of the digital image format of their elements, which create three-dimensional models and descriptions of the shape of the egg elements corresponding to their basic shapes. Approaches have been adapted to recognize the basic elements of eggs by their color digital images based on extracted features that create three-dimensional models of eggs.
A method for the formation of three-dimensional models of egg elements is proposed, which describes the nature of the change in the surface of the elements by taking into account the relative lengths and growths of intersecting lines perpendicular to the symmeters and evenly distributed along their length. Based on the descriptions thus obtained, three-dimensional egg-shaped models corresponding to their basic shapes have been defined.
Methods and tools for recognizing eggs based on morphological features and the shape of their elements have been developed, represented by three-dimensional descriptions of the surface, based on the basic geometric parameters of the elements and a set of ratios between them.
A comparative study was performed to evaluate the effect of the methods used to represent the surface of eggs on recognition accuracy. The use of the method for describing the three-dimensional shape of eggs by geometric and morphological characteristics has been found.
Software tools have been developed to implement the proposed digital image analysis methods and procedures, with the purpose of constructing descriptions of the threedimensional shape of eggs, their classification into major groups based on their shape, and the classification accuracy for recognizing different egg species.
The values of the correction factor 'c' have been determined by which the basic threedimensional shapes of the eggs can be described with sufficient accuracy. The advantage of the algorithms and procedures proposed here over the existing ones is that all the basic parameters involved in the calculations are automatically determined.
The deviation from the horizontal axis of the egg in the image ±10% has been found to produce an error in determining the egg parameters up to 5%.
The egg shapes studied were for sparrow, mallard, and wild quails. This is because they are the most studied in Bulgaria. For the future work, a study including species with more extreme egg shapes is needed.
The proposed functional solution of the algorithm allows modification of the recognition procedure and its use in the creation of methods and tools for analysis of basic external characteristics, as well as technical equipment for collecting, cleaning, sorting, packaging, transport, and storage of eggs, for both wild birds and domestic poultry.
The proposed methods and tools for three-dimensional transformation of egg images would be applicable not only for the needs of poultry farming, but also in ornithological research when working with different-shaped varieties of eggs. Experimental results show that the proposed algorithm has sufficient accuracy.
In our work, a comparative analysis of the effectiveness of the algorithm for obtaining 3D egg shapes was proposed, in terms of its error rates. Additional research is needed in the operation of the selected algorithm in its operation on single-board microcomputers, for example, Arduino or Raspberry Pi. Such an analysis would show the working speed of this algorithm and the possibilities for its direct implementation in real recognition systems, applicable directly to portable devices or sorting machines.  Institutional Review Board Statement: Not applicable (The products are from Trakia University, Bulgaria and its laboratories, Collected from the region of Yambol, Bulgaria).