CN111429413A - Image segmentation method and device and computer readable storage medium - Google Patents

Image segmentation method and device and computer readable storage medium Download PDF

Info

Publication number
CN111429413A
CN111429413A CN202010190013.5A CN202010190013A CN111429413A CN 111429413 A CN111429413 A CN 111429413A CN 202010190013 A CN202010190013 A CN 202010190013A CN 111429413 A CN111429413 A CN 111429413A
Authority
CN
China
Prior art keywords
image
gray level
processed
calculating
segmentation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010190013.5A
Other languages
Chinese (zh)
Inventor
刘志升
杨涛
才鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202010190013.5A priority Critical patent/CN111429413A/en
Publication of CN111429413A publication Critical patent/CN111429413A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • G06T7/0012Biomedical image inspection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/11Region-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/136Segmentation; Edge detection involving thresholding
    • GPHYSICS
    • G16INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR SPECIFIC APPLICATION FIELDS
    • G16HHEALTHCARE INFORMATICS, i.e. INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR THE HANDLING OR PROCESSING OF MEDICAL OR HEALTHCARE DATA
    • G16H70/00ICT specially adapted for the handling or processing of medical references
    • G16H70/60ICT specially adapted for the handling or processing of medical references relating to pathologies

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Medical Informatics (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Quality & Reliability (AREA)
  • Radiology & Medical Imaging (AREA)
  • Nuclear Medicine, Radiotherapy & Molecular Imaging (AREA)
  • Epidemiology (AREA)
  • Primary Health Care (AREA)
  • Public Health (AREA)
  • Image Analysis (AREA)

Abstract

The present disclosure relates to the field of image analysis technologies, and in particular, to an image segmentation method and apparatus, and a computer-readable storage medium. The method comprises the steps of dividing an image to be processed into a plurality of areas; writing a partial area in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial area; calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region; and calculating a gray level segmentation threshold value which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas. The method comprises the steps of dividing an image to be processed with high resolution or ultrahigh resolution into a plurality of areas, and calculating gray level division values of a target image and a background image according to pixel gray levels in the areas, so that the purpose of searching the gray level division values for dividing a foreground image and the background image in the image to be processed is achieved in a low memory space.

Description

Image segmentation method and device and computer readable storage medium
Technical Field
The present disclosure relates to the field of image analysis technologies, and in particular, to an image segmentation method and apparatus, and a computer-readable storage medium.
Background
Pathological images are formed by imaging pathological sections through a high-resolution digital pathological section scanner, and because most of the pathological images are background or fat areas and the areas containing cell tissues only account for a small part of the images, when the pathological images are processed, the parts containing the cell tissues are often separated by using an image segmentation algorithm.
The image segmentation technology is a process of dividing a digital image into mutually disjoint regions, and the main purpose of the image segmentation technology is to extract a part of interest from one image, which is a key step of image analysis. The image segmentation methods in the prior art mainly include the following types: region-based segmentation methods, threshold-based segmentation methods, edge-based segmentation methods, and the like. The segmentation method based on the threshold is the most widely used in the prior art, and the basic principle is that the image is segmented into a background image and a target image by utilizing the gray difference of pixel points in the image, and then the image is segmented into a black part and a white part by the given threshold. In the threshold segmentation method, the maximum variance of the average gray levels of the target image and the background image is used as a criterion to determine the threshold, and the threshold segmentation method is widely applied due to the fast calculation speed and the good segmentation performance.
The traditional threshold segmentation method needs to write the whole image into a memory, and then counts the proportion of each gray value to calculate the threshold value which enables the inter-class variance to be maximum, the calculation step brings some defects in the segmentation of the pathological image with the ultrahigh resolution, namely, the occupied memory is large, and for an image with the resolution of 20 ten thousand × 20, 20 ten thousand × 3 (3 channels, the number of pixel bits is 8), the occupied memory is about 120 GB.
Disclosure of Invention
To solve the problems in the prior art, embodiments herein provide an image segmentation method, an image segmentation apparatus, and a computer-readable storage medium, which implement the purpose of finding a gray-scale segmentation value used for dividing a foreground image and a background image in an image to be processed in a low memory space by segmenting the image to be processed with high resolution or ultrahigh resolution into a plurality of regions and calculating gray-scale segmentation values of a target image and the background image according to gray-scale levels of pixels in the plurality of regions.
Embodiments herein provide an image segmentation method, including,
dividing an image to be processed into a plurality of areas;
writing a partial area in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial area;
calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region;
and calculating a gray level segmentation threshold value which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas.
Embodiments herein also provide an image segmentation apparatus, including,
the image processing device comprises a first segmentation unit, a second segmentation unit and a processing unit, wherein the first segmentation unit is used for segmenting an image to be processed into a plurality of areas;
a gray level calculation unit configured to write a partial region of the plurality of regions into a memory, and calculate a gray level of each pixel in the partial region;
the pixel calculation unit is used for calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region;
and the gray level segmentation threshold calculation unit is used for calculating a gray level segmentation threshold which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas.
Embodiments herein also provide a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above-mentioned method when executing the computer program.
Embodiments herein also provide a computer-readable storage medium having stored thereon computer instructions, which when executed by a processor, implement the above-described method.
By using the embodiment of the invention, when processing the image with high resolution, especially ultrahigh resolution, the segmentation threshold of the image to be processed can be obtained by using less memory, thus saving the memory space when processing the image and reducing the system cost.
Drawings
In order to more clearly illustrate the embodiments or technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flow chart illustrating a method of image segmentation according to an embodiment of the present disclosure;
FIG. 2a is a schematic diagram illustrating a gridding and segmenting an image to be processed according to an embodiment of the present disclosure;
FIG. 2b is a schematic diagram of another gridding segmentation of an image to be processed according to an embodiment of the present disclosure;
FIG. 3 is a schematic structural diagram illustrating an image segmentation apparatus according to an embodiment of the present disclosure;
FIG. 4 is a schematic diagram illustrating an embodiment of an image segmentation apparatus according to the present disclosure;
FIG. 5 is a flowchart illustrating an embodiment of a method for image segmentation;
FIG. 6 is a diagram illustrating the number of multiple regions of the to-be-processed image and the processing time for finding a suitable grayscale segmentation threshold for the entire to-be-processed image according to an embodiment of the disclosure;
FIG. 7 is a schematic diagram illustrating storing region vertex coordinates in a task queue according to an embodiment herein;
fig. 8 is a schematic structural diagram of a split image apparatus according to an embodiment of the disclosure.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments herein without making any creative effort, shall fall within the scope of protection.
First embodiment
Fig. 1 is a flowchart of an image segmentation method according to an embodiment of the present disclosure, in this embodiment, a high-resolution image is segmented into a target image and a background image by two-time segmentation, so as to achieve the purpose of segmenting the high-resolution image at the cost of small memory consumption, and the method can be applied to image recognition of the high-resolution image for pathological analysis and other scenes requiring large memory to load the image, and specifically includes the following steps:
step 101, dividing an image to be processed into a plurality of areas.
Step 102, writing a partial area of the plurality of areas into a memory, and calculating the gray level of each pixel in the partial area.
And 103, calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region.
And 104, calculating a gray level segmentation threshold value which maximizes the gray level difference between the target image of the image to be processed and the background image according to the number of pixels with different gray levels in all the areas.
According to an aspect of embodiments herein, writing a partial region of the plurality of regions to a memory, calculating a gray level of each pixel in the partial region further comprises,
and writing partial areas in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial areas by using one thread.
According to an aspect of embodiments herein, writing a partial area of the plurality of areas into a memory, calculating a gray level of each pixel in the partial area using one thread further comprises,
and writing one of the plurality of areas into a memory, and calculating the gray level of each pixel in the one area by using one thread.
In this step, each thread takes one region out of the memory for processing, so that multiple regions can be processed simultaneously by multi-core multithreading in the CPU, for example, 16 threads can be used to calculate the gray level of each pixel in 16 regions, thereby reducing the pressure of the high resolution image on the memory of the computer and improving the image processing speed.
According to one aspect of embodiments herein, further comprising, in segmenting the image to be processed into a plurality of regions,
gridding the image to be processed, and dividing the image to be processed into a plurality of areas;
the vertex coordinates of each of the plurality of regions are recorded.
In this step, the image to be processed is divided into a plurality of regions by meshing, and the image to be processed may be divided into rectangular meshes or divided into meshes in other shapes, as shown in fig. 2a, which is a schematic diagram of the image to be processed by meshing in this embodiment, fig. 2b is a schematic diagram of the image to be processed by another meshing in this embodiment, and a plurality of regions in different shapes are formed by dividing the image to be processed by meshing, where the region 201, the region 202, and the like are both part of the image to be processed, and vertex coordinates of each region are recorded, for example, coordinates of four vertices of a rectangle in fig. 2a are recorded as boundary information of the region 201, or coordinates of three vertices of a triangle in fig. 2b are recorded as boundary information of the region 201.
According to one aspect of the embodiments herein, before gridding the image to be processed, segmenting the image to be processed into the plurality of regions,
acquiring information of a computing environment and information of the image to be processed;
and calculating the quantity of gridding segmentation of the image to be processed according to the information of the computing environment and the information of the image to be processed.
In this step, the computing environment is computer configuration information for segmenting the image to be processed, and may include, for example, information such as the number of cores of a CPU of the computer, the number of threads of the CPU, and the memory capacity of the computer, where the information of the image to be processed includes information such as the resolution of the image to be processed, the gray level in the image to be processed, and the like, and the resolution of the image to be processed is 20 ten thousand × 20 ten thousand pixels, and the gray level information is 256 gray levels (0 to 255), and the like.
Said calculating a number of gridding partitions of said image to be processed based on information of said computing environment and information of said image to be processed further comprises,
multiplying the resolution of the image to be processed by the gray level, and dividing by the product of the memory for processing the image to be processed and the number of threads.
In this step, assuming that the total memory of the computer is aMB (megabytes), the total memory for processing the image to be processed is a part of the total memory, that is, b × a, which is, for example, 60% of the total memory, x is the number of threads for processing all regions of the image to be processed, w and h are the width and height of the image to be processed, and c is the gray level of the image to be processed, the number of gridding partitions performed on the image to be processed is:
m=(w×h×c)/(b×a/x)
according to an aspect of embodiments herein, writing a partial area of the plurality of areas into the memory further comprises,
forming a task queue by the vertex coordinates of the plurality of areas;
and writing partial areas in the plurality of areas into a memory according to the vertex coordinates of the areas according to the sequence in the task queue.
According to an aspect of the embodiments herein, further comprising after calculating the gray level of each pixel in the partial area,
and releasing the memory occupied by the partial area.
According to an aspect of the embodiments herein, calculating the gray level segmentation threshold value for maximizing the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the regions further comprises,
setting a gray level segmentation value;
segmenting the image to be processed into a target image and a background image according to the gray level segmentation value;
calculating the difference between the gray level of the target image and the gray level of the background image;
changing the gray level segmentation value, and calculating the difference between the gray level of the corresponding target image and the gray level of the background image;
and calculating a corresponding gray level segmentation threshold value when the difference between the target image gray level and the background image gray level is maximum.
In this step, the gray scale division value initially set may be an average value of the sum of gray scales of all pixels of the image to be processed, or may be two thirds of the sum of gray scales of all pixels of the image to be processed. And dividing pixels with the gray level lower than the set gray segmentation value in the image to be processed into a background image, and dividing pixels with the gray level greater than or equal to the set gray segmentation value in the image to be processed into a target image.
According to one aspect of embodiments herein, calculating the difference in the target image gray level and the background image gray level further comprises,
and calculating the square of the difference between the average gray levels of the background image and the target image, and multiplying the square by the ratio of the background image and the target image to the image to be processed to obtain the difference between the gray level of the target image and the gray level of the background image.
In this step, the formula g ═ w may be used1w0(u1-u0)2To represent the above calculation process, where g is the difference between the target image and the background image, and w is1Is the proportion of the background image to the image to be processed, w0Is the proportion of the target image to the image to be processed, u1Is the mean value of the gray levels of the background image, u0Is the average of the gray levels of the target image.
In other embodiments, the difference between the gray level of the target image and the gray level of the background image may be calculated in other manners, for example, the difference between the accumulated value of the gray levels of all pixels in the background image and the accumulated value of the gray levels of all pixels in the target image may be obtained; the difference between the gray level of the target image and the gray level of the background image can be obtained by adopting the difference between the proportion of the background image in the image to be processed and the proportion of the target image in the image to be processed.
According to one aspect of the embodiments herein, further comprising after calculating the grayscale segmentation threshold that maximizes the grayscale difference between the target image and the background image of the image to be processed,
and segmenting the image to be processed into the target image and the background image according to the gray level segmentation threshold.
By the embodiment of the text, when processing images with high resolution, particularly images with ultrahigh resolution, the segmentation threshold of the image to be processed can be obtained by using less memory, so that the space of the memory when processing the image is saved, and the system cost is reduced; and the advantage of multithreading of the processor can be utilized to realize parallel processing of the independent gridded images to be processed, thereby quickening the segmentation processing speed of the high-resolution images and saving time.
Second embodiment
Fig. 3 is a schematic structural diagram of an image segmentation apparatus according to an embodiment of the present invention, where the apparatus in this embodiment may be a computing device such as a computer, a computer cluster, a server, or the like, or may be implemented by a functional module of software running in the computing device, or by a logic circuit in a general chip or a programmable logic array (FGPA), and fig. 4 is a schematic structural diagram of an image segmentation apparatus according to an embodiment of the present invention, where a specific structure of the image segmentation apparatus is described in detail in this figure, and a functional unit or a module therein may be implemented by using a software module. The method specifically comprises the following steps:
a first segmentation unit 301, configured to segment the image to be processed into a plurality of regions.
A gray level calculating unit 302, configured to write a partial region of the plurality of regions into a memory, and calculate a gray level of each pixel in the partial region.
And the pixel calculating unit 303 is configured to calculate the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region.
A gray level segmentation threshold calculation unit 304, configured to calculate a gray level segmentation threshold that maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the regions.
According to an aspect of the embodiments herein, the gray-scale calculating unit 302 is further configured to write a partial area of the plurality of areas into a memory, and calculate the gray-scale level of each pixel in the partial area by using one thread.
According to an aspect of the embodiments herein, the gray level calculating unit 302 is further configured to write one of the plurality of regions into a memory, and calculate the gray level of each pixel in the one region by using one thread.
According to an aspect of embodiments herein, the first segmentation unit 301 further comprises,
a gridding module 3011, configured to gridd the image to be processed and divide the image to be processed into the multiple regions;
a recording module 3012, configured to record vertex coordinates of each of the plurality of regions.
According to an aspect of embodiments herein, the first segmentation unit 301 further comprises,
an environment information obtaining module 3013, configured to obtain information of a computing environment and information of the image to be processed;
and a gridding segmentation number calculation module 3014, configured to calculate, according to the information of the computing environment and the information of the image to be processed, a number of gridding segmentations to be performed on the image to be processed.
According to an aspect of embodiments herein, the gridding segmentation quantity calculation module 3014 is further configured to,
multiplying the resolution of the image to be processed by the gray level, and dividing by the product of the memory for processing the image to be processed and the number of threads.
According to an aspect of the embodiments herein, the gray level calculation unit 302 further comprises,
a task queue module 3021, configured to form a task queue from the vertex coordinates of the multiple regions;
a memory writing module 3022, configured to write a partial region of the multiple regions into a memory according to the vertex coordinates of the regions in the order in the task queue.
According to an aspect of the embodiments herein, the gray level calculating unit 302 is further configured to release the memory occupied by the partial region after calculating the gray level of each pixel in the partial region.
According to an aspect of embodiments herein, the grayscale segmentation threshold calculation unit 304 further includes,
a gray level setting module 3041 for setting a gray level division value;
a segmentation module 3042, configured to segment the to-be-processed image into a target image and a background image according to the gray level segmentation value;
a difference calculating module 3043, configured to calculate a difference between the target image gray level and the background image gray level;
an adjusting module 3044, configured to change the gray level segmentation value, and call the segmentation module 3042 and the difference calculating module 3043 to calculate the difference between the gray level of the corresponding target image and the gray level of the background image;
a grayscale segmentation threshold determination module 3045, configured to calculate a grayscale segmentation threshold corresponding to the maximum difference between the target image grayscale and the background image grayscale.
According to an aspect of the embodiment herein, the difference calculating module 3043 is further configured to calculate a square of a difference between the average gray levels of the background image and the target image, and then multiply the square by the ratio of the background image and the target image to the image to be processed to obtain a difference between the gray level of the target image and the gray level of the background image.
According to an aspect of the embodiments herein, further comprising a second segmentation unit 305 for segmenting the image to be processed into the target image and a background image according to the gray level segmentation threshold.
By the embodiment of the text, when processing images with high resolution, particularly images with ultrahigh resolution, the segmentation threshold of the image to be processed can be obtained by using less memory, so that the space of the memory when processing the image is saved, and the system cost is reduced; and the advantage of multithreading of the processor can be utilized to realize parallel processing of the independent gridded images to be processed, thereby quickening the segmentation processing speed of the high-resolution images and saving time.
Third embodiment
Fig. 5 is a specific flowchart of an image segmentation method according to an embodiment of the present disclosure, which describes in detail a segmentation processing method for a high-resolution image in this embodiment, and the segmentation processing method can be used in analysis and processing of a pathological image, and can also be applied to recognition, analysis and processing of other high-resolution images (for example, images with more than 1000 ten thousand pixels) or ultrahigh-resolution images (for example, images with more than 20 ten thousand × 20 with 20 ten thousand pixels and 3 channels), and specifically includes:
step 501, acquiring information of a computing environment and information of the image to be processed.
In this step, taking a Windows system as an example, the computing environment information, that is, hardware configuration information of the computer, such as the number of cores of the CPU, the number of threads, and the memory capacity, may be obtained by calling a system registry; the computing environment information may also be obtained by calling an Application Programming Interface (API) of the Windows system, for example, by using functions such as gethypervisor memory (); the computing environment information may also be obtained by calling Windows Management Instrumentation (WMI).
The information of the image to be processed can be obtained through the attribute information carried by the image to be processed, in this example, 20 ten thousand × 20 ten thousand resolution, and the 3-channel gray scale is 256-level image to be processed.
Step 502, calculating the number of gridding and dividing the image to be processed according to the information of the computing environment and the information of the image to be processed.
In this step, the number of gridding partitions of the to-be-processed image is calculated by m ═ w × h × c)/(b × a/x, where the total memory amount of the computer is aMB (megabytes), the total memory amount of the to-be-processed image is a part of the total memory amount, i.e., b × a, for example, 50% of the total memory amount, x is the number of threads processing all regions of the to-be-processed image, w and h are the width and height of the to-be-processed image, and c is the gray level of the to-be-processed image or the gray level with multiple channels.
It should be noted that the number of threads for processing all areas of the image to be processed is a part of all available threads of the computer processor, that is, a part of thread processing is required for the computer system to operate, a part of thread processing is required for other program operations in the computer system, and a part of thread processing is also required for performing segmentation on the image to be processed and subsequent identification and segmentation of the target image and the background image.
The image to be processed is divided into a plurality of areas through the step, and the phenomena of frequently reading and writing the memory file and frequently switching tasks are mainly considered if the pixel data in the image of each divided area is too little; if the pixel data in the image of each segmented region is too much, the phenomenon that page changing is frequent due to insufficient memory occurs, the number of the multiple segmented regions of the image to be processed (the abscissa axis is the number of the dividing tasks) and the processing time for finding the appropriate gray level segmentation threshold of the whole image to be processed (the ordinate axis is the time) are as shown in fig. 6, therefore, under the condition that the computing environment and the image to be processed are considered, the inventor calculates the appropriate number of the segmented regions by the method, the image processing speed can be greatly improved, the requirement of the processed image on the memory of a computer is reduced, and the processing time of the high-resolution image is shortened.
And 503, segmenting the image to be processed according to the gridding segmentation quantity.
In this step, the to-be-processed image may be divided into a plurality of regions by referring to the gridding processing as shown in fig. 2a or fig. 2 b.
Step 504, storing the vertex coordinates of the plurality of areas into a task queue.
In this step, for example, the image to be processed is divided into m × n areas, where m is a row of the division of the image to be processed, and n is a column of the division of the image to be processed, the vertex coordinates of the areas of the image to be processed may be stored into the task queue in order from left to right with reference to the schematic diagram shown in fig. 7 for storing the vertex coordinates of the areas into the task queue according to the embodiment herein.
In this step, the vertex coordinates of all the regions may be written into the task queue of the memory, or only the vertex coordinates of a part of the regions may be written into the task queue of the memory.
Step 505, a thread fetches the region vertex coordinates of a task from the task queue, and writes a region of the to-be-processed image corresponding to the region vertex coordinates into the memory.
In this step, a region of the image to be processed may only need a memory space of several hundred megabytes, which saves a large amount of memory space and reduces the hardware requirement for the image processing apparatus, compared with the prior art in which the center writes all of the entire image to be processed into the memory.
In this step, the vertex coordinates of 2 regions (or 3 regions) may also be taken out, and the images of the corresponding regions are written into the memory, so that the image processing speed of the plurality of regions may be further increased.
Step 506, the gray level of each pixel in the region is calculated.
In this step, an array is initialized to store the gray level of each pixel, e.g. r1=[0,0,0,…,0]Where the number of bits in the array is L, where L is (0,1, …, L-1), where the number of bits in the array is 256 in this example, i.e., L is 256, each bit in the array is initialized to 0, the gray level of each pixel is obtained by traversing each pixel in the region, the number of pixels in which each gray level occurs is counted, and the result of counting the number of pixels is written into the array r1In the method, a statistical result r of the gray level of the pixels in the area is formed1=[n0,n1,...nL-1]Wherein n isiThe number of pixels corresponding to a certain gray level.
And 507, judging whether the vertex coordinate of the next area exists in the task queue, if so, acquiring the vertex coordinate of the next area, returning to the step 505, and otherwise, entering the step 508.
In step 505 and 507, different threads calculate the gray levels of the pixels in different areas.
And step 508, calculating the number of pixels with different gray levels in the whole image to be processed.
In this step, after the gray levels of the pixels in all the regions are counted, all the threads in the relevant thread pool are released, and the image data of all the regions in the memory are released.
Adding the pixel numbers corresponding to each gray level of different arrays corresponding to different areas to obtain the frequency R (N) of gray level appearance in the whole image to be processed0,N1,...NL-1]Wherein N isiThe number of pixels in the whole image to be processed corresponding to a certain gray level.
To obtain
Figure BDA0002415524290000101
Wherein N isiFor the number of pixels with the gray level i in the whole image to be processed, j is one of m × n areas, namely one task in the task queue, i is a certain gray level, i ranges from 0 to L-1, and njiThe number of pixels with gray level i in the jth region.
In step 509, a gray-scale division value is set.
In this step, an initial gray-level division value is set, for example, empirically, or the gray-level division value is set to 128, that is, to the middle of 256 gray levels in this example, or may also be set to a gray value of 2/3 out of all gray levels.
And 510, segmenting the image to be processed into a target image and a background image according to the gray level segmentation value.
In the step, the image to be processed is divided into a target image A and a background image according to a set initial gray level division value, wherein the gray level range of the target image A is {0,1, …, t-1}, the gray level range of the background image B is { t, t +1, …, L-1 }, the number of pixels of the whole image to be processed is N, and the number of pixels in the target image A is N
Figure BDA0002415524290000111
The number of pixels in the background image B is
Figure BDA0002415524290000112
w0、w1The proportion of pixels of the target image A and background image B to the total image pixels to be processed, e.g. w0=NA/N,w1=NB/N;u0、u1Which are the average gray levels of the target image a and the background image B, respectively, the accumulated sum may be divided by t by the accumulated sum of the gray levels of the target image a divided by the number of gray levels, i.e., gray level 0 takes a value of 0, gray level 1 takes a value of 1, accumulated to a value of gray level t-1, e.g., the initial division value t is 128, and the average gray level of the target image a is u0(0+1+2+ … 127)/128, or also by
Figure BDA0002415524290000113
Calculating the average gray level of the target image A, wherein i is the gray level and p is the gray leveliProbability of gray level i, pi=NiN, wherein pi>Is equal to 0, and
Figure BDA0002415524290000114
the accumulated sum may be divided by L-t, e.g., the initial segmentation value t is 128, and the average gray level of the target image a is u, by the accumulated sum of the gray levels of the background image B divided by the number of gray levels, i.e., gray level t takes the value of t, gray level 255 takes the value of 255, and the accumulated sum is divided by the number of gray levels L-1, e.g., the initial segmentation value t is 1280(128+129+130+ … 255)/128, or also by
Figure BDA0002415524290000115
The average gray level of the background image B is calculated.
Calculating to obtain the difference g between the gray level of the target image and the gray level of the background image, wherein the difference is w1w0(u1-u0)2
And 511, judging whether other changeable gray level segmentation values exist, if so, changing the gray level segmentation values, returning to the step 510, otherwise, entering the step 512.
In this step, the gray level segmentation value t is changed to 129, for example, and the difference g between the corresponding target image gray level and the background image gray level is calculated in the substituting step 510. Until all values of the gray level division value t are tried, 256 g values are obtained.
And step 512, calculating a corresponding gray level segmentation threshold value when the difference between the target image gray level and the background image gray level is maximum.
In this step, the gray level segmentation value corresponding to the maximum g value is found as the gray level segmentation threshold according to all the g values calculated in the above-mentioned steps 509-511.
And 513, segmenting the image to be processed into the target image and a background image according to the gray level segmentation threshold.
Therefore, the target image and the background image of the pathological image with ultrahigh resolution can be obtained, so that corresponding image analysis can be carried out, for example, a focus image in the target image can be further analyzed.
Through the embodiment of the text, the number of the segmentation areas is determined according to the computing environment and the information of the image to be processed, and the processing speed and the memory consumption are properly matched, so that the image processing speed can be increased, and the requirements on computer hardware can be reduced; when processing images with high resolution, particularly images with ultrahigh resolution, the segmentation threshold of the image to be processed can be obtained by using less memory, so that the space of the memory when processing the image is saved, and the system cost is reduced; and the advantage of multithreading of the processor can be utilized to realize parallel processing of the independent gridded images to be processed, thereby quickening the segmentation processing speed of the high-resolution images and saving time.
As shown in fig. 8, which is a schematic structural diagram of a split image apparatus according to an embodiment of the present disclosure, in which the split image apparatus is referred to as a computing device, a computing device 802 may include one or more processing devices 804, such as one or more Central Processing Units (CPUs), each of which may implement one or more hardware threads. The computing device 802 may also include any storage resources 806 for storing any kind of information, such as code, settings, data, and the like. For example, and without limitation, storage resources 806 may include any one or more of the following in combination: any type of RAM, any type of ROM, flash memory devices, hard disks, optical disks, etc. More generally, any storage resource may use any technology to store information. Further, any storage resource may provide volatile or non-volatile reservation of information. Further, any storage resource may represent a fixed or removable component of computing device 802. In one case, when the processing device 804 executes associated instructions stored in any storage resource or combination of storage resources, the computing device 802 can perform any of the operations of the associated instructions. The computing device 802 also includes one or more drive mechanisms 808, such as a hard disk drive mechanism, an optical disk drive mechanism, etc., for interacting with any storage resource.
Computing device 802 may also include input/output module 810(I/O) for receiving various inputs (via input device 812) and for providing various outputs (via output device 814)). One particular output mechanism may include a presentation device and an associated Graphical User Interface (GUI). Computing device 802 may also include one or more network interfaces 820 for exchanging data with other devices via one or more communication links 822. One or more communication buses 824 couple the above-described components together.
Communication link 822 may be implemented in any manner, such as over a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 822 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.
Embodiments herein also provide a computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
dividing an image to be processed into a plurality of areas;
writing a partial area in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial area;
calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region;
and calculating a gray level segmentation threshold value which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas.
The computer device provided by the embodiment can also implement the methods in fig. 2, 5-7.
Corresponding to the methods in fig. 2, 5-7, the embodiments herein also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the steps of the above-described method.
Embodiments herein also provide computer readable instructions, wherein when executed by a processor, a program thereof causes the processor to perform the methods as shown in fig. 2, 5-7.
It should be understood that, in various embodiments herein, the sequence numbers of the above-mentioned processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments herein.
It should also be understood that, in the embodiments herein, the term "and/or" is only one kind of association relation describing an associated object, meaning that three kinds of relations may exist. For example, a and/or B, may represent: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present disclosure.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided herein, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purposes of the embodiments herein.
In addition, functional units in the embodiments herein may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present invention may be implemented in a form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The principles and embodiments of this document are explained herein using specific examples, which are presented only to aid in understanding the methods and their core concepts; meanwhile, for the general technical personnel in the field, according to the idea of this document, there may be changes in the concrete implementation and the application scope, in summary, this description should not be understood as the limitation of this document.

