CN111402276B - Binary image generation method and device, electronic equipment and readable storage medium - Google Patents
Binary image generation method and device, electronic equipment and readable storage medium Download PDFInfo
- Publication number
- CN111402276B CN111402276B CN201910004989.6A CN201910004989A CN111402276B CN 111402276 B CN111402276 B CN 111402276B CN 201910004989 A CN201910004989 A CN 201910004989A CN 111402276 B CN111402276 B CN 111402276B
- Authority
- CN
- China
- Prior art keywords
- image
- pixel
- pixel value
- value
- preset
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 48
- 239000011159 matrix material Substances 0.000 claims abstract description 81
- 238000004891 communication Methods 0.000 claims description 18
- 238000006243 chemical reaction Methods 0.000 claims description 15
- 238000004590 computer program Methods 0.000 claims description 13
- 230000000007 visual effect Effects 0.000 abstract description 12
- 230000000694 effects Effects 0.000 abstract description 11
- 238000010586 diagram Methods 0.000 description 5
- 230000009471 action Effects 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 238000003491 array Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000000802 evaporation-induced self-assembly Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000010354 integration Effects 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000007639 printing Methods 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 230000007704 transition Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/12—Edge-based segmentation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T5/00—Image enhancement or restoration
- G06T5/90—Dynamic range modification of images or parts thereof
- G06T5/92—Dynamic range modification of images or parts thereof based on global image properties
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/10—Image acquisition modality
- G06T2207/10024—Color image
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20021—Dividing image into blocks, subimages or windows
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Image Processing (AREA)
Abstract
The embodiment of the invention provides a binary image generation method, a binary image generation device, electronic equipment and a readable storage medium. The method comprises the following steps: obtaining a color image to be processed; converting the color image into a gray scale image; converting a first pixel value of each pixel in the gray scale image to a second pixel value; wherein each second pixel value is located within a preset range; adding the second pixel value of each pixel of the pixel block in the gray image with the value of the corresponding position in the preset matrix to obtain a third pixel value of each pixel in the gray image; wherein the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical; resetting the third pixel value which is larger than or equal to the preset judgment threshold value to be 1, and resetting the third pixel value which is smaller than the judgment threshold value to be 0, so as to obtain a binary image corresponding to the color image. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
Description
Technical Field
The present invention relates to the field of image processing technologies, and in particular, to a binary image generating method, a binary image generating device, an electronic device, and a readable storage medium.
Background
In order to reduce the size of an image, it is often necessary to convert a color image into a binary image. Wherein the two-dimensional matrix of one binary image is composed of only two values of 0 and 1, and 0 represents black and 1 represents white. That is, there is no intermediate color in the binary image that transitions from black to white.
Currently, the manner of converting a color image into a binary image is: converting the color image into a gray scale image; comparing each pixel value in the gray image with a preset threshold value; resetting the pixel value smaller than the preset threshold to 0 and resetting the pixel value larger than the preset threshold to 1.
The inventors have found that this way of resetting the pixel values based on a preset threshold value results in a sliced 0 or 1 in the binary image in the course of implementing the invention. That is, the generated binary image appears as a patch of black and white. Therefore, the generated binary image does not have gray scale of the gray scale image any more, and a user cannot obtain better visual experience.
Disclosure of Invention
The embodiment of the invention aims to provide a binary image generation method, a binary image generation device, electronic equipment and a readable storage medium, so that the generated binary image can show a gray scale effect, and the visual experience of a user is improved. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a binary image generating method, which may include:
obtaining a color image to be processed;
converting the color image into a gray scale image;
converting a first pixel value of each pixel in the gray scale image to a second pixel value; wherein each second pixel value is located within a preset range;
adding the second pixel value of each pixel of the pixel block in the gray image with the value of the corresponding position in the preset matrix to obtain a third pixel value of each pixel in the gray image; wherein the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical;
resetting the third pixel value which is larger than or equal to the preset judgment threshold value to be 1, and resetting the third pixel value which is smaller than the judgment threshold value to be 0, so as to obtain a binary image corresponding to the color image.
Optionally, the step of converting the first pixel value of each pixel in the gray image to the second pixel value may include:
dividing a first pixel value of each pixel in the gray image by 255 to obtain a second pixel value corresponding to each first pixel value; wherein the preset range includes [0,1].
Optionally, the preset matrix may include:
optionally, the step of resetting the third pixel value greater than or equal to the preset decision threshold to 1 and resetting the third pixel value less than the decision threshold to 0 to obtain the binary image corresponding to the color image may include:
resetting the third pixel value which is more than or equal to 1, and resetting the third pixel value which is less than 1 to 0 to obtain a binary image corresponding to the color image.
Alternatively, the step of converting the color image into the gray-scale image may include:
converting the color image into a BMP image in an image file format;
the BMP image is converted into a gray scale image.
In a second aspect, an embodiment of the present invention further provides a binary image generating device, where the binary image generating device may include:
the first obtaining module is used for obtaining a color image to be processed by a user;
a first conversion module for converting a color image into a gray image;
a second conversion module for converting a first pixel value of each pixel in the gray image into a second pixel value; wherein each second pixel value is located within a preset range;
the second obtaining module is used for adding the second pixel value of each pixel of the pixel block in the gray image with the value of the corresponding position in the preset matrix to obtain a third pixel value of each pixel in the gray image; wherein the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical;
and the third obtaining module is used for resetting a third pixel value which is larger than or equal to a preset judgment threshold value to be 1, and resetting a third pixel value which is smaller than the judgment threshold value to be 0, so as to obtain a binary image corresponding to the color image.
Optionally, the second conversion module may specifically be configured to:
dividing a first pixel value of each pixel in the gray image by 255 to obtain a second pixel value corresponding to each first pixel value; wherein the preset range includes [0,1].
Optionally, the preset matrix may include:
optionally, the third obtaining module may specifically be configured to:
resetting the third pixel value which is more than or equal to 1, and resetting the third pixel value which is less than 1 to 0 to obtain a binary image corresponding to the color image.
Alternatively, the first conversion module may include:
a first conversion unit for converting the color image into a BMP image in an image file format;
and a second converting unit for converting the BMP image into a gray scale image.
In a third aspect, an embodiment of the present invention further provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the method steps of any binary image generation method when executing the program stored in the memory.
In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, in which a computer program is stored, where the computer program, when executed by a processor of an electronic device, implements method steps of any of the binary image generating methods described above.
In a fifth aspect, embodiments of the present invention also provide a computer program product that, when run on an electronic device, causes the electronic device to perform: the method steps of any binary image generation method.
In the embodiment of the invention, the electronic equipment can obtain the color image to be processed. The color image may then be converted to a grayscale image. Then, the first pixel value of each pixel in the gray image may be converted into a second pixel value, the second pixel value being within a preset range. Then, for each pixel block in the gray image, the second pixel value of each pixel in the pixel block may be added to the corresponding value in the preset matrix. Thus, the third pixel value of each pixel in the grayscale image can be obtained. Wherein the size of each pixel block is the same as the size of the preset matrix, and each value in the preset matrix is not completely the same. Then, the third pixel value greater than or equal to the preset decision threshold may be reset to 1, and the third pixel value less than the decision threshold may be reset to 0, so that the color image may be converted into a binary image.
Wherein, since the size of the pixel block is the same as the size of the preset matrix, the gray image can be divided into a plurality of pixel blocks according to the size of the preset matrix. In addition, since the values in the preset matrix are not identical, after adding the second pixel value of each pixel in each pixel block to the value of the corresponding position in the preset matrix to obtain the third pixel, comparing the third pixel value with the decision threshold value and resetting the third pixel value, both the 1 value and the 0 value appear in the pixel block. Moreover, when the number of 0 values in the pixel block is large, the human eyes can see that the pixel block is dark; when the number of 1 values in the pixel block is large, the human eye can see the light color of the pixel block. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a binary image generating method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a gray scale image according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a binary image generated by the prior art.
Fig. 4 is a schematic diagram of a binary image according to an embodiment of the present invention.
Fig. 5 is a schematic structural diagram of a binary image generating device according to an embodiment of the present invention.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In the prior art, the mode of converting a color image into a binary image is as follows: the color image is first converted to a gray scale image as shown in fig. 2. Each pixel value in the gray scale image is then compared to a preset threshold. Then, the pixel value smaller than the preset threshold is reset to 0, and the pixel value larger than the preset threshold is reset to 1. In this way, the generated binary image appears black and white as in the slice of fig. 3. That is, the binary image production method makes the generated binary image no longer have gray scale of gray scale image, and thus the user cannot obtain better visual experience.
In order to solve the technical problems, the embodiment of the invention provides a novel binary image generation method, a device, electronic equipment and a readable storage medium.
The binary image generating method provided by the embodiment of the invention is described below.
The binary image generation method provided by the embodiment of the invention is applied to electronic equipment. The electronic device includes, but is not limited to, a computer, a mobile phone and a server.
Referring to fig. 1, the method may include the steps of:
s101: obtaining a color image to be processed;
the color image to be processed may be any one or more color images. The color image may be an image in jpg format or an image in png (Portable Network Graphics, portable network picture) format, but is not limited thereto.
Specifically, the color image to be processed may also be an image stored in a PDF (Portable Document Format ) document.
S102: converting the color image into a gray scale image;
it will be appreciated that the color image may be converted to a gray image according to any method of obtaining a gray image. For example, a grayscale image as shown in fig. 2 may be obtained.
When the color image to be processed is an image stored in a PDF document, the color image may be first converted into a BMP (Bitmap, image file format) image. Wherein each pixel in the BMP image has RGB values. The BMP image may then be converted to a grayscale image.
Any method for converting BMP images into gray images in the prior art can be adopted to convert BMP images into gray images.
S103: converting a first pixel value of each pixel in the gray scale image to a second pixel value; wherein each second pixel value is located within a preset range;
the operation of converting the first pixel value of each pixel in the gray image into the second pixel value may specifically be: dividing the first pixel value of each pixel in the gray image by 255 to obtain a second pixel value corresponding to each first pixel value. Wherein the preset range includes [0,1]. In this way, the first pixel value of each pixel in the grayscale image can be converted to a second pixel value that lies within the [0,1] interval.
Of course, the first pixel value of each pixel in the gray-scale image may be divided by 25.5 to obtain the second pixel value corresponding to each first pixel value. Wherein the preset range includes [0,10]. This is also reasonable.
S104: adding the second pixel value of each pixel of the pixel block in the gray image with the value of the corresponding position in the preset matrix to obtain a third pixel value of each pixel in the gray image; wherein the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical;
the preset matrix may specifically be:
since the predetermined matrix is a matrix of 8×8, and the size of each pixel block is the same as the size of the predetermined matrix. Thus, it can be known that each pixel block includes: 8×8=64 pixels.
Assuming that the second pixel value of the pixel in the first row and the first column in a pixel block of the gray image is 0.8, after the second pixel value is added to the value 0.4 of the corresponding position (i.e., the first row and the first column) in the preset matrix, the third pixel value of the pixel in the first row and the first column in the pixel block is 1.2.
The preset matrix may also be a matrix obtained by performing data fine adjustment on the listed matrix.
In addition, the preset matrix may specifically be: it is reasonable to multiply the above listed matrix by 10.
In addition, the preset matrix may also be a 16×16 matrix, which is also reasonable.
S105: resetting the third pixel value which is larger than or equal to the preset judgment threshold value to be 1, and resetting the third pixel value which is smaller than the judgment threshold value to be 0, so as to obtain a binary image corresponding to the color image.
Specifically, the third pixel value greater than or equal to 1 may be reset to 1, and the third pixel value less than 1 may be reset to 0, so as to obtain a binary image corresponding to the color image.
Continuing with the above example, when the third pixel value of the pixel of the first row and the first column in one pixel block is 1.2, then it may be determined that the second pixel value is greater than 1, and at this time, the value of the third pixel may be set to 1. In this way, after the first pixel value in the gray image is converted into either a 0 value or a 1 value, a binary image as shown in fig. 4 corresponding to the color image can be obtained.
The binary image shown in fig. 4 is also a binary image corresponding to the gray-scale image shown in fig. 2. As can be seen from comparing fig. 2 and fig. 4, the binary image fig. 4 generated by the embodiment of the invention is closer to the gray image fig. 2 corresponding to the color image, and can show gray scale effect to the user.
This is because, based on the binary image generation method in the embodiment of the present invention, there are both 1 and 0 values in the pixel block, that is, there are both white and black in the pixel block. Specifically, when the pixel block is more white and less black, the human eye can feel that the pixel block is light; when the pixel block is much less white and more black, the human eye can feel the pixel block dark. Therefore, even if the generated binary image has only 0 value and 1 value, the gray scale effect can be displayed for the user, and the visual experience of the user can be improved.
In addition, the binary image generation method provided by the embodiment of the invention can also be applied to the technical field of printing. Therefore, the occurrence of the situation that the black and white files printed are in the form of sheets and are inconvenient for a user to read can be avoided.
In the embodiment of the invention, the electronic equipment can obtain the color image to be processed. The color image may then be converted to a grayscale image. Then, the first pixel value of each pixel in the gray image may be converted into a second pixel value, the second pixel value being within a preset range. Then, for each pixel block in the gray image, the second pixel value of each pixel in the pixel block may be added to the corresponding value in the preset matrix. Thus, the third pixel value of each pixel in the grayscale image can be obtained. Wherein the size of each pixel block is the same as the size of the preset matrix, and each value in the preset matrix is not completely the same. Then, the third pixel value greater than or equal to the preset decision threshold may be reset to 1, and the third pixel value less than the decision threshold may be reset to 0, so that the color image may be converted into a binary image.
Wherein, since the size of the pixel block is the same as the size of the preset matrix, the gray image can be divided into a plurality of pixel blocks according to the size of the preset matrix. In addition, since the values in the preset matrix are not identical, after adding the second pixel value of each pixel in each pixel block to the value of the corresponding position in the preset matrix to obtain the third pixel, comparing the third pixel value with the decision threshold value and resetting the third pixel value, both the 1 value and the 0 value appear in the pixel block. Moreover, when the number of 0 values in the pixel block is large, the human eyes can see that the pixel block is dark; when the number of 1 values in the pixel block is large, the human eye can see the light color of the pixel block. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
In summary, by applying the binary image generation method provided by the embodiment of the invention, the generated binary image can show the gray scale effect, so that the visual experience of a user can be improved.
Corresponding to the above method embodiment, the embodiment of the present invention further provides a binary image generating device, referring to fig. 5, the device may include:
a first obtaining module 501, for obtaining a color image to be processed by a user;
a first conversion module 502 for converting a color image into a gray scale image;
a second conversion module 503, configured to convert a first pixel value of each pixel in the gray-scale image into a second pixel value; wherein each second pixel value is located within a preset range;
a second obtaining module 504, configured to add a second pixel value of each pixel of the pixel block in the gray image to a value of a corresponding position in the preset matrix, so as to obtain a third pixel value of each pixel in the gray image; wherein the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical;
the third obtaining module 505 is configured to reset a third pixel value greater than or equal to a preset decision threshold to 1, and reset a third pixel value less than the decision threshold to 0, so as to obtain a binary image corresponding to the color image.
By applying the device provided by the embodiment of the invention, the electronic equipment can obtain the color image to be processed. The color image may then be converted to a grayscale image. Then, the first pixel value of each pixel in the gray image may be converted into a second pixel value, the second pixel value being within a preset range. Then, for each pixel block in the gray image, the second pixel value of each pixel in the pixel block may be added to the corresponding value in the preset matrix. Thus, the third pixel value of each pixel in the grayscale image can be obtained. Wherein the size of each pixel block is the same as the size of the preset matrix, and each value in the preset matrix is not completely the same. Then, the third pixel value greater than or equal to the preset decision threshold may be reset to 1, and the third pixel value less than the decision threshold may be reset to 0, so that the color image may be converted into a binary image.
Wherein, since the size of the pixel block is the same as the size of the preset matrix, the gray image can be divided into a plurality of pixel blocks according to the size of the preset matrix. In addition, since the values in the preset matrix are not identical, after adding the second pixel value of each pixel in each pixel block to the value of the corresponding position in the preset matrix to obtain the third pixel, comparing the third pixel value with the decision threshold value and resetting the third pixel value, both the 1 value and the 0 value appear in the pixel block. Moreover, when the number of 0 values in the pixel block is large, the human eyes can see that the pixel block is dark; when the number of 1 values in the pixel block is large, the human eye can see the light color of the pixel block. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
Optionally, in an embodiment of the present invention, the second conversion module 503 may specifically be configured to:
dividing a first pixel value of each pixel in the gray image by 255 to obtain a second pixel value corresponding to each first pixel value; wherein the preset range includes [0,1].
Optionally, in an embodiment of the present invention, the preset matrix may include:
optionally, in an embodiment of the present invention, the third obtaining module 505 may specifically be configured to:
resetting the third pixel value which is more than or equal to 1, and resetting the third pixel value which is less than 1 to 0 to obtain a binary image corresponding to the color image.
Alternatively, in an embodiment of the present invention, the first conversion module 502 may include:
a first conversion unit for converting the color image into a BMP image in an image file format;
and a second converting unit for converting the BMP image into a gray scale image.
Corresponding to the above-described method embodiments, the present invention also provides an electronic device, see fig. 6, which includes a processor 601, a communication interface 602, a memory 603, and a communication bus 604, where the processor 601, the communication interface 602, and the memory 603 perform communication with each other through the communication bus 604,
a memory 603 for storing a computer program;
the processor 601 is configured to implement the method steps of any one of the binary image generating methods described above when executing the program stored in the memory 603.
In the embodiment of the invention, the electronic equipment can obtain the color image to be processed. The color image may then be converted to a grayscale image. Then, the first pixel value of each pixel in the gray image may be converted into a second pixel value, the second pixel value being within a preset range. Then, for each pixel block in the gray image, the second pixel value of each pixel in the pixel block may be added to the corresponding value in the preset matrix. Thus, the third pixel value of each pixel in the grayscale image can be obtained. Wherein the size of each pixel block is the same as the size of the preset matrix, and each value in the preset matrix is not completely the same. Then, the third pixel value greater than or equal to the preset decision threshold may be reset to 1, and the third pixel value less than the decision threshold may be reset to 0, so that the color image may be converted into a binary image.
Wherein, since the size of the pixel block is the same as the size of the preset matrix, the gray image can be divided into a plurality of pixel blocks according to the size of the preset matrix. In addition, since the values in the preset matrix are not identical, after adding the second pixel value of each pixel in each pixel block to the value of the corresponding position in the preset matrix to obtain the third pixel, comparing the third pixel value with the decision threshold value and resetting the third pixel value, both the 1 value and the 0 value appear in the pixel block. Moreover, when the number of 0 values in the pixel block is large, the human eyes can see that the pixel block is dark; when the number of 1 values in the pixel block is large, the human eye can see the light color of the pixel block. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
Corresponding to the above method embodiments, the present invention further provides a readable storage medium, in which a computer program is stored, which when executed by a processor, implements the method steps of any of the binary image generating methods described above. Wherein the readable storage medium is a computer readable storage medium.
After the computer program stored in the readable storage medium provided by the embodiment of the invention is executed by the processor of the electronic device, the electronic device can obtain the color image to be processed. The color image may then be converted to a grayscale image. Then, the first pixel value of each pixel in the gray image may be converted into a second pixel value, the second pixel value being within a preset range. Then, for each pixel block in the gray image, the second pixel value of each pixel in the pixel block may be added to the corresponding value in the preset matrix. Thus, the third pixel value of each pixel in the grayscale image can be obtained. Wherein the size of each pixel block is the same as the size of the preset matrix, and each value in the preset matrix is not completely the same. Then, the third pixel value greater than or equal to the preset decision threshold may be reset to 1, and the third pixel value less than the decision threshold may be reset to 0, so that the color image may be converted into a binary image.
Wherein, since the size of the pixel block is the same as the size of the preset matrix, the gray image can be divided into a plurality of pixel blocks according to the size of the preset matrix. In addition, since the values in the preset matrix are not identical, after adding the second pixel value of each pixel in each pixel block to the value of the corresponding position in the preset matrix to obtain the third pixel, comparing the third pixel value with the decision threshold value and resetting the third pixel value, both the 1 value and the 0 value appear in the pixel block. Moreover, when the number of 0 values in the pixel block is large, the human eyes can see that the pixel block is dark; when the number of 1 values in the pixel block is large, the human eye can see the light color of the pixel block. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
Corresponding to the above method embodiments, the present invention also provides a computer program product, which when run on an electronic device, causes the electronic device to perform: the method steps of any binary image generation method.
The computer program product provided by the embodiment of the invention can be executed by the processor of the electronic equipment, so that the electronic equipment can obtain the color image to be processed. The color image may then be converted to a grayscale image. Then, the first pixel value of each pixel in the gray image may be converted into a second pixel value, the second pixel value being within a preset range. Then, for each pixel block in the gray image, the second pixel value of each pixel in the pixel block may be added to the corresponding value in the preset matrix. Thus, the third pixel value of each pixel in the grayscale image can be obtained. Wherein the size of each pixel block is the same as the size of the preset matrix, and each value in the preset matrix is not completely the same. Then, the third pixel value greater than or equal to the preset decision threshold may be reset to 1, and the third pixel value less than the decision threshold may be reset to 0, so that the color image may be converted into a binary image.
Wherein, since the size of the pixel block is the same as the size of the preset matrix, the gray image can be divided into a plurality of pixel blocks according to the size of the preset matrix. In addition, since the values in the preset matrix are not identical, after adding the second pixel value of each pixel in each pixel block to the value of the corresponding position in the preset matrix to obtain the third pixel, comparing the third pixel value with the decision threshold value and resetting the third pixel value, both the 1 value and the 0 value appear in the pixel block. Moreover, when the number of 0 values in the pixel block is large, the human eyes can see that the pixel block is dark; when the number of 1 values in the pixel block is large, the human eye can see the light color of the pixel block. Therefore, the generated binary image can show the gray scale effect, and the visual experience of the user is improved.
The communication bus mentioned above for the electronic devices may be a peripheral component interconnect standard (PeripheralComponent Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processing, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for apparatus, electronic devices, and readable storage medium embodiments, the description is relatively simple as it is substantially similar to method embodiments, with reference to the section descriptions of method embodiments being merely pertinent.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims (10)
1. A binary image generation method, the method comprising:
obtaining a color image to be processed;
converting the color image into a gray scale image;
dividing a first pixel value of each pixel in the gray image by a preset value to obtain a second pixel value corresponding to each first pixel value; wherein each second pixel value is located in a preset range;
adding the second pixel value of each pixel of the pixel block in the gray image to the value of the corresponding position in the preset matrix to obtain a third pixel value of each pixel in the gray image; the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical;
resetting a third pixel value which is larger than or equal to a preset judgment threshold value to be 1, and resetting a third pixel value which is smaller than the judgment threshold value to be 0 to obtain a binary image corresponding to the color image;
wherein the preset matrix comprises:
2. the method according to claim 1, wherein the step of dividing the first pixel value of each pixel in the grayscale image by a preset value to obtain a second pixel value corresponding to each first pixel value includes:
dividing a first pixel value of each pixel in the gray image by 255 to obtain a second pixel value corresponding to each first pixel value; wherein the preset range includes [0,1].
3. The method according to claim 1, wherein the step of resetting a third pixel value greater than or equal to a preset decision threshold to 1 and resetting a third pixel value smaller than the decision threshold to 0, to obtain a binary image corresponding to the color image, includes:
resetting the third pixel value which is more than or equal to 1, and resetting the third pixel value which is less than 1 to 0 to obtain the binary image corresponding to the color image.
4. The method of claim 1, wherein the step of converting the color image to a grayscale image comprises:
converting the color image into a BMP image in an image file format;
converting the BMP image into a gray scale image.
5. A binary image generating device, the device comprising:
the first obtaining module is used for obtaining a color image to be processed by a user;
a first conversion module for converting the color image into a gray scale image;
the second conversion module is used for dividing the first pixel value of each pixel in the gray image by a preset value to obtain a second pixel value corresponding to each first pixel value; wherein each second pixel value is located in a preset range;
the second obtaining module is used for adding the second pixel value of each pixel of the pixel block in the gray image with the value of the corresponding position in the preset matrix to obtain a third pixel value of each pixel in the gray image; the size of each pixel block is the same as the size of the preset matrix; the values in the preset matrix are not identical;
the third obtaining module is used for resetting a third pixel value which is larger than or equal to a preset judgment threshold value to be 1, and resetting a third pixel value which is smaller than the judgment threshold value to be 0, so that a binary image corresponding to the color image is obtained;
wherein the preset matrix comprises:
6. the apparatus of claim 5, wherein the second conversion module is specifically configured to:
dividing a first pixel value of each pixel in the gray image by 255 to obtain a second pixel value corresponding to each first pixel value; wherein the preset range includes [0,1].
7. The apparatus of claim 5, wherein the third obtaining module is specifically configured to:
resetting the third pixel value which is more than or equal to 1, and resetting the third pixel value which is less than 1 to 0 to obtain the binary image corresponding to the color image.
8. The apparatus of claim 5, wherein the first conversion module comprises:
a first conversion unit for converting the color image into a BMP image in an image file format;
and a second converting unit for converting the BMP image into a gray scale image.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method of any one of claims 1-4 when executing a program stored on a memory.
10. A readable storage medium, characterized in that it has stored therein a computer program which, when executed by a processor of an electronic device, implements the method of any of claims 1-4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910004989.6A CN111402276B (en) | 2019-01-03 | 2019-01-03 | Binary image generation method and device, electronic equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910004989.6A CN111402276B (en) | 2019-01-03 | 2019-01-03 | Binary image generation method and device, electronic equipment and readable storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111402276A CN111402276A (en) | 2020-07-10 |
CN111402276B true CN111402276B (en) | 2023-12-26 |
Family
ID=71428312
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910004989.6A Active CN111402276B (en) | 2019-01-03 | 2019-01-03 | Binary image generation method and device, electronic equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111402276B (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5499305A (en) * | 1994-03-30 | 1996-03-12 | Lasermaster Corporation | Method and apparatus for coalescing a grayscale image and rendering the coalesced grayscale image as a binary image |
JP2007006269A (en) * | 2005-06-24 | 2007-01-11 | Seiko Epson Corp | Image processing apparatus for binarization process, and image processing program |
CN101232555A (en) * | 2007-01-23 | 2008-07-30 | 夏普株式会社 | Image processing method, and image processing apparatus |
CN103366170A (en) * | 2012-04-02 | 2013-10-23 | 鸿富锦精密工业(深圳)有限公司 | Image binarization processing device and method thereof |
CN106651860A (en) * | 2016-11-02 | 2017-05-10 | 帝麦克斯(苏州)医疗科技有限公司 | Image segmenting method and apparatus |
-
2019
- 2019-01-03 CN CN201910004989.6A patent/CN111402276B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5499305A (en) * | 1994-03-30 | 1996-03-12 | Lasermaster Corporation | Method and apparatus for coalescing a grayscale image and rendering the coalesced grayscale image as a binary image |
JP2007006269A (en) * | 2005-06-24 | 2007-01-11 | Seiko Epson Corp | Image processing apparatus for binarization process, and image processing program |
CN101232555A (en) * | 2007-01-23 | 2008-07-30 | 夏普株式会社 | Image processing method, and image processing apparatus |
CN103366170A (en) * | 2012-04-02 | 2013-10-23 | 鸿富锦精密工业(深圳)有限公司 | Image binarization processing device and method thereof |
CN106651860A (en) * | 2016-11-02 | 2017-05-10 | 帝麦克斯(苏州)医疗科技有限公司 | Image segmenting method and apparatus |
Non-Patent Citations (2)
Title |
---|
A multi-scale texture segmentation method;Jian-nong Cao et al.;2014 10th International Conference on Natural Computation (ICNC);第1-5页 * |
基于Hessenberg分解的彩色图像盲水印算法;韩绍程 等;计算机工程与设计;第38卷(第12期);第3354-3360页 * |
Also Published As
Publication number | Publication date |
---|---|
CN111402276A (en) | 2020-07-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11373275B2 (en) | Method for generating high-resolution picture, computer device, and storage medium | |
CN113168684B (en) | Method, system and computer readable medium for improving quality of low brightness images | |
CN112602088B (en) | Method, system and computer readable medium for improving quality of low light images | |
WO2020093782A1 (en) | Method, system, and computer-readable medium for improving quality of low-light images | |
US11991487B2 (en) | Method, system, and computer-readable medium for improving color quality of images | |
US11836898B2 (en) | Method and apparatus for generating image, and electronic device | |
US20210279509A1 (en) | Method and System For Processing Images Using Cross-Stage Skip Connections | |
WO2023173557A1 (en) | Image processing method and apparatus, and electronic device and storage medium | |
US20160381249A1 (en) | Image processing apparatus, control method of image processing apparatus, and storage medium | |
US11176404B2 (en) | Method and apparatus for detecting object in image, and storage medium thereof | |
US20210256667A1 (en) | Method and terminal for improving color quality of images | |
CN111145202B (en) | Model generation method, image processing method, device, equipment and storage medium | |
CN110545427A (en) | PDF document compression method and device and electronic equipment | |
WO2022002002A1 (en) | Image processing method, image processing apparatus, electronic device, and storage medium | |
JP2004334852A (en) | Image processing by pixel types | |
US8699792B2 (en) | Error diffusion processing circuit | |
CN113625923B (en) | Remote cloud desktop-based mouse processing method and device, storage medium and equipment | |
CN111402276B (en) | Binary image generation method and device, electronic equipment and readable storage medium | |
CN110378479B (en) | Image input method and device based on deep learning and terminal equipment | |
CN110807300A (en) | Image processing method and device, electronic equipment and medium | |
WO2022247702A1 (en) | Image processing method and apparatus, electronic device, and storage medium | |
CN111127310B (en) | Image processing method and device, electronic equipment and storage medium | |
CN109993694B (en) | Method and device for generating super-resolution image | |
CN113591832A (en) | Training method of image processing model, document image processing method and device | |
CN110930302B (en) | Picture processing method and device, electronic equipment and readable storage medium |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |