Apple target detection method and device based on digital image processing
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA AGRI UNIV
- Filing Date
- 2024-07-26
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]本发明提供一种基于数字图像处理的苹果目标检测方法及装置,用以解决现有技术中目标检测算法在处理复杂背景和遮挡情况下的鲁棒性不足,导致检测精度和准确性不高的缺陷,实现提升苹果目标的检测识别率
[0037]本发明提供的基于数字图像处理的苹果目标检测方法及装置,通过将苹果图像LAB颜色空间中的AB分量二维数据点集作为k-means算法聚类数目和聚类中心的依据,对二维数据点进行聚类实现对图像的分割,提取到苹果区域。使用分水岭算法对苹果区域中粘连的苹果进行分离,结合苹果边缘凸包各顶点间的距离平均值去除分离后各苹果区域的伪边缘,得到苹果的真实边缘;根据苹果的真实边缘使用最小二乘法拟合圆的最小外接矩形作为候选框,并基于交并比筛选候选框得到苹果预测框,降低了复杂环境的影响,提高了从图像中识别苹果目标的准确性。
Smart Images

Figure CN118968021B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image target detection technology, and in particular to an apple target detection method and apparatus based on digital image processing. Background Technology
[0002] With the continuous advancement of agricultural modernization, automation and intelligent technologies are being applied more and more widely in agricultural production. In automated harvesting, accurate target detection is a prerequisite for efficient harvesting. As apples are a common fruit, research into target detection technology is of great significance for improving the practicality of harvesting robots.
[0003] Traditional apple object detection methods rely on image processing techniques, including color space conversion, thresholding, and edge detection. Existing object detection algorithms lack robustness in handling complex backgrounds and occlusion conditions, resulting in low detection accuracy and precision. Summary of the Invention
[0004] This invention provides an apple target detection method and apparatus based on digital image processing, which solves the shortcomings of existing target detection algorithms in handling complex backgrounds and occlusion, resulting in low detection accuracy and precision, and improves the detection and recognition rate of apple targets.
[0005] This invention provides an apple target detection method based on digital image processing, comprising the following steps:
[0006] The apple image to be detected is converted from the RGB color space to the LAB color space to obtain the apple image to be detected in the LAB color space.
[0007] Based on the A and B channels of the LAB color space, the A and B components of each pixel in the apple image to be detected in the LAB color space are extracted to construct a two-dimensional data point set. The two-dimensional data point set is then clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0008] Based on the watershed algorithm, the apples that are stuck together in the apple region are separated to obtain the apple outline. Based on the average distance between the vertices of the convex hull in the apple outline, the false edges in the apple outline are removed to obtain the true edges of the apple.
[0009] The minimum bounding rectangle of the circle is fitted to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes. The multiple apple candidate boxes are then filtered based on the intersection-union ratio to obtain the apple prediction box.
[0010] According to the present invention, an apple target detection method based on digital image processing includes, before clustering the two-dimensional data point set using the k-means algorithm, the method comprises:
[0011] Based on the A channel of the LAB color space, the histogram features of the A channel color histogram of the apple image to be detected in the LAB color space are determined, and the histogram features include the number and location of maxima.
[0012] Based on the B channel of the LAB color space, the histogram features of the B channel color histogram of the apple image to be detected in the LAB color space are determined.
[0013] The number of clusters in the k-means algorithm is determined to be the number of maxima in the A-channel color histogram, and the cluster centers of the k-means algorithm are determined based on the histogram features of the A-channel color histogram and the histogram features of the B-channel color histogram.
[0014] According to the present invention, an apple target detection method based on digital image processing is provided, wherein the apples adhering to each other in the apple region are separated based on the watershed algorithm to obtain the apple outline, comprising:
[0015] The binary image of the apple region is converted into a distance transform map based on the distance transform, and the distance transform map is normalized to obtain a normalized distance transform map.
[0016] The region with brightness greater than a preset brightness threshold in the normalized distance transformation graph is taken as the internal region of the apple region;
[0017] The inner region is marked, and the outer region outside the inner region is marked;
[0018] Based on the watershed algorithm, the marked regions are guided to separate the adhered apples and obtain the apple outline.
[0019] According to the apple target detection method based on digital image processing provided by the present invention, the calculation formula for normalizing the distance transform map is as follows:
[0020] ;
[0021] in, This is the initial distance transformation map. Normalized distance transformation graph The grayscale value of the pixel at that location. The minimum grayscale value of the initial distance transformation map. This represents the maximum grayscale value of the initial distance transformation map.
[0022] According to the present invention, an apple target detection method based on digital image processing is provided, wherein the method removes false edges in the apple contour based on the average distance between vertices of the convex hull in the apple contour to obtain the true edge of the apple, comprising:
[0023] The convex hull of the edges in the apple contour is determined based on the roll wrapping method, and the distance between two adjacent vertices of the convex hull is calculated.
[0024] If the distance between two adjacent vertices of the convex hull is greater than a preset vertex threshold, the edge segment of the convex hull is determined to be a pseudo edge.
[0025] The false edges are removed to obtain the true edges of the apple.
[0026] According to the present invention, an apple target detection method based on digital image processing is provided, wherein the apple prediction box is obtained by filtering the plurality of apple candidate boxes based on intersection-union comparison (IUCN), comprising:
[0027] Calculate the Intersection over Union (IOU) value between apple candidate boxes;
[0028] Apple candidate boxes whose IOU value is greater than a preset IOU threshold are identified as apple prediction boxes from the plurality of apple candidate boxes.
[0029] The present invention also provides an apple target detection device based on digital image processing, comprising the following modules:
[0030] The conversion module is used to convert the apple image to be detected in the RGB color space to the LAB color space, so as to obtain the apple image to be detected in the LAB color space.
[0031] The apple region extraction module is used to extract the A and B components of each pixel in the apple image to be detected in the LAB color space based on the A and B channels of the LAB color space, construct a two-dimensional data point set, and cluster the two-dimensional data point set based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0032] The edge determination module is used to separate the apples that are stuck together in the apple region based on the watershed algorithm to obtain the apple outline, and to remove the false edges in the apple outline based on the average distance between the vertices of the convex hull in the apple outline to obtain the true edge of the apple.
[0033] The prediction box determination module is used to fit the minimum bounding rectangle of the circle to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes, and to filter the multiple apple candidate boxes based on the intersection-union ratio to obtain the apple prediction box.
[0034] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the apple target detection method based on digital image processing as described above.
[0035] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the apple target detection method based on digital image processing as described above.
[0036] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the apple target detection method based on digital image processing as described above.
[0037] The apple target detection method and apparatus based on digital image processing provided by this invention uses the two-dimensional data point set of AB components in the LAB color space of the apple image as the basis for the number of clusters and cluster centers in the k-means algorithm to cluster the two-dimensional data points to achieve image segmentation and extract the apple region. The watershed algorithm is used to separate the connected apples in the apple region, and the false edges of each apple region are removed by combining the average distance between the vertices of the apple edge convex hull to obtain the true edge of the apple. Based on the true edge of the apple, the minimum bounding rectangle of the least squares fitted circle is used as the candidate box, and the predicted apple box is obtained by filtering the candidate boxes based on the intersection-union ratio (IU). This reduces the influence of complex environments and improves the accuracy of identifying apple targets from images. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0039] Figure 1 This is a flowchart illustrating the apple target detection method based on digital image processing provided by the present invention.
[0040] Figure 2 This is a schematic diagram illustrating the solution of the maximum value of the color histogram of the A channel of an apple image provided by the present invention.
[0041] Figure 3 This is a schematic diagram illustrating the solution of the maximum value of the B-channel color histogram of an apple image provided by the present invention.
[0042] Figure 4 This is a schematic diagram of the initial cluster center selection of the k-means algorithm provided by the present invention.
[0043] Figure 5 This is a schematic diagram of the structure of the apple target detection device based on digital image processing provided by the present invention.
[0044] Figure 6 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0046] Figure 1 This is a flowchart illustrating the apple target detection method based on digital image processing provided by the present invention, as shown below. Figure 1 As shown, the method includes the following:
[0047] Step 110: Convert the apple image to be detected in RGB color space to LAB color space to obtain the apple image to be detected in LAB color space.
[0048] Step 120: Based on the A and B channels of the LAB color space, extract the A and B components of each pixel in the apple image to be detected in the LAB color space to construct a two-dimensional data point set, and cluster the two-dimensional data point set based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0049] Step 130: Based on the watershed algorithm, separate the apples that are stuck together in the apple region to obtain the apple outline, and based on the average distance between the vertices of the convex hull in the apple outline, remove the false edges in the apple outline to obtain the real edges of the apple.
[0050] Step 140: Fit the minimum bounding rectangle of the circle to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes, and filter the multiple apple candidate boxes based on the intersection-union ratio to obtain the apple prediction box.
[0051] The execution subject of the apple target detection method based on digital image processing provided by this invention can be an electronic device, a component in an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., while a non-mobile electronic device can be a server, network attached storage (NAS), or personal computer (PC), etc. This invention does not impose specific limitations.
[0052] The following example, using a computer executing the apple target detection method based on digital image processing provided by this invention, illustrates the technical solution of this invention in detail.
[0053] In step 110, the apple image to be detected in the RGB color space is converted to the LAB color space to obtain the apple image to be detected in the LAB color space.
[0054] The RGB color space consists of three color channels: red (R), green (G), and blue (B), with each channel typically having a value between 0 and 255. The LAB color space, on the other hand, includes one lightness channel (L) and two color channels (A and B). The A channel represents the range from red to green, and the B channel represents the range from yellow to blue.
[0055] Specifically, this can be achieved using image processing software. Image processing software such as Photoshop and GIMP usually have built-in color space conversion functions, which can directly convert RGB images to LAB images. In programming environments, this conversion can also be easily achieved using MATLAB, Python's Pillow library, or OpenCV library.
[0056] In step 120, based on the A and B channels of the LAB color space, the A and B components of each pixel in the apple image to be detected in the LAB color space are extracted to construct a two-dimensional data point set. Then, the two-dimensional data point set is clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0057] Constructing a two-dimensional data point set can serve as the basis for determining the number of clusters and cluster centers in the k-means algorithm. The specific process can be as follows:
[0058] First, find the number of maxima in the color histogram of channel A. and location Then, calculate the number of maxima in the color histogram of channel b. and location Since the apple region mainly occupies the a channel, the number of maxima in the a channel color histogram is reduced. As the number of clusters; initial cluster centers to be determined. have Select from them. One was used as the initial cluster center.
[0059] Specifically, such as Figure 2 The present invention provides a schematic diagram for solving the maximum value of the A-channel color histogram of an apple image and... Figure 3 The schematic diagram of solving the maximum value of the B channel color histogram of an apple image provided by this invention is shown. The specific steps for solving the maximum value of each channel color histogram are as follows:
[0060] Calculate the color histogram for each channel separately, and the histogram's... The axis represents the pixel value. The axis represents the number of pixels;
[0061] The fitting curves of the color histograms of each channel are obtained by smoothing the fit, and the maximum and minimum values of the fitting curves are obtained.
[0062] For the first maximum of the fitted curve, search for the maximum value of the color histogram within the interval from the start of the color histogram to the first minimum of the fitted curve, and use this as the maximum value of the color histogram for that interval. For the last maximum of the fitted curve, search for the maximum value of the color histogram within the interval from the last minimum of the fitted curve to the end of the color histogram, and use this as the maximum value of the color histogram for that interval. For the remaining maximums of the fitted curve, search for the maximum value of the color histogram within the interval from the preceding minimum to the following minimum, and use this as the maximum value of the color histogram for that interval.
[0063] Specifically, such as Figure 4 The schematic diagram of the initial cluster center selection of the k-means algorithm provided by this invention is shown, wherein the undetermined initial cluster centers... have Select from them. One was used as the initial cluster center, including:
[0064] Select As the first initial cluster center;
[0065] Select the cluster furthest from the first initial cluster center. As the second initial cluster center;
[0066] If the number of clusters is greater than 2, then proceed sequentially from... Select a point on the straight line as the next initial cluster center, such that the distance from that point to other cluster centers is maximized; repeat this step until all cluster centers are selected.
[0067] After determining the cluster centers and the number of clusters, the two-dimensional data point set is clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0068] In step 130, the apples that are stuck together in the apple region are separated based on the watershed algorithm to obtain the apple outline. Based on the average distance between the vertices of the convex hull in the apple outline, the false edges in the apple outline are removed to obtain the true edges of the apple.
[0069] The watershed algorithm is used to separate apples that are stuck together in the apple region. Specifically, this can include:
[0070] The binary image of the apple region is converted into a distance transform map through distance transformation and then normalized. Regions with brightness greater than a set threshold in the normalized distance transform map are designated as internal apple regions. The binary image of the apple region is dilated, and the internally marked regions are subtracted and labeled as unknown regions; the remaining regions are designated as external regions. These labeled regions guide the watershed algorithm to separate the adhered apples. The normalization formula for the distance transform map is as follows:
[0071] ;
[0072] in, This is the initial distance transformation map. Normalized distance transformation graph The grayscale value of the pixel at that location. The minimum grayscale value of the initial distance transformation map. This represents the maximum grayscale value of the initial distance transformation map.
[0073] By combining the average distance between vertices of the apple's edge convex hull to remove the false edges of each separated apple region, the true edges of the apple are obtained, including:
[0074] The edges of the separated apple region are obtained using the Canny edge detection algorithm;
[0075] The convex hull of the apple region's edge is obtained using the roll-wrap method, and the distance between two adjacent vertices of the convex hull is calculated.
[0076] The average distance between all vertices is used as a threshold. If the distance between two adjacent vertices is greater than this threshold, the edge segment is considered a false edge and needs to be removed; if the distance between two vertices is less than or equal to the threshold, the edge segment is considered a true edge and is retained. After removing false edges, the true edge of the apple is obtained.
[0077] In step 140, the minimum bounding rectangle of the circle is fitted to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes. The multiple apple candidate boxes are then filtered based on the intersection-union ratio to obtain the apple prediction box.
[0078] Intersection over Union (IoU) is a metric that measures the degree of overlap between two regions, and is commonly used in object detection to evaluate the matching degree between predicted and ground truth bounding boxes. IoU values range from 0 (no overlap) to 1 (complete overlap).
[0079] For each candidate bounding box, calculate its Intersection over Union (IoU) with the ground truth bounding box. This typically involves calculating the intersection and union of the two rectangular regions, and then finding the ratio of the intersection area to the union area.
[0080] Candidate boxes are filtered based on their IoU (Intersection over Union) values. Typically, a threshold is set; a candidate box is considered a valid apple prediction box only if its IoU with the ground truth box is greater than this threshold.
[0081] Set an IOU threshold and calculate the IOU between candidate boxes. If the IOU is greater than the threshold, it is considered a target, and the average of the coordinates of these candidate boxes is used as the coordinates of the predicted box.
[0082] This invention provides an apple target detection method based on digital image processing. It uses the AB component two-dimensional data point set in the LAB color space of the apple image as the basis for the number and centers of clusters in the k-means algorithm to segment the image and extract the apple region. The watershed algorithm is used to separate adhered apples within the apple region. The average distance between vertices of the apple's edge convex hull is then used to remove false edges in the separated apple regions, yielding the true edges of the apple. Based on the true edges of the apple, the minimum bounding rectangle of a circle fitted using the least squares method is used as a candidate bounding box. Finally, the predicted apple bounding box is obtained by filtering the candidate bounding boxes based on the intersection-union ratio (IU). This method reduces the influence of complex environments and improves the accuracy of identifying apple targets from images.
[0083] In one embodiment, before clustering the two-dimensional data point set based on the k-means algorithm, the method includes: determining the histogram features of the A-channel color histogram of the apple image to be detected in the LAB color space based on the A-channel, wherein the histogram features include the number and location of maxima; determining the histogram features of the B-channel color histogram of the apple image to be detected in the LAB color space based on the B-channel; determining the number of clusters for the k-means algorithm as the number of maxima of the A-channel color histogram, and determining the cluster centers of the k-means algorithm based on the histogram features of the A-channel color histogram and the histogram features of the B-channel color histogram.
[0084] Specifically, constructing a two-dimensional data point set can serve as the basis for determining the number of clusters and cluster centers in the k-means algorithm. The specific process can be as follows:
[0085] First, find the number of maxima in the color histogram of channel A. and location Then, calculate the number of maxima in the color histogram of channel b. and location Since the apple region mainly occupies the a channel, the number of maxima in the a channel color histogram is reduced. As the number of clusters; initial cluster centers to be determined. have Select from them. One was used as the initial cluster center.
[0086] Specifically, the steps to find the maxima of the color histogram for each channel are as follows:
[0087] Calculate the color histogram for each channel separately, and the histogram's... The axis represents the pixel value. The axis represents the number of pixels;
[0088] The fitting curves of the color histograms of each channel are obtained by smoothing the fit, and the maximum and minimum values of the fitting curves are obtained.
[0089] For the first maximum of the fitted curve, search for the maximum value of the color histogram within the interval from the start of the color histogram to the first minimum of the fitted curve, and use this as the maximum value of the color histogram for that interval. For the last maximum of the fitted curve, search for the maximum value of the color histogram within the interval from the last minimum of the fitted curve to the end of the color histogram, and use this as the maximum value of the color histogram for that interval. For the remaining maximums of the fitted curve, search for the maximum value of the color histogram within the interval from the preceding minimum to the following minimum, and use this as the maximum value of the color histogram for that interval.
[0090] Specifically, the initial cluster centers to be determined have Select from them. One was used as the initial cluster center, including:
[0091] Select As the first initial cluster center;
[0092] Select the cluster furthest from the first initial cluster center. As the second initial cluster center;
[0093] If the number of clusters is greater than 2, then proceed sequentially from... Select a point on the straight line as the next initial cluster center, such that the distance from that point to other cluster centers is maximized; repeat this step until all cluster centers are selected.
[0094] After determining the cluster centers and the number of clusters, the two-dimensional data point set is clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0095] In one embodiment, separating the adhered apples in the apple region based on the watershed algorithm to obtain the apple outline includes: converting the binary image of the apple region into a distance transform map based on distance transform, and normalizing the distance transform map to obtain a normalized distance transform map; identifying regions in the normalized distance transform map with brightness greater than a preset brightness threshold as internal regions of the apple region; marking the internal regions and marking the external regions outside the internal regions; and guiding the marked regions based on the watershed algorithm to separate the adhered apples and obtain the apple outline.
[0096] Specifically, the binary image of the apple region is converted into a distance transform map through distance transformation and then normalized. Regions with brightness greater than a set threshold in the normalized distance transform map are marked as internal apple regions. The binary image of the apple region is dilated, and the internally marked regions are subtracted and designated as unknown regions; the remaining regions are marked as external regions. These marked regions guide the watershed algorithm to separate the adhered apples. The normalization formula for the distance transform map is as follows:
[0097] ;
[0098] in, This is the initial distance transformation map. Normalized distance transformation graph The grayscale value of the pixel at that location. The minimum grayscale value of the initial distance transformation map. This represents the maximum grayscale value of the initial distance transformation map.
[0099] In one embodiment, based on the average distance between vertices of the convex hull in the apple contour, false edges in the apple contour are removed to obtain the true edge of the apple. This includes: determining the convex hull of the edge in the apple contour based on the wrapping method, and calculating the distance between two adjacent vertices of the convex hull; if the distance between two adjacent vertices of the convex hull is greater than a preset vertex threshold, determining the edge segment of the convex hull as a false edge; and removing the false edge to obtain the true edge of the apple.
[0100] By combining the average distance between vertices of the apple's edge convex hull to remove the false edges of each separated apple region, the true edges of the apple are obtained, including:
[0101] The edges of the separated apple region are obtained using the Canny edge detection algorithm;
[0102] The convex hull of the apple region's edge is obtained using the roll-wrap method, and the distance between two adjacent vertices of the convex hull is calculated.
[0103] The average distance between all vertices is used as a threshold. If the distance between two adjacent vertices is greater than the threshold, the edge segment is considered a false edge and needs to be removed; if the distance between two vertices is less than or equal to the threshold, the edge segment is considered a true edge and is retained.
[0104] In one embodiment, filtering the plurality of apple candidate boxes based on the intersection-union ratio (IOU) to obtain apple prediction boxes includes: calculating the intersection-union ratio (IOU) values between the apple candidate boxes; and determining apple candidate boxes whose IOU values are greater than a preset IOU threshold as apple prediction boxes from the plurality of apple candidate boxes.
[0105] Intersection over Union (IoU) is a metric that measures the degree of overlap between two regions, and is commonly used in object detection to evaluate the matching degree between predicted and ground truth bounding boxes. IoU values range from 0 (no overlap) to 1 (complete overlap).
[0106] For each candidate bounding box, calculate its Intersection over Union (IoU) with the ground truth bounding box. This typically involves calculating the intersection and union of the two rectangular regions, and then finding the ratio of the intersection area to the union area.
[0107] Candidate boxes are filtered based on their IoU (Intersection over Union) values. Typically, a preset IoU threshold is set; a candidate box is considered a valid Apple prediction box only if its IoU with the ground truth box exceeds this threshold.
[0108] Optionally, a preset IOU threshold is determined and the IOU between candidate boxes is calculated. If the IOU is greater than the preset IOU threshold, it is considered a target, and the average of the coordinates of these candidate boxes is used as the coordinates of the predicted box.
[0109] The apple target detection device based on digital image processing provided by the present invention is described below. The apple target detection device based on digital image processing described below can be referred to in correspondence with the apple target detection method based on digital image processing described above. Figure 5 As shown, the device includes:
[0110] The conversion module 510 is used to convert the apple image to be detected in RGB color space to LAB color space to obtain the apple image to be detected in LAB color space.
[0111] The apple region extraction module 520 is used to extract the A and B components of each pixel in the apple image to be detected in the LAB color space based on the A and B channels of the LAB color space, construct a two-dimensional data point set, and cluster the two-dimensional data point set based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0112] The edge determination module 530 is used to separate the apples that are stuck together in the apple region based on the watershed algorithm to obtain the apple outline, and to remove the false edges in the apple outline based on the average distance between the vertices of the convex hull in the apple outline to obtain the real edge of the apple.
[0113] The prediction box determination module 540 is used to fit the minimum bounding rectangle of the circle to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes, and to filter the multiple apple candidate boxes based on the intersection-union ratio to obtain the apple prediction box.
[0114] The apple target detection device based on digital image processing provided by this invention uses the two-dimensional data point set of AB components in the LAB color space of the apple image as the basis for the number of clusters and cluster centers in the k-means algorithm to cluster the two-dimensional data points and achieve image segmentation, extracting the apple region. The watershed algorithm is used to separate the connected apples in the apple region, and the false edges of each apple region after separation are removed by combining the average distance between the vertices of the apple edge convex hull, obtaining the true edge of the apple. Based on the true edge of the apple, the minimum bounding rectangle of the least squares fitted circle is used as the candidate box, and the apple prediction box is obtained by filtering the candidate boxes based on the intersection-union ratio. This reduces the influence of complex environments and improves the accuracy of identifying apple targets from images.
[0115] In one embodiment, the apple region extraction module 520 is specifically used for:
[0116] Before clustering the two-dimensional data point set based on the k-means algorithm, the following steps are included:
[0117] Based on the A channel of the LAB color space, the histogram features of the A channel color histogram of the apple image to be detected in the LAB color space are determined, and the histogram features include the number and location of maxima.
[0118] Based on the B channel of the LAB color space, the histogram features of the B channel color histogram of the apple image to be detected in the LAB color space are determined.
[0119] The number of clusters in the k-means algorithm is determined to be the number of maxima in the A-channel color histogram, and the cluster centers of the k-means algorithm are determined based on the histogram features of the A-channel color histogram and the histogram features of the B-channel color histogram.
[0120] In one embodiment, the edge determination module 530 is specifically used for:
[0121] The process of separating the adhered apples in the apple region based on the watershed algorithm to obtain the apple outline includes:
[0122] The binary image of the apple region is converted into a distance transform map based on the distance transform, and the distance transform map is normalized to obtain a normalized distance transform map.
[0123] The region with brightness greater than a preset brightness threshold in the normalized distance transformation graph is taken as the internal region of the apple region;
[0124] The inner region is marked, and the outer region outside the inner region is marked;
[0125] Based on the watershed algorithm, the marked regions are guided to separate the adhered apples and obtain the apple outline.
[0126] In one embodiment, the edge determination module 530 is further configured to:
[0127] The calculation formula for normalizing the distance transformation graph is as follows:
[0128] ;
[0129] in, This is the initial distance transformation map. Normalized distance transformation graph The grayscale value of the pixel at that location. The minimum grayscale value of the initial distance transformation map. This represents the maximum grayscale value of the initial distance transformation map.
[0130] In one embodiment, the edge determination module 530 is further configured to:
[0131] The step of removing false edges from the apple contour based on the average distance between vertices of the convex hull in the apple contour to obtain the true edge of the apple includes:
[0132] The convex hull of the edges in the apple contour is determined based on the roll wrapping method, and the distance between two adjacent vertices of the convex hull is calculated.
[0133] If the distance between two adjacent vertices of the convex hull is greater than a preset vertex threshold, the edge segment of the convex hull is determined to be a pseudo edge.
[0134] The false edges are removed to obtain the true edges of the apple.
[0135] In one embodiment, the prediction box determination module 540 is specifically used for:
[0136] The step of filtering the multiple apple candidate boxes based on intersection-union comparison to obtain apple prediction boxes includes:
[0137] Calculate the Intersection over Union (IOU) value between apple candidate boxes;
[0138] Apple candidate boxes whose IOU value is greater than a preset IOU threshold are identified as apple prediction boxes from the plurality of apple candidate boxes.
[0139] Figure 6 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 6 As shown, the electronic device may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, the communications interface 620, and the memory 630 communicate with each other via the communication bus 640. The processor 610 can call logical instructions in the memory 630 to execute an apple target detection method based on digital image processing. This method includes converting the apple image to be detected in the RGB color space to the LAB color space to obtain a LAB color space apple image to be detected.
[0140] Based on the A and B channels of the LAB color space, the A and B components of each pixel in the apple image to be detected in the LAB color space are extracted to construct a two-dimensional data point set. The two-dimensional data point set is then clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0141] Based on the watershed algorithm, the apples that are stuck together in the apple region are separated to obtain the apple outline. Based on the average distance between the vertices of the convex hull in the apple outline, the false edges in the apple outline are removed to obtain the true edges of the apple.
[0142] The minimum bounding rectangle of the circle is fitted to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes. The multiple apple candidate boxes are then filtered based on the intersection-union ratio to obtain the apple prediction box.
[0143] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0144] On the other hand, the present invention also provides a computer program product, the computer program product including a computer program, the computer program being able to be stored on a non-transitory computer-readable storage medium, the computer program being executed by a processor, the computer being able to execute the apple target detection method based on digital image processing provided by the above methods, the method including: converting the apple image to be detected in RGB color space to LAB color space to obtain the apple image to be detected in LAB color space;
[0145] Based on the A and B channels of the LAB color space, the A and B components of each pixel in the apple image to be detected in the LAB color space are extracted to construct a two-dimensional data point set. The two-dimensional data point set is then clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0146] Based on the watershed algorithm, the apples that are stuck together in the apple region are separated to obtain the apple outline. Based on the average distance between the vertices of the convex hull in the apple outline, the false edges in the apple outline are removed to obtain the true edges of the apple.
[0147] The minimum bounding rectangle of the circle is fitted to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes. The multiple apple candidate boxes are then filtered based on the intersection-union ratio to obtain the apple prediction box.
[0148] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the apple target detection method based on digital image processing provided by the above methods, the method comprising: converting an apple image to be detected in RGB color space to LAB color space to obtain an apple image to be detected in LAB color space;
[0149] Based on the A and B channels of the LAB color space, the A and B components of each pixel in the apple image to be detected in the LAB color space are extracted to construct a two-dimensional data point set. The two-dimensional data point set is then clustered based on the k-means algorithm to determine the apple region of the apple image to be detected.
[0150] Based on the watershed algorithm, the apples that are stuck together in the apple region are separated to obtain the apple outline. Based on the average distance between the vertices of the convex hull in the apple outline, the false edges in the apple outline are removed to obtain the true edges of the apple.
[0151] The minimum bounding rectangle of the circle is fitted to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes. The multiple apple candidate boxes are then filtered based on the intersection-union ratio to obtain the apple prediction box.
[0152] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0153] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An apple target detection method based on digital image processing, characterized in that, The method includes: The apple image to be detected is converted from the RGB color space to the LAB color space to obtain the apple image to be detected in the LAB color space. Based on the A and B channels of the LAB color space, the A and B components of each pixel in the apple image to be detected in the LAB color space are extracted to construct a two-dimensional data point set. The two-dimensional data point set is then clustered based on the k-means algorithm to determine the apple region of the apple image to be detected. Based on the watershed algorithm, the apples that are stuck together in the apple region are separated to obtain the apple outline. Based on the average distance between the vertices of the convex hull in the apple outline, the false edges in the apple outline are removed to obtain the true edges of the apple. The minimum bounding rectangle of the circle is fitted to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes. The multiple apple candidate boxes are then filtered based on the intersection-union ratio to obtain the apple prediction box. The process of separating the adhered apples in the apple region based on the watershed algorithm to obtain the apple outline includes: The binary image of the apple region is converted into a distance transform map based on the distance transform, and the distance transform map is normalized to obtain a normalized distance transform map. The region with brightness greater than a preset brightness threshold in the normalized distance transformation graph is taken as the internal region of the apple region; The inner region is marked, and the outer region outside the inner region is marked; Based on the watershed algorithm, the marked regions are guided to separate the stuck apples and obtain the apple outline; The calculation formula for normalizing the distance transformation graph is as follows: ; in, This is the initial distance transformation map. Normalized distance transformation graph The grayscale value of the pixel at that location. The minimum grayscale value of the initial distance transformation map. This represents the maximum grayscale value of the initial distance transformation map.
2. The apple target detection method based on digital image processing according to claim 1, characterized in that, Before clustering the two-dimensional data point set based on the k-means algorithm, the following steps are included: Based on the A channel of the LAB color space, the histogram features of the A channel color histogram of the apple image to be detected in the LAB color space are determined, and the histogram features include the number and location of maxima. Based on the B channel of the LAB color space, the histogram features of the B channel color histogram of the apple image to be detected in the LAB color space are determined. The number of clusters in the k-means algorithm is determined to be the number of maxima in the A-channel color histogram, and the cluster centers of the k-means algorithm are determined based on the histogram features of the A-channel color histogram and the histogram features of the B-channel color histogram.
3. The apple target detection method based on digital image processing according to claim 1, wherein removing false edges in the apple contour based on the average distance between vertices of the convex hull in the apple contour to obtain the true edge of the apple includes: The convex hull of the edges in the apple contour is determined based on the roll wrapping method, and the distance between two adjacent vertices of the convex hull is calculated. If the distance between two adjacent vertices of the convex hull is greater than a preset vertex threshold, the edge segment of the convex hull is determined to be a pseudo edge. The false edges are removed to obtain the true edges of the apple.
4. The apple target detection method based on digital image processing according to claim 1, wherein the step of filtering the plurality of apple candidate boxes based on intersection-union comparison to obtain apple prediction boxes includes: Calculate the Intersection over Union (IOU) value between apple candidate boxes; Apple candidate boxes whose IOU value is greater than a preset IOU threshold are identified as apple prediction boxes from the plurality of apple candidate boxes.
5. An apple target detection device based on digital image processing, characterized in that, include: The conversion module is used to convert the apple image to be detected in the RGB color space to the LAB color space, so as to obtain the apple image to be detected in the LAB color space. The apple region extraction module is used to extract the A and B components of each pixel in the apple image to be detected in the LAB color space based on the A and B channels of the LAB color space, construct a two-dimensional data point set, and cluster the two-dimensional data point set based on the k-means algorithm to determine the apple region of the apple image to be detected. The edge determination module is used to separate the apples that are stuck together in the apple region based on the watershed algorithm to obtain the apple outline, and to remove the false edges in the apple outline based on the average distance between the vertices of the convex hull in the apple outline to obtain the true edge of the apple. The prediction box determination module is used to fit the minimum bounding rectangle of the circle to the true edge of the apple using the least squares method to obtain multiple apple candidate boxes, and to filter the multiple apple candidate boxes based on the intersection-union ratio to obtain the apple prediction box. The step of separating the adhered apples in the apple region based on the watershed algorithm to obtain the apple outline includes: The binary image of the apple region is converted into a distance transform map based on the distance transform, and the distance transform map is normalized to obtain a normalized distance transform map. The region with brightness greater than a preset brightness threshold in the normalized distance transformation graph is taken as the internal region of the apple region; The inner region is marked, and the outer region outside the inner region is marked; Based on the watershed algorithm, the marked regions are guided to separate the stuck apples and obtain the apple outline; The calculation formula for normalizing the distance transformation graph is as follows: ; in, This is the initial distance transformation map. Normalized distance transformation graph The grayscale value of the pixel at that location. The minimum grayscale value of the initial distance transformation map. This represents the maximum grayscale value of the initial distance transformation map.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the apple target detection method based on digital image processing as described in any one of claims 1 to 4.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the apple target detection method based on digital image processing as described in any one of claims 1 to 4.
8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the apple target detection method based on digital image processing as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Target detection method and system for open scene
CN117853792A
Method and system for selecting detection box using mask r-CNN, and electronic device and storage medium
WO2021051601A1