Claims (22)

1. An image segmentation method is characterized by comprising the following steps,
dividing an image to be processed into a plurality of areas;
writing a partial area in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial area;
calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region;
and calculating a gray level segmentation threshold value which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas.
2. The method of claim 1, wherein in writing a portion of the plurality of regions to memory, calculating a gray scale level for each pixel in the portion further comprises,
and writing partial areas in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial areas by using one thread.
3. The method of claim 2, wherein in writing a portion of the plurality of regions to memory, calculating a gray level for each pixel in the portion using a thread further comprises,
and writing one of the plurality of areas into a memory, and calculating the gray level of each pixel in the one area by using one thread.
4. The method of claim 1, further comprising, in segmenting the image to be processed into a plurality of regions,
gridding the image to be processed, and dividing the image to be processed into a plurality of areas;
the vertex coordinates of each of the plurality of regions are recorded.
5. The method according to claim 4, further comprising, before gridding the image to be processed, segmenting the image to be processed into the plurality of regions,
acquiring information of a computing environment and information of the image to be processed;
and calculating the quantity of gridding segmentation of the image to be processed according to the information of the computing environment and the information of the image to be processed.
6. The method of claim 5, wherein the calculating the number of gridding partitions the image to be processed according to the information of the computing environment and the information of the image to be processed further comprises,
multiplying the resolution of the image to be processed by the gray level, and dividing by the product of the memory for processing the image to be processed and the number of threads.
7. The method of claim 4, further comprising writing a portion of the plurality of regions to memory,
forming a task queue by the vertex coordinates of the plurality of areas;
and writing partial areas in the plurality of areas into a memory according to the vertex coordinates of the areas according to the sequence in the task queue.
8. The method according to claim 1, wherein the calculating the gray level segmentation threshold value for maximizing the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the regions further comprises,
setting a gray level segmentation value;
segmenting the image to be processed into a target image and a background image according to the gray level segmentation value;
calculating the difference between the gray level of the target image and the gray level of the background image;
changing the gray level segmentation value, and calculating the difference between the gray level of the corresponding target image and the gray level of the background image;
and calculating a corresponding gray level segmentation threshold value when the difference between the target image gray level and the background image gray level is maximum.
9. The method of claim 8, wherein calculating the difference in the target image gray level and background image gray level further comprises,
and calculating the square of the difference between the average gray levels of the background image and the target image, and multiplying the square by the ratio of the background image and the target image to the image to be processed to obtain the difference between the gray level of the target image and the gray level of the background image.
10. The method of claim 1, further comprising, after calculating a grayscale segmentation threshold that maximizes grayscale differences between the target image and the background image of the image to be processed,
and segmenting the image to be processed into the target image and the background image according to the gray level segmentation threshold.
11. An image segmentation apparatus, characterized by comprising,
the image processing device comprises a first segmentation unit, a second segmentation unit and a processing unit, wherein the first segmentation unit is used for segmenting an image to be processed into a plurality of areas;
a gray level calculation unit configured to write a partial region of the plurality of regions into a memory, and calculate a gray level of each pixel in the partial region;
the pixel calculation unit is used for calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region;
and the gray level segmentation threshold calculation unit is used for calculating a gray level segmentation threshold which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas.
12. The apparatus of claim 11, wherein the gray level calculating unit is further configured to write a partial area of the plurality of areas into a memory, and calculate the gray level of each pixel in the partial area using one thread.
13. The apparatus of claim 12, wherein the gray level calculating unit is further configured to write one of the plurality of regions into a memory, and calculate the gray level of each pixel in the one region using one thread.
14. The apparatus of claim 11, wherein the first segmentation unit further comprises,
the gridding module is used for gridding the image to be processed and dividing the image to be processed into a plurality of areas;
a recording module for recording the vertex coordinates of each of the plurality of regions.
15. The apparatus of claim 14, wherein the first segmentation unit further comprises,
the environment information acquisition module is used for acquiring information of a computing environment and information of the image to be processed;
and the gridding segmentation quantity calculation module is used for calculating the quantity of gridding segmentation to be carried out on the image to be processed according to the information of the calculation environment and the information of the image to be processed.
16. The apparatus of claim 15, wherein the gridding partitioning number computation module is further configured to,
multiplying the resolution of the image to be processed by the gray level, and dividing by the product of the memory for processing the image to be processed and the number of threads.
17. The apparatus of claim 14, wherein the gray level calculation unit further comprises,
the task queue module is used for forming a task queue by the vertex coordinates of the plurality of areas;
and the memory writing module is used for writing partial regions in the plurality of regions into a memory according to the vertex coordinates of the regions according to the sequence in the task queue.
18. The apparatus of claim 11, wherein the grayscale segmentation threshold calculation unit further includes,
the gray level setting module is used for setting a gray level segmentation value;
the segmentation module is used for segmenting the image to be processed into a target image and a background image according to the gray level segmentation value;
the difference calculation module is used for calculating the difference between the gray level of the target image and the gray level of the background image;
the adjusting module is used for changing the gray level segmentation value and calling the segmentation module and the difference calculating module to calculate the difference between the gray level of the corresponding target image and the gray level of the background image;
and the gray level segmentation threshold determination module is used for calculating a corresponding gray level segmentation threshold when the difference between the gray level of the target image and the gray level of the background image is maximum.
19. The apparatus of claim 18, wherein the difference calculating module is further configured to calculate a square of a difference between the average gray levels of the background image and the target image, and multiply the square by the ratio of the background image and the target image to the image to be processed to obtain a difference between the gray level of the target image and the gray level of the background image.
20. The apparatus according to claim 11, further comprising a second segmentation unit configured to segment the image to be processed into the target image and a background image according to the gray level segmentation threshold.
21. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor when executing the computer program implements the steps of:
dividing an image to be processed into a plurality of areas;
writing a partial area in the plurality of areas into a memory, and calculating the gray level of each pixel in the partial area;
calculating the number of pixels with different gray levels in all the regions according to the gray level of each pixel in the partial region;
and calculating a gray level segmentation threshold value which maximizes the gray level difference between the target image and the background image of the image to be processed according to the number of pixels with different gray levels in all the areas.
22. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, is adapted to carry out the method of any of the preceding claims 1-10.
CN202010190013.5A 2020-03-18 2020-03-18 Image segmentation method and device and computer readable storage medium Pending CN111429413A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010190013.5A CN111429413A (en) 2020-03-18 2020-03-18 Image segmentation method and device and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010190013.5A CN111429413A (en) 2020-03-18 2020-03-18 Image segmentation method and device and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN111429413A true CN111429413A (en) 2020-07-17

