TWI661393B - Image segmentation method, computer program, storage medium, and electronic device - Google Patents
Image segmentation method, computer program, storage medium, and electronic device Download PDFInfo
- Publication number
- TWI661393B TWI661393B TW107139740A TW107139740A TWI661393B TW I661393 B TWI661393 B TW I661393B TW 107139740 A TW107139740 A TW 107139740A TW 107139740 A TW107139740 A TW 107139740A TW I661393 B TWI661393 B TW I661393B
- Authority
- TW
- Taiwan
- Prior art keywords
- image
- bar graph
- segmentation
- value
- computer program
- Prior art date
Links
Landscapes
- Image Analysis (AREA)
Abstract
一種影像分割方法,所述方法包括:獲取影像和所述影像的深度圖像;獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標;採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心;確定長條圖中兩個類別的中心之間的對應縱坐標值最小的橫坐標值為分割閾值;確定所述分割閾值是否滿足預設條件;當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域。本發明還提供一種電腦程式、存儲介質及電子裝置,可避免在影像深度分佈連續的位置進行前背景分割。An image segmentation method, the method includes: obtaining an image and a depth image of the image; obtaining a bar graph of the depth image, the bar graph including an abscissa and an ordinate; using a clustering algorithm to The bar graph data is clustered to obtain the two categories and the centers of the two categories; determine that the abscissa corresponding to the smallest vertical coordinate value between the centers of the two categories in the bar graph is the segmentation threshold; determine the segmentation threshold Whether a preset condition is satisfied; when the segmentation threshold value satisfies the preset condition, the image is segmented into a foreground and a background area according to the segmentation threshold value. The invention also provides a computer program, a storage medium and an electronic device, which can avoid front-background segmentation at positions where the image depth distribution is continuous.
Description
本發明涉及數位影像處理技術領域,特別涉及一種影像分割方法、電腦程式、存儲介質及電子裝置。The invention relates to the technical field of digital image processing, in particular to an image segmentation method, a computer program, a storage medium and an electronic device.
目前,影像的後期處理,例如背景虛擬處理,需要事先將影像進行前背景分割處理。然而,現有的影像進行前背景分割處理往往存在在影像深度分佈連續的位置進行分割導致影像的前景和背景分割不恰當,進而影響影像的後期處理。At present, post-processing of images, such as background virtual processing, requires pre-background segmentation processing of the image in advance. However, the existing background segmentation processing of existing images often involves segmentation at positions where the image depth distribution is continuous, resulting in improper foreground and background segmentation of the image, which will affect the post-processing of the image.
鑒於以上內容,有必要提供一種影像分割方法、電腦程式、存儲介質及電子裝置,可避免在影像深度分佈連續的位置進行前背景分割。In view of the above, it is necessary to provide an image segmentation method, a computer program, a storage medium, and an electronic device, which can avoid front-background segmentation at locations where the image depth distribution is continuous.
本發明的第一方面提供一種影像分割方法,所述方法包括:A first aspect of the present invention provides an image segmentation method. The method includes:
獲取影像和所述影像的深度圖像;Acquiring an image and a depth image of the image;
獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標;Acquiring a bar graph of the depth image, where the bar graph includes an abscissa and an ordinate;
採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心;The clustering algorithm is used to cluster the bar graph data to obtain two categories and the centers of the two categories;
確定長條圖中兩個類別的中心之間的對應縱坐標值最小的橫坐標值為分割閾值;Determining that the abscissa corresponding to the smallest ordinate value between the centers of the two categories in the bar graph is the segmentation threshold;
確定所述分割閾值是否滿足預設條件;Determining whether the segmentation threshold value satisfies a preset condition;
當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域。When the segmentation threshold value satisfies a preset condition, the image is segmented into a foreground and a background region according to the segmentation threshold value.
較佳的,所述獲取所述影像的深度圖像包括:Preferably, the obtaining a depth image of the image includes:
藉由雙目匹配演算法或者深度圖像採集裝置獲取所述影像的深度圖像。A depth image of the image is acquired by a binocular matching algorithm or a depth image acquisition device.
較佳的,所述預設條件為所述長條圖中以所述分割閾值為中心的預設範圍內的縱坐標值的平均值小於預設值。或者,所述預設條件為所述長條圖中所述分割閾值對應的縱坐標值小於預設值。Preferably, the preset condition is that an average value of the ordinate values in a preset range centered on the segmentation threshold in the bar graph is smaller than a preset value. Alternatively, the preset condition is that an ordinate value corresponding to the segmentation threshold in the bar graph is smaller than a preset value.
較佳的,所述方法還包括:Preferably, the method further includes:
當所述分割閾值不滿足預設條件時,確定所述影像不適合分割成所述前景和所述背景兩個區域。When the segmentation threshold does not satisfy a preset condition, it is determined that the image is not suitable for segmentation into the foreground and the background regions.
較佳的,所述長條圖中的所述橫坐標代表所述深度圖像的圖元的深度值;Preferably, the abscissa in the bar graph represents a depth value of a primitive of the depth image;
所述長條圖中的所述縱坐標代表對應每一所述深度值的所述圖元的個數。The ordinate in the bar graph represents the number of the primitives corresponding to each of the depth values.
較佳的,所述聚類演算法為K-means演算法。Preferably, the clustering algorithm is a K-means algorithm.
本發明的第二方面提供一種電腦程式,所述電腦程式包括至少一個電腦程式指令,所述至少一個電腦程式指令用於被處理器執行以實現如上任意一項所述的影像分割方法。A second aspect of the present invention provides a computer program. The computer program includes at least one computer program instruction, and the at least one computer program instruction is executed by a processor to implement the image segmentation method according to any one of the above.
本發明的協力廠商面提供一種存儲介質,所述存儲介質存儲至少一個電腦程式指令,所述至少一個電腦程式指令用於被處理器執行以實現如上任意一項所述的影像分割方法。The third-party vendor of the present invention provides a storage medium that stores at least one computer program instruction, and the at least one computer program instruction is used by a processor to implement the image segmentation method according to any one of the above.
本發明的第四方面提供一種電子裝置,所述電子裝置包括處理器及記憶體,所述處理器用於執行所述記憶體中存儲的至少一個電腦程式指令以實現如上任意一項所述的影像分割方法。According to a fourth aspect of the present invention, an electronic device is provided. The electronic device includes a processor and a memory, and the processor is configured to execute at least one computer program instruction stored in the memory to implement the image according to any one of the foregoing Segmentation method.
本方案藉由獲取影像和所述影像的深度圖像;獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標;採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心;確定長條圖中兩個類別的中心之間的對應縱坐標值最小的橫坐標值為分割閾值;確定所述分割閾值是否滿足預設條件;當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域,避免在影像深度分佈連續的位置進行前背景分割。In this solution, an image and a depth image of the image are obtained; a bar graph of the depth image is obtained, and the bar graph includes an abscissa and an ordinate; a clustering algorithm is used to aggregate the bar graph data; Class to obtain two categories and the centers of the two categories; determine that the abscissa value corresponding to the smallest ordinate value between the centers of the two categories in the bar graph is the segmentation threshold value; determine whether the segmentation threshold value meets a preset condition; When the segmentation threshold value satisfies a preset condition, the image is segmented into foreground and background regions according to the segmentation threshold value, so as to avoid front background segmentation at positions where image depth distribution is continuous.
下面將結合本發明實施方式中的附圖,對本發明實施方式中的技術方案進行清楚、完整地描述,顯然,所描述的實施方式僅僅是本發明一部分實施方式,而不是全部的實施方式。基於本發明中的實施方式,本領域具有通常技藝者在沒有付出創造性勞動前提下所獲得的所有其他實施方式,都屬於本發明保護的範圍。In the following, the technical solutions in the embodiments of the present invention will be clearly and completely described with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all of them. Based on the embodiments of the present invention, all other embodiments obtained by a person skilled in the art without paying any creative labor belong to the protection scope of the present invention.
實施例一Example one
圖1是本發明實施例一提供的影像分割方法的流程圖。根據不同的需求,該流程圖中步驟的順序可以改變,某些步驟可以省略。所述方法應用於電子裝置中,所述電子裝置可以為任何一種電子產品,例如,個人電腦、平板電腦、智慧手機、個人數位助理(Personal Digital Assistant,PDA)等。如圖1所示,所述影像分割方法可以包括以下步驟:FIG. 1 is a flowchart of an image segmentation method according to a first embodiment of the present invention. According to different requirements, the order of steps in this flowchart can be changed, and some steps can be omitted. The method is applied to an electronic device, and the electronic device may be any kind of electronic product, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), and the like. As shown in FIG. 1, the image segmentation method may include the following steps:
步驟S11,獲取影像和所述影像的深度圖像。Step S11: Obtain an image and a depth image of the image.
所述獲取影像和所述影像的深度圖像可包括:獲取影像,並藉由雙目匹配演算法獲取影像的深度圖像。所述獲取影像和所述影像的深度圖像還可包括:藉由深度圖像採集裝置獲取影像和所述影像的深度圖像。其中,所述深度圖像採集裝置可直接採集影像及影像的深度圖像。在本實施例中,所述深度圖像採集裝置可為Kinect攝像機。在其他實施例中,所述深度圖像採集裝置可為PrimeSense等感測器。The acquiring an image and a depth image of the image may include: acquiring an image, and acquiring a depth image of the image by using a binocular matching algorithm. The acquiring the image and the depth image of the image may further include: acquiring the image and the depth image of the image by a depth image acquisition device. The depth image acquisition device can directly acquire an image and a depth image of the image. In this embodiment, the depth image acquisition device may be a Kinect camera. In other embodiments, the depth image acquisition device may be a sensor such as PrimeSense.
所述深度圖像為單色圖像,其大小和所述影像相同。所述深度圖像的灰度值為所述影像的圖元的深度值。所述深度值為所述影像所拍攝的景物和所述深度圖像採集裝置之間的距離。The depth image is a monochrome image, and its size is the same as the image. A gray value of the depth image is a depth value of a primitive of the image. The depth value is a distance between a scene captured by the image and the depth image acquisition device.
步驟S12,獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標。Step S12: Obtain a bar graph of the depth image, where the bar graph includes an abscissa and an ordinate.
在本實施例中,在獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標之前,本方法還對所述深度圖像進行處理來消除雜訊。所述處理可為圖像平滑處理。在本實施例中,所述圖像平滑處理可為鄰域平均法、中值濾波法等等。In this embodiment, before obtaining a bar graph of the depth image, the bar graph includes an abscissa and an ordinate, the method further processes the depth image to eliminate noise. The processing may be an image smoothing process. In this embodiment, the image smoothing process may be a neighborhood average method, a median filter method, or the like.
在本實施例中,所述長條圖為深度長條圖。在本實施例中,所述長條圖反映了所述深度圖像中具有所述深度值的圖元的個數,如圖2所示。其中,所述長條圖的橫坐標代表所述深度圖像的圖元的深度值,所述長條圖的縱坐標代表對應每一深度值的所述圖元的個數。在本實施例中,所述深度值的範圍是[0,255],所述圖元的個數的範圍是[0,3000]。In this embodiment, the bar graph is a deep bar graph. In this embodiment, the bar graph reflects the number of primitives having the depth value in the depth image, as shown in FIG. 2. The abscissa of the bar graph represents the depth value of the primitives of the depth image, and the ordinate of the bar graph represents the number of the primitives corresponding to each depth value. In this embodiment, the range of the depth value is [0,255], and the range of the number of primitives is [0,3000].
步驟S13,採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心。In step S13, the bar graph data is clustered by using a clustering algorithm to obtain two categories and the centers of the two categories.
在本實施例中,所述聚類演算法為K-means演算法。所述K-means演算法可為任意一種已知的K-means演算法。下面詳細介紹一種K-means演算法,而對其他的已知的K-means演算法不進行詳細介紹。所述K-means演算法包括:In this embodiment, the clustering algorithm is a K-means algorithm. The K-means algorithm may be any known K-means algorithm. One K-means algorithm is described in detail below, and other known K-means algorithms are not described in detail. The K-means algorithm includes:
a1: 從長條圖資料中選擇K個點作為初始類別的中心,K為大於一的整數;a1: Select K points from the bar graph data as the center of the initial category, where K is an integer greater than one;
a2:掃描長條圖中全部資料,計算每個點與類別的中心的距離,並根據最小距離將所述點歸入相應的類別;a2: scan all the data in the bar graph, calculate the distance between each point and the center of the category, and classify the points into the corresponding category according to the minimum distance;
a3:重新計算每個類別的中心;a3: recalculate the center of each category;
a4:反覆運算預設次數或者新的類別的中心與原類別的中心相等或距離小於預設閾值時,演算法結束。在本實施例中,所述K=2,所述預設次數為10次,所述預設閾值為0.1。a4: The algorithm ends when the preset number of iterations is repeated or the center of the new category is equal to the center of the original category or the distance is less than a preset threshold. In this embodiment, the K = 2, the preset number of times is 10, and the preset threshold value is 0.1.
在其他實施例中,所述聚類演算法為核密度估計演算法等。所述核密度估計演算法為任意一種已知的核密度估計演算法。由於核密度估計演算法為已知,在此不進行贅述。In other embodiments, the clustering algorithm is a kernel density estimation algorithm and the like. The kernel density estimation algorithm is any known kernel density estimation algorithm. Since the kernel density estimation algorithm is known, it will not be repeated here.
在本實施例中,當聚類演算法結束後,在長條圖中得到所述兩個類別及所述兩個類別的中心。在本實施例中,以圖2所示的長條圖為例,所述兩個類別在圖3中以深淺不同的兩種灰色表示,所述兩個類別的中心的橫坐標值分別為106.19及236.28,在圖3中分別用虛線表示。In this embodiment, after the clustering algorithm ends, the two categories and the centers of the two categories are obtained in a bar graph. In this embodiment, the bar graph shown in FIG. 2 is taken as an example. The two categories are represented by two different shades of gray in FIG. 3, and the abscissa values of the centers of the two categories are 106.19, respectively. And 236.28 are shown by dotted lines in FIG. 3, respectively.
步驟S14,確定長條圖中兩個類別的中心之間的對應縱坐標值為最小值的橫坐標值為分割閾值。Step S14: Determine the abscissa value corresponding to the minimum ordinate value between the centers of the two categories in the bar graph as the division threshold.
例如:長條圖中橫坐標值106.19與橫坐標值236.28之間具有最小縱坐標值的橫坐標值為206,則確定所述橫坐標值206為分割閾值,在圖4中用點劃線表示。For example: if the abscissa value with the smallest ordinate value between the abscissa value 106.19 and the abscissa value 236.28 in the bar graph is 206, then the abscissa value 206 is determined as the segmentation threshold, which is indicated by a dashed line in FIG. .
在本實施例中,前景通常為距離影像採集裝置較近的景物,背景通常為距離影像採集裝置較遠的景物,前景和背景距離影像採集裝置的距離往往不同,使得在深度圖像中前景和背景的深度分佈不連續,從而可將兩個類別的中心之間的深度分佈不連續的位置設為分割閾值,實現前景和背景的有效分割。In this embodiment, the foreground is usually a scene closer to the image acquisition device, and the background is usually a scene farther away from the image acquisition device. The distance between the foreground and background from the image acquisition device is often different, so that in the depth image, the foreground and The depth distribution of the background is discontinuous, so that the position of the depth distribution discontinuity between the centers of the two classes can be set as the segmentation threshold to achieve effective segmentation of the foreground and background.
步驟S15,確定所述分割閾值是否滿足預設條件。Step S15: Determine whether the segmentation threshold value satisfies a preset condition.
所述預設條件可為所述長條圖中以所述分割閾值為中心的預設範圍內的縱坐標值的平均值小於預設值。在本實施例中,所述預設範圍為橫坐標值為[T-N,T+N]的範圍,T為所述分割閾值,N為正整數,例如N可為2。所述預設值為50~200,例如所述預設值為100。顯然,所述N及所述預設值不僅局限於上述值,可根據需要而設置為其他值。The preset condition may be that an average value of the ordinate values in a preset range centered on the segmentation threshold value in the bar graph is smaller than a preset value. In this embodiment, the preset range is a range in which the abscissa value is [T-N, T + N], T is the segmentation threshold, and N is a positive integer, for example, N may be 2. The preset value is 50 ~ 200, for example, the preset value is 100. Obviously, the N and the preset value are not limited to the above-mentioned values, and may be set to other values as required.
所述預設條件還可為所述長條圖中所述分割閾值對應的縱坐標值小於預設值。所述預設值可為50~200,例如所述預設值為100。顯然,所述預設值不僅局限於上述值,可根據需要而設置為其他值。The preset condition may also be that an ordinate value corresponding to the segmentation threshold in the bar graph is smaller than a preset value. The preset value may be 50 ~ 200, for example, the preset value is 100. Obviously, the preset value is not limited to the above-mentioned value, and may be set to other values as needed.
步驟S16,當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域。In step S16, when the segmentation threshold value meets a preset condition, the image is segmented into a foreground and a background region according to the segmentation threshold value.
所述預設條件可為所述長條圖中以所述分割閾值為中心的預設範圍內的縱坐標值的平均值小於預設值,或者為所述長條圖中所述分割閾值對應的縱坐標值小於預設值。在本實施例中,所述分割閾值滿足預設條件表示前景和背景之間具有清晰的界線,此時可根據所述分割閾值將所述影像分割成前景和背景兩個區域。具體來說,可將所述影像中深度值小於所述分割閾值的圖元劃分為所述前景,並將所述影像中深度值大於所述分割閾值的圖元劃分為所述背景。所述影像中深度值等於所述分割閾值的圖元可以劃分為所述前景或所述背景。在本實施例中,根據所述分割閾值將所述影像分割成前景和背景兩個區域後,可對影像進行後期處理,例如背景虛擬處理,改變背景等,從而實現各種功能。The preset condition may be that an average value of an ordinate value in a preset range centered on the segmentation threshold value in the bar graph is smaller than a preset value, or a corresponding value of the segmentation threshold in the bar graph. The ordinate value of is smaller than the preset value. In this embodiment, the segmentation threshold meets a preset condition to indicate that there is a clear boundary between the foreground and the background. At this time, the image may be segmented into two regions, the foreground and the background, according to the segmentation threshold. Specifically, a primitive having a depth value less than the segmentation threshold in the image may be divided into the foreground, and a primitive having a depth value greater than the segmentation threshold in the image may be divided into the background. The primitives with a depth value equal to the segmentation threshold in the image may be divided into the foreground or the background. In this embodiment, after the image is divided into the foreground and background regions according to the segmentation threshold, the image can be post-processed, such as background virtual processing, changing the background, etc., thereby achieving various functions.
實施例一提供的方法藉由獲取影像和所述影像的深度圖像;獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標;採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心;確定長條圖中兩個類別的中心之間的對應縱坐標值最小的橫坐標值為分割閾值;確定所述分割閾值是否滿足預設條件;當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域,從而確定所述分割閾值為影像深度分佈不連續的位置,使得後續的前背景分割恰當,同時當前景和背景之間的邊界清晰時才進行前背景分割,進一步實現前背景的有效分割。The method provided in the first embodiment is to obtain an image and a depth image of the image; obtain a bar graph of the depth image, the bar graph including the horizontal coordinate and the vertical coordinate; The graph data is clustered to obtain the two categories and the centers of the two categories; determine that the abscissa corresponding to the smallest vertical coordinate value between the centers of the two categories in the bar graph is the segmentation threshold; determine whether the segmentation threshold meets A preset condition; when the segmentation threshold value meets the preset condition, the image is divided into two regions of foreground and background according to the segmentation threshold value, so as to determine the position where the segmentation threshold value is discontinuous in the image depth distribution, so that subsequent The front background is properly segmented, and the front background is segmented only when the boundary between the foreground and the background is clear, to further effectively segment the front background.
實施例二Example two
圖5是本發明實施例二提供的影像分割方法的流程圖。根據不同的需求,該流程圖中步驟的順序可以改變,某些步驟可以省略。所述方法應用於電子裝置中,所述電子裝置可以為任何一種電子產品,例如,個人電腦、平板電腦、智慧手機、個人數位助理(Personal Digital Assistant,PDA)等。如圖5所示,所述影像分割方法可以包括以下步驟:FIG. 5 is a flowchart of an image segmentation method provided by Embodiment 2 of the present invention. According to different requirements, the order of steps in this flowchart can be changed, and some steps can be omitted. The method is applied to an electronic device, and the electronic device may be any kind of electronic product, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), and the like. As shown in FIG. 5, the image segmentation method may include the following steps:
步驟S71,獲取影像和所述影像的深度圖像。Step S71: Obtain an image and a depth image of the image.
本實施例中步驟S71與所述實施例一中步驟S11一致,具體請參閱實施例一中步驟S11的相關描述,在此不進行贅述。Step S71 in this embodiment is consistent with step S11 in the first embodiment. For details, refer to the description of step S11 in the first embodiment, and details are not described herein.
步驟S72,獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標。Step S72: Obtain a bar graph of the depth image, where the bar graph includes an abscissa and an ordinate.
本實施例中步驟S72與所述實施例一中步驟S12一致,具體請參閱實施例一中步驟S12的相關描述,在此不進行贅述。Step S72 in this embodiment is consistent with step S12 in the first embodiment. For details, refer to the description of step S12 in the first embodiment, and details are not described herein.
步驟S73,採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心。In step S73, the bar graph data is clustered by using a clustering algorithm to obtain two categories and the centers of the two categories.
本實施例中步驟S73與所述實施例一中步驟S13一致,具體請參閱實施例一中步驟S13的相關描述,在此不進行贅述。Step S73 in this embodiment is consistent with step S13 in the first embodiment. For details, refer to the description of step S13 in the first embodiment, and details are not described herein.
步驟S74,確定長條圖中兩個類別的中心之間的對應縱坐標值為最小值的橫坐標值為分割閾值。Step S74: Determine the abscissa value corresponding to the minimum ordinate value between the centers of the two categories in the bar graph as the division threshold.
本實施例中步驟S74與所述實施例一中步驟S14一致,具體請參閱實施例一中步驟S14的相關描述,在此不進行贅述。Step S74 in this embodiment is consistent with step S14 in the first embodiment. For details, refer to the description of step S14 in the first embodiment, and details are not described herein.
步驟S75,確定所述分割閾值是否滿足預設條件。Step S75: Determine whether the segmentation threshold value satisfies a preset condition.
本實施例中步驟S75與所述實施例一中步驟S15一致,具體請參閱實施例一中步驟S15的相關描述,在此不進行贅述。Step S75 in this embodiment is consistent with step S15 in the first embodiment. For details, refer to the description of step S15 in the first embodiment, and details are not described herein.
步驟S76,當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域。In step S76, when the segmentation threshold value meets a preset condition, the image is segmented into two regions, the foreground and the background, according to the segmentation threshold value.
本實施例中步驟S76與所述實施例一中步驟S16一致,具體請參閱實施例一中步驟S16的相關描述,在此不進行贅述。Step S76 in this embodiment is consistent with step S16 in the first embodiment. For details, refer to the description of step S16 in the first embodiment, and details are not described herein.
步驟S77,當所述分割閾值不滿足預設條件時,確定所述影像不適合分割成前景和背景兩個區域。In step S77, when the segmentation threshold does not satisfy a preset condition, it is determined that the image is not suitable for segmentation into foreground and background regions.
所述分割閾值不滿足預設條件可為所述長條圖中以所述分割閾值為中心的所述預設範圍內的縱坐標值的平均值大於或等於預設值,或者為所述長條圖中所述分割閾值對應的縱坐標值大於或等於預設值。The segmentation threshold value not satisfying the preset condition may be that an average value of an ordinate value in the preset range centered on the segmentation threshold value in the bar graph is greater than or equal to a preset value, or is the length The ordinate value corresponding to the segmentation threshold in the bar graph is greater than or equal to a preset value.
在本實施例中,所述分割閾值不滿足預設條件表示前景和背景之間沒有清晰的界線,此時所述影像不適合分割成前景和背景兩個區域,所以放棄切分所述影像。In this embodiment, the segmentation threshold does not satisfy the preset condition, indicating that there is no clear boundary between the foreground and the background. At this time, the image is not suitable for being divided into the foreground and background regions, so the segmentation of the image is abandoned.
實施例二提供的方法藉由獲取影像和所述影像的深度圖像;獲取所述深度圖像的長條圖,所述長條圖包括橫坐標及縱坐標;採用聚類演算法對長條圖資料進行聚類,得到兩個類別及兩個類別的中心;確定長條圖中兩個類別的中心之間的對應縱坐標值最小的橫坐標值為分割閾值;確定所述分割閾值是否滿足預設條件;當所述分割閾值滿足預設條件時,根據所述分割閾值將所述影像分割成前景和背景兩個區域,當所述分割閾值不滿足預設條件時,確定所述影像不適合分割成前景和背景兩個區域,從而確定所述分割閾值為影像深度分佈不連續的位置,使得後續的前背景分割恰當,同時當前景和背景之間的邊界清晰時才進行前背景分割,進一步實現前背景的有效分割,並當前景和背景之間的邊界不清晰時不進行前背景分割,避免了前背景的分割不恰當。The method provided in the second embodiment is to obtain an image and a depth image of the image; obtain a bar graph of the depth image, where the bar graph includes an abscissa and an ordinate; and use a clustering algorithm for the bar The graph data is clustered to obtain the two categories and the centers of the two categories; determine that the abscissa corresponding to the smallest vertical coordinate value between the centers of the two categories in the bar graph is the segmentation threshold; determine whether the segmentation threshold meets A preset condition; when the segmentation threshold value meets the preset condition, the image is divided into two regions of foreground and background according to the segmentation threshold value; when the segmentation threshold value does not satisfy the preset condition, it is determined that the image is not suitable It is divided into two areas, foreground and background, so that the segmentation threshold is a position where the depth distribution of the image is discontinuous, so that the subsequent front background segmentation is appropriate, and the front background segmentation is performed only when the boundary between the current scene and the background is clear. The front background is effectively segmented, and the front background is not segmented when the boundary between the foreground and the background is not clear, which prevents the front background from being segmented inappropriately.
實施例三Example three
圖6為本發明實施例三提供的電子裝置的示意圖。FIG. 6 is a schematic diagram of an electronic device according to a third embodiment of the present invention.
所述電子裝置8包括:記憶體81、至少一個處理器82、及存儲在所述記憶體81中並可在所述至少一個處理器82上運行的電腦程式83。所述至少一個處理器82用於執行所述電腦程式83以實現上述影像分割方法實施例中的步驟。The electronic device 8 includes: a memory 81, at least one processor 82, and a computer program 83 stored in the memory 81 and executable on the at least one processor 82. The at least one processor 82 is configured to execute the computer program 83 to implement the steps in the foregoing image segmentation method embodiment.
示例性的,所述電腦程式83可以被分割成一個或多個模組/單元,所述一個或者多個模組/單元被存儲在所述記憶體81中,並由所述至少一個處理器82執行,以完成本發明。所述一個或多個模組/單元可以是能夠完成特定功能的一系列電腦程式指令段,該指令段用於描述所述電腦程式83在所述電子裝置8中的執行過程。Exemplarily, the computer program 83 may be divided into one or more modules / units, and the one or more modules / units are stored in the memory 81 and processed by the at least one processor 82 is executed to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 83 in the electronic device 8.
所述電子裝置8可以為任何一種電子產品,例如,個人電腦、平板電腦、智慧手機、個人數位助理(Personal Digital Assistant,PDA)等。本領域具有通常技藝者可以理解,所述示意圖6僅僅是電子裝置8的示例,並不構成對電子裝置8的限定,所述電子裝置8可以包括比圖示更多或更少的部件,或者組合某些部件,或者不同的部件,例如所述電子裝置8還可以包括輸入輸出設備、網路接入設備、顯示幕等。The electronic device 8 may be any type of electronic product, for example, a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), and the like. Those skilled in the art can understand that the schematic diagram 6 is only an example of the electronic device 8 and does not constitute a limitation on the electronic device 8. The electronic device 8 may include more or fewer components than shown in the figure, or Combining certain components or different components, for example, the electronic device 8 may further include an input-output device, a network access device, a display screen, and the like.
所述至少一個處理器82可以是中央處理單元(Central Processing Unit,CPU),還可以是其他通用處理器、數位訊號處理器(Digital Signal Processor,DSP)、專用積體電路(Application Specific Integrated Circuit,ASIC)、現成可程式設計閘陣列(Field-Programmable Gate Array,FPGA)或者其他可程式設計邏輯器件、分立門或者電晶體邏輯器件、分立硬體元件等。該處理器82可以是微處理器或者該處理器82也可以是任何常規的處理器等,所述處理器82是所述電子裝置8的控制中心,利用各種介面和線路連接整個電子裝置8的各個部分。The at least one processor 82 may be a central processing unit (CPU), or may be other general-purpose processors, digital signal processors (DSPs), and application specific integrated circuits. ASIC), ready-made programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 82 may be a microprocessor or the processor 82 may be any conventional processor, etc. The processor 82 is a control center of the electronic device 8, and uses various interfaces and lines to connect the entire electronic device 8. Various parts.
所述記憶體81可用於存儲所述電腦程式83和/或模組/單元,所述處理器82藉由運行或執行存儲在所述記憶體81內的電腦程式和/或模組/單元,以及調用存儲在記憶體81內的資料,實現所述電子裝置8的各種功能。所述記憶體81可主要包括存儲程式區和存儲資料區,其中,存儲程式區可存儲作業系統、至少一個功能所需的應用程式(比如聲音播放功能、圖像播放功能等)等;存儲資料區可存儲根據電子裝置8的使用所創建的資料(比如音訊資料、電話本等)等。此外,記憶體81可以包括高速隨機存取記憶體和非易失性記憶體,例如硬碟、記憶體、插接式硬碟、智慧存儲卡(Smart Media Card,SMC)、安全數位(Secure Digital,SD)卡、快閃記憶體卡(Flash Card)、至少一個磁碟記憶體件、快閃記憶體器件、或其他易失性固態記憶體件。The memory 81 may be used to store the computer program 83 and / or module / unit, and the processor 82 runs or executes the computer program and / or module / unit stored in the memory 81, And calling data stored in the memory 81 to implement various functions of the electronic device 8. The memory 81 may mainly include a storage program area and a storage data area, where the storage program area may store an operating system, at least one application required by a function (such as a sound playback function, an image playback function, etc.), and the like; storage data The area may store materials (such as audio materials, phone books, etc.) created according to the use of the electronic device 8. In addition, the memory 81 may include a high-speed random access memory and a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), and a Secure Digital (Secure Digital , SD) card, flash memory card (Flash Card), at least one disk memory device, flash memory device, or other volatile solid state memory device.
所述電子裝置8集成的模組/單元如果以軟體功能單元的形式實現並作為獨立的產品銷售或使用時,可以存儲在一個電腦可讀取存儲介質中。基於這樣的理解,本發明實現上述實施例方法中的全部或部分流程,也可以藉由電腦程式來控制相關的硬體來完成,所述的電腦程式可存儲於一電腦可讀存儲介質中,該電腦程式在被處理器執行時,可實現上述各個方法實施例的步驟。其中,所述電腦程式包括電腦程式代碼,所述電腦程式代碼可以為原始程式碼形式、物件代碼形式、可執行檔或某些中間形式等。所述電腦可讀介質可以包括:能夠攜帶所述電腦程式代碼的任何實體或裝置、記錄介質、U盤、移動硬碟、磁碟、光碟、電腦記憶體、唯讀記憶體(ROM,Read-Only Memory)、隨機存取記憶體(RAM,Random Access Memory)、電載波信號、電信信號以及軟體分發介質等。需要說明的是,所述電腦可讀介質包含的內容可以根據司法管轄區內立法和專利實踐的要求進行適當的增減,例如在某些司法管轄區,根據立法和專利實踐,電腦可讀介質不包括電載波信號和電信信號。When the integrated module / unit of the electronic device 8 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the method of the above embodiment, and can also be completed by controlling related hardware with a computer program, which can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the foregoing method embodiments can be implemented. The computer program includes computer program code, and the computer program code may be in a form of an original code, a form of an object code, an executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM, Read- Only Memory), Random Access Memory (RAM, Random Access Memory), electric carrier signals, telecommunication signals, and software distribution media. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdictions. For example, in some jurisdictions, the computer-readable medium Excludes electric carrier signals and telecommunication signals.
在本發明所提供的幾個實施例中,應該理解到,所揭露的電子裝置和方法,可以藉由其它的方式實現。例如,以上所描述的電子裝置實施例僅僅是示意性的。In the several embodiments provided by the present invention, it should be understood that the disclosed electronic device and method can be implemented in other ways. For example, the embodiments of the electronic device described above are merely schematic.
對於本領域具有通常技藝者而言,顯然本發明不限於上述示範性實施例的細節,而且在不背離本發明的精神或基本特徵的情況下,能夠以其他的具體形式實現本發明。因此,無論從哪一點來看,均應將實施例看作是示範性的,而且是非限制性的,本發明的範圍由所附申請專利範圍而不是上述說明限定,因此旨在將落在申請專利範圍的等同要件的含義和範圍內的所有變化涵括在本發明內。不應將申請專利範圍中的任何附圖標記視為限制所涉及的申請專利範圍。此外,顯然“包括”一詞不排除其他單元或,單數不排除複數。最後應說明的是,以上實施例僅用以說明本發明的技術方案而非限制,儘管參照較佳實施例對本發明進行了詳細說明,本領域具有通常技藝者應當理解,可以對本發明的技術方案進行修改或等同替換,而不脫離本發明技術方案的精神範圍。It is obvious to a person having ordinary skill in the art that the present invention is not limited to the details of the above-mentioned exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or basic features of the present invention. Therefore, regardless of the point of view, the embodiments should be regarded as exemplary and non-limiting. The scope of the present invention is defined by the scope of the attached patent application rather than the above description, so it is intended to fall into the application. The meaning of the equivalent scope of the patent scope and all changes within the scope are included in the present invention. Any reference sign in the scope of a patent application should not be considered as limiting the scope of the patent application involved. Furthermore, it is clear that the word "comprising" does not exclude other units or that the singular does not exclude the plural. Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention and are not limiting. Although the present invention is described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be Modifications or equivalent substitutions can be made without departing from the spirit and scope of the technical solution of the present invention.
8‧‧‧電子裝置8‧‧‧ electronic device
81‧‧‧記憶體 81‧‧‧Memory
82‧‧‧處理器 82‧‧‧ processor
83‧‧‧電腦程式 83‧‧‧Computer Program
圖1是本發明實施例一提供的影像分割方法的流程圖。 圖2是本發明一較佳實施例的深度圖像的長條圖。 圖3是本發明一較佳實施例的得到類別的中心的示意圖。 圖4是本發明一較佳實施例的確定分割閾值的示意圖。 圖5是本發明實施例二提供的影像分割方法的流程圖。 圖6是本發明實施例三提供的電子裝置的示意圖。FIG. 1 is a flowchart of an image segmentation method according to a first embodiment of the present invention. FIG. 2 is a bar graph of a depth image according to a preferred embodiment of the present invention. FIG. 3 is a schematic diagram of a category center obtained according to a preferred embodiment of the present invention. FIG. 4 is a schematic diagram of determining a segmentation threshold according to a preferred embodiment of the present invention. FIG. 5 is a flowchart of an image segmentation method provided by Embodiment 2 of the present invention. FIG. 6 is a schematic diagram of an electronic device according to a third embodiment of the present invention.
無no
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| TW107139740A TWI661393B (en) | 2018-11-08 | 2018-11-08 | Image segmentation method, computer program, storage medium, and electronic device |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| TW107139740A TWI661393B (en) | 2018-11-08 | 2018-11-08 | Image segmentation method, computer program, storage medium, and electronic device |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| TWI661393B true TWI661393B (en) | 2019-06-01 |
| TW202018660A TW202018660A (en) | 2020-05-16 |
Family
ID=67764037
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| TW107139740A TWI661393B (en) | 2018-11-08 | 2018-11-08 | Image segmentation method, computer program, storage medium, and electronic device |
Country Status (1)
| Country | Link |
|---|---|
| TW (1) | TWI661393B (en) |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| TW201314582A (en) * | 2011-09-29 | 2013-04-01 | Mediatek Singapore Pte Ltd | Method and apparatus of foreground object detection and background detection |
| CN103034997A (en) * | 2012-11-30 | 2013-04-10 | 杭州易尊数字科技有限公司 | Foreground detection method for separation of foreground and background of surveillance video |
| TW201322183A (en) * | 2011-11-17 | 2013-06-01 | Hon Hai Prec Ind Co Ltd | Image analysis device and analysis method thereof |
| TW201742005A (en) * | 2016-05-16 | 2017-12-01 | 安訊士有限公司 | Method and apparatus for updating a background model used for background subtraction of an image |
-
2018
- 2018-11-08 TW TW107139740A patent/TWI661393B/en active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| TW201314582A (en) * | 2011-09-29 | 2013-04-01 | Mediatek Singapore Pte Ltd | Method and apparatus of foreground object detection and background detection |
| TW201322183A (en) * | 2011-11-17 | 2013-06-01 | Hon Hai Prec Ind Co Ltd | Image analysis device and analysis method thereof |
| CN103034997A (en) * | 2012-11-30 | 2013-04-10 | 杭州易尊数字科技有限公司 | Foreground detection method for separation of foreground and background of surveillance video |
| CN103034997B (en) | 2012-11-30 | 2017-04-19 | 北京博创天盛科技有限公司 | Foreground detection method for separation of foreground and background of surveillance video |
| TW201742005A (en) * | 2016-05-16 | 2017-12-01 | 安訊士有限公司 | Method and apparatus for updating a background model used for background subtraction of an image |
Also Published As
| Publication number | Publication date |
|---|---|
| TW202018660A (en) | 2020-05-16 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110660066B (en) | Training method of network, image processing method, network, terminal equipment and medium | |
| CN108961303B (en) | Image processing method and device, electronic equipment and computer readable medium | |
| CN111161299B (en) | Image segmentation method, storage medium and electronic device | |
| CN111047615B (en) | Image-based straight line detection method and device and electronic equipment | |
| CN109064390B (en) | Image processing method, image processing device and mobile terminal | |
| WO2019134504A1 (en) | Method and device for blurring image background, storage medium, and electronic apparatus | |
| CN111311482B (en) | Background blurring method and device, terminal equipment and storage medium | |
| CN104574358B (en) | From the method and apparatus for focusing heap image progress scene cut | |
| CN110415237B (en) | Skin flaw detection method, skin flaw detection device, terminal device and readable storage medium | |
| CN110335216B (en) | Image processing method, image processing apparatus, terminal device, and readable storage medium | |
| CN110009555B (en) | Image blurring method, device, storage medium and electronic device | |
| CN109951635A (en) | Photographing processing method, device, mobile terminal, and storage medium | |
| CN111179276A (en) | Image processing method and device | |
| WO2014123583A1 (en) | Image processor with edge selection functionality | |
| CN114092905B (en) | Lane line detection method and device, electronic equipment and storage medium | |
| CN111290684A (en) | Image display method, image display device and terminal equipment | |
| CN115294328B (en) | Method, device, storage medium and electronic device for generating target detection frame | |
| CN110517201A (en) | Method, device and electronic equipment for loop edge-preserving smoothing filter | |
| CN108805838B (en) | Image processing method, mobile terminal and computer-readable storage medium | |
| CN108776800A (en) | Image processing method, mobile terminal and computer readable storage medium | |
| CN110475078A (en) | Camera shutter time method of adjustment and terminal device | |
| CN108810407B (en) | Image processing method, mobile terminal and computer-readable storage medium | |
| CN109753957B (en) | Image saliency detection method, device, storage medium and electronic device | |
| CN111311610A (en) | Image segmentation method and terminal device | |
| TWI661393B (en) | Image segmentation method, computer program, storage medium, and electronic device |