Image segmentation method and device
By adding black closed boxes to the periphery of the image and segmenting the images in these boxes with a computer, the problems of low efficiency and inaccurate image segmentation in the prior art are solved, and more efficient and accurate image segmentation is achieved.
Patent Information
- Application Number
- CN202510097639.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-05-16
AI Technical Summary
The existing image segmentation methods are inefficient and inaccurate.
A black enclosed box is added to each of the N first sub-images on the first bitmap. The computer sequentially retrieves all black pixels of each black enclosed box, and uses each black enclosed box as the segmentation track to divide the N second sub-images.
The efficiency and accuracy of image segmentation are improved, and the inefficiency and inaccuracy of manual segmentation are avoided.
Smart Images

Figure CN120013965A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of image processing technology, and in particular, to an image segmentation method and device. Background Art
[0002] refer to Figure 1 In the field of laser direct imaging, it is usually necessary to separately and completely segment and save N (6 for example) first sub-images 01-06 on a first bitmap 0A, and print the segmented 6 first sub-images on other carriers (such as clothes, paper or product packaging). Figure 1 In FIG. 1 , the dotted rectangle represents the boundary of the first sub-image 0A. In fact, there is no black pixel in the boundary. At present, the commonly used processing method is to manually segment the six first sub-images respectively, but manual segmentation is not only inefficient, but also has the phenomenon of inaccurate segmentation. Summary of the invention
[0003] The embodiments of the present application provide an image segmentation method and device, which aim to solve the problems of low segmentation efficiency and inaccurate segmentation in existing image segmentation methods.
[0004] The scheme of the present invention is as follows:
[0005] An image segmentation method, comprising:
[0006] Step 1: Add a black closed frame to the periphery of each of the N first sub-images on the first bitmap, so that the first bitmap becomes a second bitmap, the second bitmap includes N second sub-images, and each of the second sub-images includes all image areas within the corresponding black closed frame;
[0007] Step 2: The computer retrieves all the black pixels of each black closed frame in turn, takes each black closed frame as a segmentation trajectory, segments all the images within the N black closed frames, and obtains N second sub-images.
[0008] In some embodiments, each black closed frame is a black closed rectangular frame.
[0009] In some embodiments, in step 2, the computer sequentially segments all images within the N black closed frames to obtain N second sub-images, including:
[0010] Step 21: The computer segments the first first sub-image to obtain the first second sub-image;
[0011] Step 22: The computer sequentially divides the remaining N-1 first sub-images to obtain N-1 second sub-images.
[0012] In some embodiments, step 21 includes:
[0013] Step 211: The computer starts from the initial point o(0,0) at the top left of the second bitmap, and retrieves the first black pixel B11 for the first time in a sequence from left to right and from top to bottom. The black closed rectangular frame containing the first black pixel B11 is defined as the first black closed rectangular frame, and all images enclosed by the first black closed rectangular frame and including the first sub-image are defined as the first second sub-image;
[0014] Step 212: The computer uses the first black pixel B11 as the search starting point, and searches vertically downward and horizontally rightward respectively, until the white pixel W11 is first searched in the vertical direction, and the white pixel W12 located at the upper right corner of the first black closed rectangular frame is first searched in the horizontal direction. The vertical distance from the first black pixel B11 to the white pixel W11 is defined as h11, and the horizontal distance from the first black pixel B11 to the white pixel W12 is defined as s11;
[0015] Step 213: Search horizontally to the right along white pixel W11 until white pixel W13 is found again, search vertically downward along white pixel W12 until white pixel W13 is found, mark the vertical distance from white pixel W12 to white pixel W13 as h12, and the horizontal distance from white pixel W11 to white pixel W13 as s12;
[0016] Step 214: if s11=s12, and h11=h12, it means that the first black closed rectangular frame selects the entire first sub-image;
[0017] If s11≠s12, or h11≠h12, it means that the first black closed rectangular frame does not completely frame the first sub-image, and the position of the first black closed rectangular frame is adjusted until: s11=s12, and h11=h12;
[0018] Step 215: intercepting all images within the first black closed rectangular frame to obtain a first second sub-image;
[0019] In some embodiments, step 22 includes:
[0020] Step 221: The computer segments the second first sub-image to obtain a second second sub-image;
[0021] Step 222: The computer sequentially divides the remaining N-2 first sub-images to obtain N-2 second sub-images;
[0022] When the computer searches for any black closed rectangular frame of the remaining N-2 second sub-images, the starting position of the search is the white pixel position corresponding to the upper right corner of the previous black closed rectangular frame adjacent to the any black closed rectangular frame.
[0023] The embodiment of the present application also discloses an image segmentation device, including:
[0024] A black closed frame adding module is used to: add a black closed frame around each of the N first sub-images on the first bitmap, so that the first bitmap becomes a second bitmap, the second bitmap includes N second sub-images, and each of the second sub-images includes all image areas within the corresponding black closed frame;
[0025] The image segmentation module is used to: take each black closed frame as a segmentation track, and sequentially segment all images within N black closed frames to obtain N second sub-images.
[0026] In some embodiments, each black closed frame is a black closed rectangular frame.
[0027] In some embodiments, in the image segmentation module, the computer segments all images in N black closed frames in sequence to obtain N second sub-images, including:
[0028] Step 21: The computer segments the first first sub-image to obtain the first second sub-image;
[0029] Step 22: The computer sequentially divides the remaining N-1 first sub-images to obtain N-1 second sub-images.
[0030] In some embodiments, the computer segments the first first sub-image to obtain the first second sub-image, including:
[0031] Step 211: The computer starts from the initial point o(0,0) at the top left of the second bitmap, and retrieves the first black pixel B11 for the first time in a sequence from left to right and from top to bottom. The black closed rectangular frame containing the first black pixel B11 is defined as the first black closed rectangular frame, and all images enclosed by the first black closed rectangular frame and including the first sub-image are defined as the first second sub-image;
[0032] Step 212: The computer uses the first black pixel B11 as the search starting point, and searches vertically downward and horizontally rightward respectively, until the white pixel W11 is first searched in the vertical direction, and the white pixel W12 located at the upper right corner of the first black closed rectangular frame is first searched in the horizontal direction. The vertical distance from the first black pixel B11 to the white pixel W11 is defined as h11, and the horizontal distance from the first black pixel B11 to the white pixel W12 is defined as s11;
[0033] Step 213: Search horizontally to the right along white pixel W11 until white pixel W13 is found again, search vertically downward along white pixel W12 until white pixel W13 is found, mark the vertical distance from white pixel W12 to white pixel W13 as h12, and the horizontal distance from white pixel W11 to white pixel W13 as s12;
[0034] Step 214: if s11=s12, and h11=h12, it means that the first black closed rectangular frame selects the entire first sub-image;
[0035] If s11≠s12, or h11≠h12, it means that the first black closed rectangular frame does not completely frame the first sub-image, and the position of the first black closed rectangular frame is adjusted until: s11=s12, and h11=h12;
[0036] Step 215: intercept all images within the first black closed rectangular frame to obtain a first second sub-image.
[0037] The embodiment of the present application further discloses a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the aforementioned image segmentation method are implemented.
[0038] The embodiment of the present application also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the aforementioned image segmentation method are implemented.
[0039] The technical effect of the embodiment of the present application is as follows: N second sub-images are obtained by adding N black closed frames to the periphery of N first sub-images located on the first bitmap; the computer sequentially divides the N second sub-images: the first black pixel of each black closed frame is retrieved in order from left to right and from top to bottom, and then the entire black closed frame is retrieved along the trajectory of the black closed frame, and the second sub-image enclosed by it is divided out using the black closed frame as the segmentation trajectory, wherein each second sub-image includes the corresponding first sub-image and other areas enclosed by the corresponding black closed frame except the first sub-image. When dividing the second and remaining second sub-images, the starting position where the computer starts to search is the position where the white pixel in the upper right corner of the black closed frame corresponding to the previous second sub-image is located. Therefore, when the computer completes the segmentation of each second sub-image, it is not necessary to start searching from the starting point 0 (0, 0) at the upper left corner of the first bitmap, thereby improving the efficiency and accuracy of image segmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 is a schematic diagram of six first sub-images that need to be segmented on the first bitmap 00;
[0041] Figure 2 For Figure 1 Schematic diagram of adding black closed rectangular frames to the first sub-images of the six images;
[0042] Figure 3 A diagram showing the steps of an image segmentation method according to an embodiment of the present application;
[0043] Figure 4 A detailed trajectory diagram for computer segmentation of the first second sub-image 01B;
[0044] Figure 5 It is a schematic diagram that the first black closed rectangular frame 01A fails to completely enclose the first first sub-image 01;
[0045] Figure 6 is a schematic diagram of the first second sub-image 01B in the second bitmap 00A after being segmented;
[0046] Figure 7 A detailed trajectory diagram for computer segmentation of the second second sub-image 02B;
[0047] Figure 8 is a schematic diagram of the first second sub-image 01B and the second second sub-image 02B in the second bitmap 00A after being segmented;
[0048] Fig. 9 This is a module diagram of the image segmentation device of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific position, be constructed and operated in a specific position, and therefore cannot be understood as limiting the present invention; the terms "first", "second", and "third" are only used to describe the difference, and cannot be understood as indicating or implying relative importance. In addition, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate object, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0051] refer to Figure 2 and Figure 3 , an image segmentation method disclosed in an embodiment of the present invention includes:
[0052] Step 1: Add a black closed frame to the periphery of each of the N first sub-images on the first bitmap, so that the first bitmap becomes a second bitmap, the second bitmap includes N second sub-images, and each of the second sub-images includes all image areas within the corresponding black closed frame;
[0053] Step 2: The computer retrieves all the black pixels of each black closed frame in turn, takes each black closed frame as a segmentation trajectory, segments all the images within the N black closed frames, and obtains N second sub-images.
[0054] refer to Figure 1 and Figure 2In the present application, N is exemplarily taken as 6, and the number of first sub-images in the first bitmap 00 is 6. In order to separately and completely segment and save the 6 first sub-images 01-06, a black closed frame is added to the outside of each of the 6 first sub-images 01-06, and the first bitmap 00 becomes the second bitmap 00A. The shapes of the 6 black closed frames can be the same or different, and the shapes are not restricted, but what needs to be satisfied is that the 6 black closed frames can enclose each first sub-image, that is, each black closed frame and the first sub-image enclosed inside theoretically do not have overlapping pixels. There should be no intersection between each two adjacent black closed frames, that is, there is no intersection between the two. The purpose of adding a black closed frame is to provide a segmentation trajectory for segmenting each first sub-image.
[0055] In the embodiment of the present application, the black closed frame is exemplarily selected as a rectangular black square frame, but it should be noted that the black closed frame can also be a circular frame, a triangular frame, a parallelogram frame, or any irregular black closed frame. In the embodiment of the present application, when the black closed frame is exemplarily selected as a black closed rectangular frame, the size of each black closed rectangular frame is not required to be the same, as long as it can ensure that the corresponding first sub-image is enclosed. Figure 1 In the figure, the six first sub-images 01-06 are named in sequence: the first first sub-image 01, the second first sub-image 02, the third first sub-image 03, the fourth first sub-image 04, the fifth first sub-image 05 and the sixth first sub-image 06. Figure 2In the figure, the black closed rectangular frames added to the periphery of each first sub-image 01 are named as the first black closed rectangular frame 01A, the second black closed rectangular frame 02A, the third black closed rectangular frame 03A, the fourth black closed rectangular frame 04A, the fifth black closed rectangular frame 05A, and the sixth black closed rectangular frame 06A. Each black closed rectangular frame together with all images enclosed by it (including the corresponding first sub-image) is defined as the second sub-image. For example, all images enclosed by the first black closed rectangular frame 01A including the first first sub-image 01 are defined as the first second sub-image 01B, and all images enclosed by the second black closed rectangular frame 02A including the second first sub-image 02 are defined as the second second sub-image 02B. All images including the third first sub-image 03 enclosed by the third black closed rectangular frame 03A are defined as the second second sub-image 03B, all images including the fourth first sub-image 04 enclosed by the fourth black closed rectangular frame 04A are defined as the fourth second sub-image 04B, all images including the fifth first sub-image 05 enclosed by the fifth black closed rectangular frame 05A are defined as the fifth second sub-image 05B, and all images including the sixth first sub-image 06 enclosed by the sixth black closed rectangular frame 06A are defined as the sixth second sub-image 06B. These six second sub-images are exactly the objects that need to be divided and saved separately. It should be noted that the six second sub-images 01B-06B are not placed in order from left to right and from top to bottom, but are numbered in sequence according to the corresponding black closed rectangular frames retrieved by the computer. For example: Figure 2 In the figure, the leftmost image in the first row is not the first second sub-image retrieved by the computer, but the third second sub-image 03B. The first second sub-image 01B retrieved by the computer is the third one from the left in the first row.
[0056] The following specifically describes how to set up the program to let the computer segment the six second sub-images one by one.
[0057] Specifically, the segmentation procedure set by the computer is as follows:
[0058] Step 21: The computer segments the first first sub-image to obtain the first second sub-image;
[0059] Step 22: The computer sequentially divides the remaining N-1 first sub-images to obtain N-1 second sub-images.
[0060] Specifically for this embodiment, refer to Figure 2 and Figure 4 , the steps of computer segmenting the first sub-image 01B are:
[0061] Step 211: Reference Figure 2, the computer starts from the initial point o(0,0) at the top left of the second bitmap 00A, and retrieves the first black pixel B11 for the first time in the order from left to right and from top to bottom, and defines the black closed rectangular frame 01A containing the first black pixel B11 as the first black closed rectangular frame 01A, and defines all images enclosed by the first black closed rectangular frame 01A as the first second sub-image 01B. Obviously, the area included in the first second sub-image 01B includes not only the first first image 01, but also the blank area enclosed by the first black closed rectangular frame 01A.
[0062] Step 212: The computer uses the first black pixel B11 as the search starting point, and searches vertically downward and horizontally rightward respectively, until the white pixel W11 is first searched in the vertical direction, and the white pixel W12 located at the upper right corner of the first black closed rectangular frame 01A is first searched in the horizontal direction, the vertical distance from the first black pixel B11 to the white pixel W11 is defined as h11, and the horizontal distance from the first black pixel B11 to the white pixel W12 is defined as s11;
[0063] Step 213: Search horizontally to the right along white pixel W11 until white pixel W13 is found again, search vertically downward along white pixel W12 until white pixel W13 is found, mark the vertical distance from white pixel W12 to white pixel W13 as h12, and the horizontal distance from white pixel W11 to white pixel W13 as s12;
[0064] Step 214: if s11=s12, and h11=h12, it means that the first black closed rectangular frame 01A selects the entire first sub-image 01;
[0065] If s11≠s12, or h11≠h12, it means that the first black closed rectangular frame 01A does not completely frame the first sub-image 01, and the position of the first black closed rectangular frame 01A is adjusted until: s11=s12, and h11=h12. For example, refer to Figure 5 If the first black closed rectangular frame 01A does not completely frame the first first sub-image 01, for example, the right vertical line of the first black closed rectangular frame 01A intersects with the first first sub-image 01, then h11≠h12. Therefore, it is necessary to readjust the position of the first black closed rectangular frame 01A until s11=s12 and h11=h12 are detected again, indicating that the first black closed rectangular frame 01A completely frames the first first sub-image 01.
[0066] Step 215: Segment all images within the first black closed rectangular frame 01A to obtain the first second sub-image 01B and save it separately.
[0067] refer to Figure 6 When the first second sub-image 01B is segmented, the entire area of the first second sub-image 01B is left blank. When the computer segments the next second sub-image 02B, there is no need to return to Figure 2 Instead of using the initial point o(0,0) at the top left of the image, the new starting point is the location W12(x2,y2) of the white pixel W12 at the top right corner of the first black closed rectangular frame 01A, and the first black pixel is retrieved again from left to right and from top to bottom. Since the first second sub-image 01B has been segmented, the remaining areas are all blank areas, and the second black closed rectangular frame 02A enclosing the second first sub-image 02 is located above the third black closed rectangular frame 03A, so with W12(x2,y2) as the starting point, the first black pixel retrieved again is the black pixel B21 at the top left corner of the second black closed rectangular frame 02A. Then repeat the ideas of step 211 to step 215 to segment the second second sub-image 02B, as follows:
[0068] refer to Figure 6 and Figure 7 , the computer takes the position W12 (x2, y2) as the starting point, and retrieves the first black pixel B21 for the first time in the order from left to right and from top to bottom, and defines the black closed rectangular frame 02A containing the first black pixel B21 as the second black closed rectangular frame 02A, and defines all images enclosed by the second black closed rectangular frame 02A as the second second sub-image 02B. Obviously, the area included in the second second sub-image 02B includes not only the second second image 02, but also the blank area enclosed by the second black closed rectangular frame 02A;
[0069] The computer uses B21 as the search starting point and searches vertically downward and horizontally rightward respectively until the white pixel W21 is first searched in the vertical direction and the white pixel W22 located at the upper right corner of the second black closed rectangular frame 02A is first searched in the horizontal direction. The vertical distance from the first black pixel B21 to the white pixel W21 is defined as h21, and the horizontal distance from the first black pixel B21 to the white pixel W22 is defined as s21.
[0070] Search horizontally to the right along white pixel W21 until white pixel W23 is found again, search vertically downward along white pixel W22 until white pixel W23 is found, mark the vertical distance from white pixel W22 to white pixel W23 as h22, and the horizontal distance from white pixel W21 to white pixel W23 as s22;
[0071] If s21=s22, and h21=h22, it means that the second black closed rectangular frame 02A selects the entire second second sub-image 02B;
[0072] If s21≠s22, or h21≠h22, it means that the second black closed rectangular frame 02A does not completely select the second first sub-image 02, and the position of the second black closed rectangular frame 02A is adjusted until: s21=s22, and h21=h22, which means that the second black closed rectangular frame completely encloses the second first sub-image 02.
[0073] Finally, all images within the second black closed rectangular frame 02A are segmented to obtain a second second sub-image 02B and save it separately.
[0074] It should be noted that, since the first black closed rectangular frame 01A and the second black closed rectangular frame 02A are not necessarily the same in shape and size, s11 is not necessarily equal to s21, and h11 is not necessarily equal to h21.
[0075] After the second second sub-image 02B is segmented, the remaining four second sub-images 03B-06B are as follows: Figure 8 shown.
[0076] In the process of segmenting the second second sub-image 02B, it is necessary to record the position coordinates (x2, y2) of the white pixel W22 at the upper right corner of the second black closed rectangular frame 02A, which will be used as the retrieval starting point when segmenting the third second sub-image 03B.
[0077] From the above analysis, we can see that except for retrieving the first black enclosed rectangular box, Figure 2 In addition to starting from the initial point o(0,0) at the upper left corner of the second bitmap 00A, when searching for the remaining N-1 black closed rectangular boxes, the white pixel position corresponding to the upper right corner of the previous black closed rectangular box is used as the starting position, thereby improving the search efficiency.
[0078] Through the image segmentation method described in the present application, the N first sub-images in the first bitmap can be quickly and accurately segmented separately, named and stored separately for printing needs, thus overcoming the time-consuming and inaccurate defects of manual segmentation.
[0079] Although the embodiments of the present application only list the case where all black closed frames are black closed rectangular frames, it is applicable to the case where the black closed frames are circular, triangular, elliptical or other irregular closed frames. In essence, all black pixels on the black closed frame are retrieved to obtain the trajectory coordinates of the black closed frame, which are then used as the segmentation trajectory. The closed frame in the present application must meet the fully closed condition, otherwise the purpose of retrieving all black pixels of the continuously distributed, linear black closed frame cannot be achieved.
[0080] Figure 2 , Figure 6 and Figure 8 In FIG. 1 , the dotted rectangular box represents the boundary of the second bitmap 00A. In fact, there is no black pixel on the boundary.
[0081] refer to Fig. 9 , the embodiment of the present application also discloses an image segmentation device, including:
[0082] A black closed frame adding module is used to: add a black closed frame around each of the N first sub-images on the first bitmap, so that the first bitmap becomes a second bitmap, the second bitmap includes N second sub-images, and each of the second sub-images includes all image areas within the corresponding black closed frame;
[0083] The image segmentation module is used to: take each black closed frame as a segmentation track, and sequentially segment all images within N black closed frames to obtain N second sub-images.
[0084] In some embodiments, each black closed frame is a black closed rectangular frame.
[0085] In some embodiments, in the image segmentation module, the computer segments all images in N black closed frames in sequence to obtain N second sub-images, including:
[0086] Step 21: The computer segments the first first sub-image to obtain the first second sub-image;
[0087] Step 22: The computer sequentially divides the remaining N-1 first sub-images to obtain N-1 second sub-images.
[0088] In some embodiments, the computer segments the first first sub-image to obtain the first second sub-image, including:
[0089] Step 211: The computer starts from the initial point o(0,0) at the top left of the second bitmap and retrieves the first black pixel B11 for the first time in a sequence from left to right and from top to bottom. All images enclosed by the black closed rectangular frame containing the first black pixel B11 are defined as the first second sub-image;
[0090] Step 212: The computer uses the first black pixel B11 as the search starting point, and searches vertically downward and horizontally rightward respectively, until the white pixel W11 is first searched in the vertical direction, and the white pixel W12 located at the upper right corner of the first black closed rectangular frame is first searched in the horizontal direction. The vertical distance from the first black pixel B11 to the white pixel W11 is defined as h11, and the horizontal distance from the first black pixel B11 to the white pixel W12 is defined as s11;
[0091] Step 213: Search horizontally to the right along white pixel W11 until white pixel W13 is found again, search vertically downward along white pixel W12 until white pixel W13 is found, mark the vertical distance from white pixel W12 to white pixel W13 as h12, and the horizontal distance from white pixel W11 to white pixel W13 as s12;
[0092] Step 214: if s11=s12, and h11=h12, it means that the first black closed rectangular frame selects the entire first sub-image;
[0093] If s11≠s12, or h11≠h12, it means that the first black closed rectangular frame does not completely frame the first sub-image, and the position of the first black closed rectangular frame is adjusted until: s11=s12, and h11=h12;
[0094] Step 215: intercept all images within the first black closed rectangular frame to obtain a first second sub-image.
[0095] The functional modules of the above-mentioned image segmentation device have been described in detail when introducing the segmentation method, and will not be repeated here.
[0096] The present application also discloses a storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the aforementioned image segmentation method can be implemented. The storage medium refers to a carrier for storing data. For example, a floppy disk, an optical disk, a DVD, a hard disk, a flash memory, a USB flash disk, a CF card, an SD card, an MMC card, a SM card, a memory stick (Memory Stick), an xD card, etc. Popular storage media are media based on flash memory (Nand flash), such as a USB flash disk, a CF card, an SD card, an SDHC card, an MMC card, a SM card, a memory stick, an XD card, etc.
[0097] The embodiment of the present application also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the aforementioned image segmentation method when executing the program. The processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory, and one or more kernels may be provided. The memory may include a non-permanent memory in a computer-readable medium, a random access memory (RAM) and / or a non-volatile memory, such as a read-only memory (ROM) or a flash memory (flash RAM), and the memory includes at least one memory chip.
[0098] The image segmentation method, device, storage medium and computer equipment disclosed in the embodiments of the present application can achieve the following technical effects: by adding N black closed frames to the periphery of N first sub-images located on the first bitmap, N second sub-images are obtained; the computer sequentially segments the N second sub-images: by sequentially retrieving the first black pixel of each black closed frame from left to right and from top to bottom, and then retrieving the entire black closed frame along the trajectory of the black closed frame, and using the black closed frame as the segmentation trajectory, the second sub-image enclosed by it is segmented, wherein each second sub-image includes the corresponding first sub-image and other areas enclosed by the corresponding black closed frame except the first sub-image. When segmenting the second and remaining second sub-images, the starting position where the computer starts to search is the position where the white pixel in the upper right corner of the black closed frame corresponding to the segmented second sub-image is located. Therefore, when the computer completes the segmentation of each second sub-image, it is not necessary to start the search from the starting point 0 (0, 0) at the upper left corner of the first bitmap, thereby improving the efficiency and accuracy of image segmentation.
[0099] Finally, it should be noted that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments, or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. An image segmentation method, characterized in that: include: Step 1: Add a black closed frame to the periphery of each of the N first sub-images on the first bitmap, so that the first bitmap becomes a second bitmap, the second bitmap includes N second sub-images, and each of the second sub-images includes all image areas within the corresponding black closed frame; Step 2: The computer retrieves all black pixels of each black closed frame in turn, and uses each black closed frame as a segmentation trajectory to segment all images within N black closed frames to obtain N second sub-images.
2. The image segmentation method according to claim 1, characterized in that: Each of the black closed frames is a black closed rectangular frame.
3. The image segmentation method according to claim 2, characterized in that: Step 2 includes: Step 21: The computer segments the first first sub-image to obtain the first second sub-image; Step 22: The computer sequentially divides the remaining N-1 first sub-images to obtain N-1 second sub-images.
4. The image segmentation method according to claim 3, characterized in that: Step 21 includes: Step 211: The computer starts from the initial point o(0,0) at the top left of the second bitmap, and retrieves the first black pixel B11 for the first time in a sequence from left to right and from top to bottom. The black closed rectangular frame containing the first black pixel B11 is defined as the first black closed rectangular frame, and all images enclosed by the first black closed rectangular frame and including the first sub-image are defined as the first second sub-image; Step 212: The computer uses the first black pixel B11 as a search starting point, and searches vertically downward and horizontally rightward respectively, until the white pixel W11 is first searched in the vertical direction, and the white pixel W12 located at the upper right corner of the first black closed rectangular frame is first searched in the horizontal direction, the vertical distance from the first black pixel B11 to the white pixel W11 is defined as h11, and the horizontal distance from the first black pixel B11 to the white pixel W12 is defined as s11; Step 213: Search horizontally to the right along the white pixel W11 until the white pixel W13 is found again, search vertically downward along the white pixel W12 until the white pixel W13 is found, mark the vertical distance from the white pixel W12 to the white pixel W13 as h12, and the horizontal distance from the white pixel W11 to the white pixel W13 as s12; Step 214: if s11=s12, and h11=h12, it means that the first black closed rectangular frame selects the entire first first sub-image; If s11≠s12, or h11≠h12, it means that the first black closed rectangular frame does not completely frame the first first sub-image, and the position of the first black closed rectangular frame is adjusted until: s11=s12, and h11=h12; Step 215: intercepting all images within the first black closed rectangular frame to obtain the first second sub-image.
5. The image segmentation method according to claim 4, characterized in that: Step 22 includes: Step 221: The computer segments the second first sub-image to obtain a second second sub-image; Step 222: The computer sequentially divides the remaining N-2 first sub-images to obtain N-2 second sub-images; When the computer searches for any black closed rectangular frame of the remaining N-2 second sub-images, the starting position of the search is the white pixel position corresponding to the upper right corner of the previous black closed rectangular frame adjacent to the any black closed rectangular frame.
6. An image segmentation device, characterized in that: include: A black closed frame adding module is used to: after adding a black closed frame to the periphery of each of the N first sub-images on the first bitmap, the first bitmap becomes a second bitmap, the second bitmap includes the N second sub-images, and each of the second sub-images includes all image areas within the corresponding black closed frame; The image segmentation module is used to: the computer sequentially retrieves all black pixels of each black closed frame, takes each black closed frame as a segmentation trajectory, segments all images within N black closed frames, and obtains N second sub-images.
7. The image segmentation device according to claim 6, characterized in that: Each of the black closed frames is a black closed rectangular frame.
8. The image segmentation device according to claim 7, characterized in that: In the image segmentation module, the computer segments all the images in the N black closed frames in sequence to obtain N second sub-images, including: Step 21: The computer segments the first first sub-image to obtain the first second sub-image; Step 22: The computer sequentially divides the remaining N-1 first sub-images to obtain N-1 second sub-images.
9. The image segmentation device according to claim 8, characterized in that: Step 21 includes: Step 211: The computer starts from the initial point o(0,0) at the top left of the second bitmap, and retrieves the first black pixel B11 for the first time in a sequence from left to right and from top to bottom. The black closed rectangular frame containing the first black pixel B11 is defined as the first black closed rectangular frame, and all images enclosed by the first black closed rectangular frame and including the first sub-image are defined as the first second sub-image; Step 212: The computer uses the first black pixel B11 as a search starting point, and searches vertically downward and horizontally rightward respectively, until the white pixel W11 is first searched in the vertical direction, and the white pixel W12 located at the upper right corner of the first black closed rectangular frame is first searched in the horizontal direction, the vertical distance from the first black pixel B11 to the white pixel W11 is defined as h11, and the horizontal distance from the first black pixel B11 to the white pixel W12 is defined as s11; Step 213: Search horizontally to the right along the white pixel W11 until the white pixel W13 is found again, search vertically downward along the white pixel W12 until the white pixel W13 is found, mark the vertical distance from the white pixel W12 to the white pixel W13 as h12, and the horizontal distance from the white pixel W11 to the white pixel W13 as s12; Step 214: if s11=s12, and h11=h12, it means that the first black closed rectangular frame selects the entire first first sub-image; If s11≠s12, or h11≠h12, it means that the first black closed rectangular frame does not completely frame the first first sub-image, and the position of the first black closed rectangular frame is adjusted until: s11=s12, and h11=h12; Step 215: intercept all images within the first black closed rectangular frame to obtain a first second sub-image.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the image segmentation method according to any one of claims 1 to 5 are implemented.
11. A computer 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 program, the steps of the image segmentation method according to any one of claims 1 to 5 are implemented.