Family

ID=71553582

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010190013.5A Pending CN111429413A (en) 2020-03-18 2020-03-18 Image segmentation method and device and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN111429413A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015102057A1 (en) * 2014-01-06 2015-07-09 富士通株式会社 Image processing method, image processing system, and program
CN105184769A (en) * 2015-08-05 2015-12-23 魏芳 Sharp-image-processing-based underwater equipment defect identification system
CN107146193A (en) * 2017-04-28 2017-09-08 南京觅踪电子科技有限公司 A kind of GPU parallel calculating methods based on double video cards applied to image procossing
CN108008975A (en) * 2017-12-22 2018-05-08 郑州云海信息技术有限公司 A kind of processing method and processing device of the view data based on KNL platforms

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015102057A1 (en) * 2014-01-06 2015-07-09 富士通株式会社 Image processing method, image processing system, and program
CN105184769A (en) * 2015-08-05 2015-12-23 魏芳 Sharp-image-processing-based underwater equipment defect identification system
CN107146193A (en) * 2017-04-28 2017-09-08 南京觅踪电子科技有限公司 A kind of GPU parallel calculating methods based on double video cards applied to image procossing
CN108008975A (en) * 2017-12-22 2018-05-08 郑州云海信息技术有限公司 A kind of processing method and processing device of the view data based on KNL platforms

Similar Documents

Publication Publication Date Title
Yang et al. Constant time median and bilateral filtering
EP1831823B1 (en) Segmenting digital image and producing compact representation
JP6151763B2 (en) Word segmentation for document images using recursive segmentation
WO2019129032A1 (en) Remote sensing image recognition method and apparatus, storage medium and electronic device
US9697423B1 (en) Identifying the lines of a table
CN111080660B (en) Image segmentation method, device, terminal equipment and storage medium
US9342870B2 (en) Tree-based linear regression for denoising
CN107209942B (en) Object detection method and image retrieval system
CN108510499B (en) Image threshold segmentation method and device based on fuzzy set and Otsu
JP6161266B2 (en) Information processing apparatus, control method therefor, electronic device, program, and storage medium
CN113870293B (en) Image processing method, image processing device, electronic equipment and storage medium
CN112419372B (en) Image processing method, device, electronic equipment and storage medium
US20190019292A1 (en) Fast, progressive approach to supervoxel-based spatial temporal video segmentation
CN113034387A (en) Image denoising method, device, equipment and medium
CN115908363B (en) Tumor cell statistics method, device, equipment and storage medium
CN111429413A (en) Image segmentation method and device and computer readable storage medium
Kamarujjaman et al. A novel decision-based adaptive feedback median filter for high density impulse noise suppression
CN114972209A (en) Cervical pathology image processing method and device
CN111160358B (en) Image binarization method, device, equipment and medium
Fujita et al. High-dimensional Guided Image Filtering.
CN112001479A (en) Processing method and system based on deep learning model and electronic equipment
CN112446933A (en) Financial asset imaging method and device, electronic equipment and readable storage medium
CN111369425A (en) Image processing method, image processing device, electronic equipment and computer readable medium
DE102018130345A1 (en) Budget aware method for capturing activity in videos
US11244190B1 (en) System and method for patterned artifact removal for bitonal images

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20220914

Address after: 25 Financial Street, Xicheng District, Beijing 100033

Applicant after: CHINA CONSTRUCTION BANK Corp.

Address before: 25 Financial Street, Xicheng District, Beijing 100033

Applicant before: CHINA CONSTRUCTION BANK Corp.

Applicant before: Jianxin Financial Science and Technology Co.,Ltd.