Image gray scale processing-based printing method and device, and electronic device
Patent Information
- Application Number
- CN202310523728.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-10
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2043-05-10
AI Technical Summary
[0002]热敏打印机通过加热热敏纸使加热区域的热敏纸呈现黑色,以此实现黑白两色的打印效果,目前热敏打印机只有在对固定灰阶数量的打印数据进行打印时,才可取得良好的打印效果,例如:支持16灰阶的热敏打印机,只有在打印16灰阶的打印数据时,打印效果才好,而在打印8灰阶打印数据时,打印效果便会大打折扣
[0081]根据本公开的第五方面,提供了一种计算机程序产品,包括计算机程序,所述计算机程序在被处理器执行时实现如前述第一方面所述的方法。
Smart Images

Figure CN116540957B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing technology, and in particular to a printing method and apparatus, and electronic equipment based on image grayscale processing. Background Technology
[0002] Thermal printers achieve a black and white printing effect by heating thermal paper to make the heated area appear black. Currently, thermal printers only achieve good printing results when printing data with a fixed number of gray levels. For example, a thermal printer supporting 16 gray levels only produces good print results when printing data with 16 gray levels; the print quality drops significantly when printing data with 8 gray levels. Therefore, providing a printing method, apparatus, and electronic device based on image grayscale processing to improve the printing quality of thermal printers for different numbers of gray levels is an urgent problem to be solved. Summary of the Invention
[0003] This disclosure provides a printing method, apparatus, and electronic device based on image grayscale processing. Its main objective is to provide a printing method, apparatus, and electronic device based on image grayscale processing to improve the printing effect of the thermal printer on printing data with different numbers of grayscale levels.
[0004] According to a first aspect of this disclosure, a printing method based on image grayscale processing is provided, comprising:
[0005] The target image is clustered based on a preset clustering algorithm to obtain the first gray value of the target gray level, wherein the target gray level is the order used to print the target image;
[0006] An index array is constructed based on the first grayscale value and the second grayscale value. The second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the number of preset grayscale levels. The index array is used to index the second grayscale value, and the preset grayscale level is the number of grayscale printing levels supported by the printing device.
[0007] The target image is reduced in size to obtain an index map, which points to the target index position of the index array;
[0008] The second grayscale value is indexed according to the target index position, and then printed according to the indexed second grayscale value.
[0009] Optionally, the step of clustering the target image based on a preset clustering algorithm to obtain the first grayscale value of the target grayscale includes:
[0010] Determine the size of the target grayscale and the preset grayscale;
[0011] If the target gray level is determined to be smaller than the preset gray level, the target image is clustered based on the preset clustering algorithm to obtain the first gray value of the target gray level.
[0012] Optionally, constructing an index array based on the first grayscale value and the second grayscale value includes:
[0013] Construct a first array based on the first grayscale value of the target grayscale;
[0014] Construct a second array based on the second grayscale value of the preset grayscale;
[0015] Starting from the first gray value at the first position in the first array, calculate the difference between the first gray value and each second gray value in the second array in turn;
[0016] Determine the target position of the second grayscale value corresponding to the minimum difference in the second array;
[0017] The target position is used as the first element of the index array until all the first grayscale values in the first array have been traversed.
[0018] Optionally, the step of reducing the order of the target image to obtain the index map includes:
[0019] The first preset number of bits of the grayscale value byte data to be reduced in the target image corresponding to the pixel are set as the target index value. The first preset number of bits are determined according to the target grayscale. The target index value points to the target index position.
[0020] Set the remaining number of bits in the grayscale value byte data to be downgraded as the error value;
[0021] The error value is distributed to the grayscale value to be reduced in each direction corresponding to the pixel around the pixel according to a preset ratio. The index map is obtained by reducing the order of each pixel in the target image.
[0022] Optionally, after performing a reduction-order process on the target image to obtain an index map, the method further includes:
[0023] The index graph is compressed;
[0024] The compressed index diagram and the index array are sent to the printing unit;
[0025] Decompress the compressed index map;
[0026] The second grayscale value is indexed according to the target index position pointed to by the index map after decompression, and then printed according to the indexed second grayscale value.
[0027] Optionally, printing based on the indexed second grayscale value includes:
[0028] The target index position is indexed by the target index value corresponding to each pixel in the index image, and the second gray value is indexed according to the target index position;
[0029] The second grayscale value obtained from the index is assigned to the corresponding pixel in the index image, and the index image after assignment is printed.
[0030] Optionally, the method includes:
[0031] When it is determined that the target gray level is greater than the preset gray level, the printing device is restricted from responding to the printing command;
[0032] When the target gray level is determined to be equal to the preset gray level, the target image can be clustered based on a preset clustering algorithm, depending on the requirements.
[0033] Optionally, before determining the size of the target grayscale and the preset grayscale, the method includes:
[0034] Convert the image to be detected into a grayscale image;
[0035] The grayscale image is scaled according to the printing size to obtain the target image;
[0036] Set the target grayscale corresponding to the target image.
[0037] Optionally, clustering the target image based on the preset clustering algorithm to obtain the first grayscale value of the target grayscale includes:
[0038] Perform histogram statistics on the target image to obtain the target histogram;
[0039] The target histogram is clustered based on a preset clustering algorithm to obtain the first gray value of the target gray level.
[0040] According to a second aspect of this disclosure, a printing apparatus based on image grayscale processing is provided, comprising:
[0041] A clustering unit is used to cluster the target image based on a preset clustering algorithm to obtain the first gray value of the target gray level, wherein the target gray level is the order used to print the target image;
[0042] A construction unit is configured to construct an index array based on the first grayscale value and the second grayscale value, wherein the second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the number of preset grayscale levels. The index array is used to index the second grayscale value, and the preset grayscale level is the number of grayscale printing levels supported by the printing device.
[0043] The processing unit is used to perform a reduction processing on the target image to obtain an index map, wherein the index map points to the target index position of the index array;
[0044] The printing unit is configured to index the second grayscale value according to the target index position and print according to the indexed second grayscale value.
[0045] Optionally, the clustering unit includes:
[0046] The judgment module is used to determine the size of the target gray level and the preset gray level;
[0047] The clustering module is used to cluster the target image based on the preset clustering algorithm when it is determined that the target gray level is less than the preset gray level, so as to obtain the first gray value of the target gray level.
[0048] Optionally, the building unit includes:
[0049] A construction module is used to construct a first array based on the first grayscale value of the target grayscale.
[0050] The construction module is also used to construct a second array based on the second grayscale value of the preset grayscale;
[0051] The calculation module is used to calculate the difference between the first gray value and each second gray value in the second array, starting from the first gray value at the first position in the first array.
[0052] The determination module is used to determine the target position of the second gray value corresponding to the minimum difference in the second array;
[0053] The traversal module is used to take the target position as the first element of the index array until all the first grayscale values in the first array have been traversed.
[0054] Optionally, the processing unit includes:
[0055] The setting module is used to set the first preset number of bits of the grayscale value byte data to be reduced in order of pixels in the target image as the target index value. The first preset number of bits are determined according to the target grayscale. The target index value points to the target index position.
[0056] The setting module is also used to set the remaining number of bits in the grayscale value byte data to be downgraded as an error value;
[0057] The allocation module is used to allocate the error value to the grayscale value to be reduced in each direction corresponding to the pixel around the pixel according to a preset ratio, and to obtain the index map by reducing the order of each pixel in the target image.
[0058] Optionally, the device further includes:
[0059] A compression unit is used to compress the index map;
[0060] A sending unit is configured to send the compressed index diagram and the index array to the printing unit;
[0061] A decompression unit is used to decompress the compressed index map;
[0062] The printing unit is also used to index the second grayscale value according to the target index position pointed to by the decompressed index map, and to print according to the indexed second grayscale value.
[0063] Optionally, the printing unit includes:
[0064] An indexing module is used to index the target index position using the target index value corresponding to each pixel in the index image, and to index the second grayscale value according to the target index position;
[0065] The printing module is used to assign the second grayscale value obtained by indexing to the corresponding pixel in the index image, and to print the index image after assignment.
[0066] Optionally, the device includes:
[0067] A limiting unit is used to limit the printing device from responding to a printing command when it is determined that the target grayscale is greater than the preset grayscale.
[0068] The selection unit is used to select whether to cluster the target image based on a preset clustering algorithm when it is determined that the target gray level is equal to the preset gray level.
[0069] Optionally, the device includes:
[0070] A conversion unit is used to convert the image to be detected into a grayscale image;
[0071] A scaling unit is used to scale the grayscale image according to the printing size to obtain the target image;
[0072] A setting unit is used to set the target grayscale corresponding to the target image.
[0073] Optionally, the clustering module is further configured to:
[0074] Perform histogram statistics on the target image to obtain the target histogram;
[0075] The target histogram is clustered based on a preset clustering algorithm to obtain the first gray value of the target gray level.
[0076] According to a third aspect of this disclosure, an electronic device is provided, comprising:
[0077] At least one processor; and
[0078] A memory communicatively connected to the at least one processor; wherein,
[0079] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect above.
[0080] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are configured to cause the computer to perform the method described in the first aspect above.
[0081] According to a fifth aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method described in the first aspect above.
[0082] The printing method, apparatus, and electronic device based on image grayscale processing disclosed herein include: clustering a target image based on a preset clustering algorithm to obtain a first grayscale value of the target grayscale, wherein the target grayscale is the order used for printing the target image; constructing an index array based on the first grayscale value and a second grayscale value, wherein the second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the order of the preset grayscale, wherein the index array is used to index the second grayscale value, and the preset grayscale is the grayscale printing order supported by the printing device; performing order reduction processing on the target image to obtain an index map, wherein the index map points to a target index position in the index array; indexing the second grayscale value according to the target index position, and printing according to the indexed second grayscale value. Compared with related technologies, this method improves the printing effect for different gray levels by clustering the target image to obtain the first gray value of the target gray level, constructing an index array using the first gray value and the second gray value, thereby obtaining the second gray value supported by the printing device corresponding to the first gray value of the target gray level, reducing the gray level of the target image to obtain an index map, wherein the index map points to the target index position of the index array, indexing the second gray value according to the target index position using the index array, and printing the target image based on the second gray value. By changing the target gray level when clustering the target image, the first gray value of different target gray levels can be obtained, and a corresponding index array can be constructed based on the first gray value and the second gray value of different target gray levels. The second gray value corresponding to the index map after the target image is reduced in gray level is then indexed based on the corresponding index array for printing, thereby improving the printing effect for different gray levels.
[0083] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description
[0084] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0085] Figure 1 This is a schematic flowchart of a printing method based on image grayscale processing provided in an embodiment of the present disclosure;
[0086] Figure 2 This is a schematic diagram of the structure of a printing apparatus based on image grayscale processing provided in an embodiment of the present disclosure;
[0087] Figure 3 A schematic diagram of another printing apparatus based on image grayscale processing provided in this disclosure embodiment;
[0088] Figure 4 A schematic block diagram of an example electronic device 300 provided for embodiments of this disclosure. Detailed Implementation
[0089] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0090] The following description, with reference to the accompanying drawings, describes a printing method, apparatus, and electronic device based on image grayscale processing according to embodiments of the present disclosure.
[0091] Figure 1 This is a schematic flowchart of a printing method based on image grayscale processing provided in an embodiment of the present disclosure.
[0092] like Figure 1 As shown, the method includes the following steps:
[0093] Step 101: Cluster the target image based on a preset clustering algorithm to obtain the first gray value of the target gray level, wherein the target gray level is the order used to print the target image.
[0094] As a refinement of step 101 above, in order to obtain the first grayscale value of the target grayscale, the grayscale values included in the target image are clustered based on the preset clustering algorithm to obtain the first grayscale value of the target grayscale. The target grayscale is the order used to print the target image. The target grayscale can be set according to the order of the target image to be printed. The preset clustering algorithm can be, but is not limited to, the mean algorithm. For example, when printing a target image with 8 target grayscales, eight first grayscale values are obtained by clustering the grayscale values included in the target image. The above description is merely illustrative, and this disclosure does not limit the number of grayscales to be printed, i.e., it does not limit the target grayscale to 8.
[0095] Step 102: Construct an index array based on the first grayscale value and the second grayscale value. The second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the number of preset grayscale levels. The index array is used to index the second grayscale value, and the preset grayscale level is the number of grayscale printing levels supported by the printing device.
[0096] As a refinement of step 102 above, in order to enable the selection of grayscale values supported by the color wheel when the printing device performs different numbers of grayscale printing, the index array is constructed based on the difference relationship between the first grayscale value obtained by clustering and the second grayscale value supported by the printing device.
[0097] To more clearly illustrate the process of the above embodiments, it is necessary to understand that after clustering the target image to obtain eight first grayscale values for printing the target image of eight target grayscale levels, since the second grayscale values of the preset grayscale supported by the printing device are not completely the same as the first grayscale values, it is necessary to determine eight second grayscale values corresponding to the eight first grayscale values from the second grayscale values of the preset grayscale based on the difference between the first grayscale values and the second grayscale values. This enables the selection of the second grayscale values supported by the color wheel of the printing device when printing the target image of eight target grayscale levels, thereby realizing the printing of the target image of eight target grayscale levels using the printing device. The above description is only an illustrative example and does not constitute a limitation of this disclosure. Furthermore, by clustering the target image to obtain the first grayscale values and selecting the corresponding second grayscale values based on the first grayscale values, the effect of printing the target image of target grayscale levels using the second grayscale values is better.
[0098] Step 103: Perform a reduction-order processing on the target image to obtain an index map, which points to the target index position of the index array.
[0099] As a refinement of step 103 above, in order to adapt the target image to the printing of the target grayscale, the target image needs to be downgraded, that is, the grayscale corresponding to the target image is reduced to the target grayscale. After downgrading, the index map is obtained. The index map points to the target index position in the index array. The target index position is the position corresponding to each element stored in the index array.
[0100] Step 104: Index the second grayscale value according to the target index position, and print according to the indexed second grayscale value.
[0101] As a refinement of step 104 above, the target index position points to the second gray value, the second gray value is indexed through the target index position, and the target gray level is printed according to the indexed second gray value.
[0102] The printing method based on image grayscale processing disclosed herein includes: clustering a target image using a preset clustering algorithm to obtain a first grayscale value of the target grayscale, wherein the target grayscale is the order used for printing the target image; constructing an index array based on the first grayscale value and a second grayscale value, wherein the second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the order of the preset grayscale, wherein the index array is used to index the second grayscale value, and the preset grayscale is the grayscale printing order supported by the printing device; performing order reduction processing on the target image to obtain an index map, wherein the index map points to a target index position in the index array; indexing the second grayscale value according to the target index position, and printing according to the indexed second grayscale value. Compared with related technologies, this method improves the printing effect for different gray levels by clustering the target image to obtain the first gray value of the target gray level, constructing an index array using the first gray value and the second gray value, thereby obtaining the second gray value supported by the printing device corresponding to the first gray value of the target gray level, reducing the gray level of the target image to obtain an index map, wherein the index map points to the target index position of the index array, indexing the second gray value according to the target index position using the index array, and printing the target image based on the second gray value. By changing the target gray level when clustering the target image, the first gray value of different target gray levels can be obtained, and a corresponding index array can be constructed based on the first gray value and the second gray value of different target gray levels. The second gray value corresponding to the index map after the target image is reduced in gray level is then indexed based on the corresponding index array for printing, thereby improving the printing effect for different gray levels.
[0103] As a refinement of the embodiments of this disclosure, when performing step 101 to cluster the target image based on a preset clustering algorithm to obtain the first gray value of the target gray level, the following implementation methods may be adopted, but are not limited to: determining the size of the target gray level and the preset gray level; when it is determined that the target gray level is smaller than the preset gray level, clustering the target image based on the preset clustering algorithm to obtain the first gray value of the target gray level.
[0104] Since the selected target grayscale is limited by the preset grayscale supported by the printing device when printing the target image at the target grayscale, it is necessary to compare the target grayscale with the preset grayscale to determine the size of the target grayscale. If the target grayscale is determined to be smaller than the preset grayscale, it indicates that the printing device can achieve printing at the target grayscale. Then, the target image is clustered based on the preset clustering algorithm to obtain the first grayscale value of the target grayscale.
[0105] As a refinement of the above embodiments, when constructing the index array based on the first grayscale value and the second grayscale value in step 102, the following implementation methods can be adopted, but are not limited to: constructing a first array based on the first grayscale value of the target grayscale; constructing a second array based on the second grayscale value of the preset grayscale; starting from the first grayscale value at the first position in the first array, sequentially calculating the difference between the first grayscale value and each second grayscale value in the second array; determining the target position of the second grayscale value corresponding to the minimum difference in the second array; using the target position as the first element of the index array, until all the first grayscale values in the first array have been traversed.
[0106] As a refinement of the above embodiments, the construction of a first array based on the first grayscale value of the target grayscale and the construction of a second array based on the second grayscale value of the preset grayscale mean that the first grayscale value of the target grayscale is constructed as an array, and the second grayscale value of the preset grayscale is constructed as an array. For example, the first array can be represented as array1[m] = {0, 16, 32, 48, 64, 82, 98...255}; the second array can be represented as array2[n] = {2, 13, 41,...250}, where array1 is the first array, m represents the target grayscale, and the first grayscale value of the target grayscale is enclosed in curly braces; array2 is the first array, n represents the preset grayscale, and the second grayscale value of the preset grayscale is enclosed in curly braces. Then, the index array is obtained based on the constructed first array and second array. The specific steps are as follows:
[0107] The difference between the first grayscale value at index zero in the first array and each second grayscale value in the second array is calculated. The index of the second grayscale value with the smallest difference from the first grayscale value is then used as the element at index zero in the index array. This process is repeated, calculating the difference between each first grayscale value in the first array and each second grayscale value in the second array, and filling the index of the second grayscale value with the smallest difference into the corresponding index position in the index array to obtain the index array. An intermediate array is generated during the construction of the index array. The elements of the intermediate array are the differences between the first and second grayscale values. This intermediate array serves only as a transitional record for constructing the index array. The above-described index array process is merely exemplary and does not constitute a limitation of this disclosure.
[0108] As a refinement of the above embodiments, when performing step 103 to reduce the order of the target image and obtain the index map, the following implementation methods can be adopted, but are not limited to: setting the first preset number of bits of the grayscale value byte data corresponding to the pixel in the target image to be reduced to the target index value, wherein the first preset number of bits is determined according to the target grayscale, and the target index value points to the target index position; setting the remaining number of bits in the grayscale value byte data to be reduced to the error value; distributing the error value to the grayscale value to be reduced to the pixels in each direction around the pixel according to a preset ratio, thereby obtaining the index map by reducing the order of each pixel in the target image.
[0109] To clearly illustrate the process of reducing the order of the target image, this embodiment provides an exemplary description. For example, the gray value of a pixel in the target image of 256 order can be represented by one byte, and one byte occupies 8 bits. Therefore, the gray value 143 in binary representation is 10001111. When converting the target image of 256 order to the index image of 8 order, only 3 bits are needed from a binary perspective, i.e., 0-7. Therefore, the first 3 high bits 100 are converted to 00000100, which equals 4, representing the target index value. The last 5 low bits 01111 are converted to 00001111, which equals 15, and are allocated as the error value for error diffusion. When using error diffusion to distribute the error value, the method includes: accumulating the values in the right, lower left, lower, and lower right directions at ratios of 7 / 16, 3 / 16, 5 / 16, and 1 / 16 respectively, and then reducing the order of the entire image to obtain the index image. The above description is merely exemplary and does not constitute a limitation of this disclosure.
[0110] As a refinement of the above embodiments, the target image can be reduced in order using, but is not limited to, the following methods: One method is equal division reduction, where the image is divided into n equal parts, each part corresponding to an index value, where n is a variable parameter. Another method is the averaging method, which determines several regions of the target grayscale based on the first grayscale value of the obtained target grayscale, using the first grayscale value as the center, and sequentially sets the index value of each region to 0-m, where m is the target grayscale value minus one. The difference between the original grayscale value of a pixel in the target image and the corresponding first grayscale value is used as the error value.
[0111] As a refinement of the above embodiments, after the target image is downgraded to obtain an index map, the method may also adopt, but is not limited to, the following implementation methods: compressing the index map; sending the compressed index map and the index array to the printing unit; decompressing the compressed index map; indexing the second gray value according to the target index position pointed to by the decompressed index map, and printing according to the indexed second gray value.
[0112] To clearly illustrate the compression steps described above, this embodiment provides an exemplary description. For example, the index map data is compressed such that the target index values of levels 3-4 occupy 2 bits in 1 byte, levels 5-8 occupy 3 bits in 1 byte, levels 9-16 occupy 4 bits, and so on. This merges multiple data into one byte, reducing the data volume. Depending on the actual printer hardware and transmission speed, further compression can be performed using methods such as Huffman compression to obtain the printed data. In actual implementation scenarios, printing speed, printer heating control, and hardware costs need to be considered. Therefore, the printer will not support more than 32 preset grayscale levels, and the data volume is limited to using 16 preset grayscale levels. Normal designs also use even-numbered levels, such as 4 or 8, to facilitate data calculation. At the same time, to enable the printer to quickly split the printed data, for example, level 8, which originally occupies 3 bits, will also be stored using 4 bits, that is, one byte stores the target index value of 2 pixels. After obtaining all the target index values, the index map is obtained. The second grayscale value is indexed according to the target index position pointed to by the index map, and the indexed second grayscale value is printed.
[0113] As a refinement of the above embodiments, when printing according to the indexed second grayscale value in step 104, the following implementation methods can be adopted, but are not limited to: indexing the target index position by the target index value corresponding to each pixel in the index image, and indexing the second grayscale value according to the target index position; assigning the indexed second grayscale value to the corresponding pixel in the index image, and printing the index image after assignment.
[0114] To explain the printing process more clearly, it is important to understand that the target index value points to the target index position in the index array, and the target index position points to the corresponding second grayscale value in the second array. That is, after indexing the index array through the index image, the preset grayscale value in the second array is indexed based on the index array, and finally the preset grayscale value is returned to the index image to complete the assignment of the index image. Then, the assigned index image is printed to obtain the printing result of the target grayscale.
[0115] As a refinement of the above embodiments, after determining the size of the preset grayscale and the target grayscale, the method may also adopt, but is not limited to, the following implementation methods: when it is determined that the target grayscale is greater than the preset grayscale, the printing device is restricted from responding to the printing command; when it is determined that the target grayscale is equal to the preset grayscale, the target image may be clustered based on a preset clustering algorithm as needed.
[0116] As a refinement of the above embodiments, when it is determined that the target grayscale is greater than the preset grayscale, it indicates that the printing device does not support printing the target grayscale, and therefore does not respond to the printing command; when it is determined that the target grayscale is equal to the preset grayscale, it indicates that the first grayscale value and the second grayscale value can correspond one-to-one, so it is possible not to cluster the target image; if it is necessary to make the first grayscale value and the second grayscale value more similar, then it is possible to choose to cluster the target image.
[0117] As a refinement of the above embodiments, before determining the size of the target grayscale and the preset grayscale, the method may also adopt, but is not limited to, the following implementation methods, for example: converting the image to be detected into a grayscale image; scaling the grayscale image according to the printing size to obtain the target image; and setting the target grayscale corresponding to the target image.
[0118] The image to be detected is the initial image to be printed. The image to be detected is converted to grayscale to obtain a grayscale image. Then, the grayscale image is scaled according to the printing size to obtain the target image. The printing size is a set printing size. At the same time, the target grayscale of the image to be printed is set.
[0119] As a refinement of the above embodiments, when performing clustering of the target image based on the preset clustering algorithm to obtain the first gray value of the target gray level, the following implementation methods can also be adopted, for example: performing data histogram statistics on the target image to obtain a target histogram; performing clustering of the target histogram based on the preset clustering algorithm to obtain the first gray value of the target gray level.
[0120] The distribution of gray values within the target image is statistically analyzed using the target histogram. Then, the gray values within the target histogram are clustered to obtain the first gray value.
[0121] In summary, this embodiment achieves the following effects:
[0122] 1. By changing the target grayscale when clustering the target image, the first grayscale value of different target grayscales can be obtained. Based on the first grayscale value and the second grayscale value of different target grayscales, a corresponding index array can be constructed. The second grayscale value corresponding to the index map after the target image is reduced in grayscale is indexed according to the corresponding index array and printed, thereby improving the printing effect of printing data of different grayscales.
[0123] 2. By using the mean clustering method, the representative values of continuous grayscale values in the target image can be obtained. Combined with the actual printable grayscale values, the effect of replacing the original image with values that are as close as possible can be achieved, so that the printing effect of the low grayscale image is similar to that of the high grayscale image.
[0124] Corresponding to the above-described printing method based on image grayscale processing, this invention also proposes a printing apparatus based on image grayscale processing. Since the apparatus embodiments of this invention correspond to the method embodiments described above, details not disclosed in the apparatus embodiments can be referred to in the method embodiments described above, and will not be repeated here.
[0125] Figure 2 This is a schematic diagram of the structure of a printing apparatus based on image grayscale processing provided in an embodiment of the present disclosure, as shown below. Figure 2 As shown, it includes:
[0126] Clustering unit 21 is used to cluster the target image based on a preset clustering algorithm to obtain the first gray value of the target gray level, wherein the target gray level is the order used to print the target image;
[0127] The construction unit 22 is used to construct an index array based on the first grayscale value and the second grayscale value, wherein the second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the number of preset grayscale levels. The index array is used to index the second grayscale value, and the preset grayscale level is the number of grayscale printing levels supported by the printing device.
[0128] Processing unit 23 is used to perform a reduction processing on the target image to obtain an index map, wherein the index map points to the target index position of the index array;
[0129] The printing unit 24 is used to index the second grayscale value according to the target index position, and to print according to the indexed second grayscale value.
[0130] The printing apparatus based on image grayscale processing disclosed herein clusters a target image using a preset clustering algorithm to obtain a first grayscale value of the target grayscale, wherein the target grayscale is the order used for printing the target image; an index array is constructed based on the first grayscale value and a second grayscale value, wherein the second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the order of the preset grayscale, the index array is used to index the second grayscale value, and the preset grayscale is the grayscale printing order supported by the printing device; the target image is subjected to order reduction processing to obtain an index map, the index map pointing to the target index position of the index array; the second grayscale value is indexed according to the target index position, and printing is performed according to the indexed second grayscale value. Compared with related technologies, this method improves the printing effect for different gray levels by clustering the target image to obtain the first gray value of the target gray level, constructing an index array using the first gray value and the second gray value, thereby obtaining the second gray value supported by the printing device corresponding to the first gray value of the target gray level, reducing the gray level of the target image to obtain an index map, wherein the index map points to the target index position of the index array, indexing the second gray value according to the target index position using the index array, and printing the target image based on the second gray value. By changing the target gray level when clustering the target image, the first gray value of different target gray levels can be obtained, and a corresponding index array can be constructed based on the first gray value and the second gray value of different target gray levels. The second gray value corresponding to the index map after the target image is reduced in gray level is then indexed based on the corresponding index array for printing, thereby improving the printing effect for different gray levels.
[0131] Figure 3 This is a schematic diagram of the structure of a printing apparatus based on image grayscale processing provided in an embodiment of this disclosure. Further, in one possible implementation of this embodiment, as follows... Figure 3 As shown, the clustering unit 21 includes:
[0132] The judgment module 211 is used to judge the size of the target gray level and the preset gray level;
[0133] Clustering module 212 is used to cluster the target image based on the preset clustering algorithm when it is determined that the target gray level is less than the preset gray level, so as to obtain the first gray value of the target gray level.
[0134] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the building unit 22 includes:
[0135] Construction module 221 is used to construct a first array based on the first gray value of the target gray level;
[0136] The construction module 221 is further configured to construct a second array based on the second grayscale value of the preset grayscale;
[0137] Calculation module 222 is used to calculate the difference between the first gray value and each second gray value in the second array, starting from the first gray value at the first position in the first array.
[0138] The determining module 223 is used to determine the target position of the second gray value corresponding to the minimum difference in the second array;
[0139] The traversal module 224 is used to take the target position as the first element of the index array until all the first gray values in the first array have been traversed.
[0140] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the processing unit 23 includes:
[0141] Setting module 231 is used to set the first preset number of bits of the grayscale value byte data to be reduced in the target image corresponding to the pixel as the target index value, wherein the first preset number of bits are determined according to the target grayscale, and the target index value points to the target index position.
[0142] The setting module 231 is also used to set the remaining number of bits in the grayscale value byte data to be downgraded as an error value;
[0143] The allocation module 232 is used to allocate the error value to the grayscale value to be reduced in each direction corresponding to the pixel around the pixel according to a preset ratio, and to obtain the index map by reducing the order of each pixel in the target image.
[0144] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the device further includes:
[0145] Compression unit 25 is used to compress the index map;
[0146] Sending unit 26 is used to send the compressed index map and the index array to the printing unit;
[0147] Decompression unit 27 is used to decompress the compressed index map;
[0148] The printing unit 24 is further configured to index the second grayscale value according to the target index position pointed to by the decompressed index map, and print according to the indexed second grayscale value.
[0149] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the printing unit 24 includes:
[0150] The indexing module 241 is used to index the target index position by the target index value corresponding to each pixel in the index image, and to index the second gray value according to the target index position;
[0151] The printing module 242 is used to assign the second grayscale value obtained by indexing to the corresponding pixel in the index map, and to print the index map after assignment.
[0152] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the device includes:
[0153] The limiting unit 28 is used to limit the printing device from responding to a printing command when it is determined that the target gray level is greater than the preset gray level;
[0154] Selection unit 29 is used to select whether to cluster the target image based on a preset clustering algorithm when it is determined that the target gray level is equal to the preset gray level.
[0155] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the device includes:
[0156] The conversion unit 2101 is used to convert the image to be detected into a grayscale image;
[0157] The scaling unit 2102 is used to scale the grayscale image according to the printing size to obtain the target image;
[0158] The setting unit 2103 is used to set the target grayscale corresponding to the target image.
[0159] Furthermore, in one possible implementation of this embodiment, such as Figure 3 As shown, the clustering module 212 is further used for:
[0160] Perform histogram statistics on the target image to obtain the target histogram;
[0161] The target histogram is clustered based on a preset clustering algorithm to obtain the first gray value of the target gray level.
[0162] It should be noted that the foregoing explanation of the method embodiments also applies to the apparatus of this embodiment, and the principle is the same, so it is not limited in this embodiment.
[0163] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0164] Figure 4 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0165] like Figure 4 As shown, device 300 includes a computing unit 301, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 302 or a computer program loaded from storage unit 308 into RAM (Random Access Memory) 303. RAM 303 can also store various programs and data required for the operation of device 300. The computing unit 301, ROM 302, and RAM 303 are interconnected via bus 304. I / O (Input / Output) interface 305 is also connected to bus 304.
[0166] Multiple components in device 300 are connected to I / O interface 305, including: input unit 306, such as keyboard, mouse, etc.; output unit 307, such as various types of monitors, speakers, etc.; storage unit 308, such as disk, optical disk, etc.; and communication unit 309, such as network card, modem, wireless transceiver, etc. Communication unit 309 allows device 300 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0167] The computing unit 301 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 301 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 301 performs the various methods and processes described above, such as the image grayscale processing-based printing method. For example, in some embodiments, the image grayscale processing-based printing method can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 308. In some embodiments, part or all of the computer program can be loaded and / or installed on device 300 via ROM 302 and / or communication unit 309. When the computer program is loaded into RAM 303 and executed by the computing unit 301, one or more steps of the methods described above can be performed. Alternatively, in other embodiments, the computing unit 301 may be configured to perform the aforementioned image grayscale processing-based printing method by any other suitable means (e.g., by means of firmware).
[0168] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System-on-Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0169] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0170] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0171] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0172] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include LANs (Local Area Networks), WANs (Wide Area Networks), the Internet, and blockchain networks.
[0173] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem, addressing the shortcomings of traditional physical hosts and VPS (Virtual Private Server, or simply "VPS") services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.
[0174] It's important to note that artificial intelligence (AI) is the study of enabling computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily include computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graph technologies.
[0175] It should be understood that the various forms of processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0176] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A printing method based on image grayscale processing, characterized in that, include: The target image is clustered based on a preset clustering algorithm to obtain the first gray value of the target gray level, wherein the target gray level is the order used to print the target image; An index array is constructed based on the first grayscale value and the second grayscale value. The second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the number of preset grayscale levels. The index array is used to index the second grayscale value, and the preset grayscale level is the number of grayscale printing levels supported by the printing device. The target image is subjected to a reduction processing to obtain an index map, which points to the target index position of the index array; the index map contains a target index value corresponding to each pixel, and each target index value is set based on the first preset number of bits of the grayscale value byte data of the corresponding pixel in the target image to be reduced, which is determined according to the target grayscale; The second grayscale value is indexed according to the target index position, and then printed according to the indexed second grayscale value; The construction of the index array based on the first grayscale value and the second grayscale value includes: Construct a first array based on the first grayscale value of the target grayscale; Construct a second array based on the second grayscale value of the preset grayscale; Starting from the first gray value at the first position in the first array, calculate the difference between the first gray value and each second gray value in the second array in turn; Determine the target position of the second grayscale value corresponding to the minimum difference in the second array; The target position is used as the first element of the index array until all the first grayscale values in the first array have been traversed.
2. The method according to claim 1, characterized in that, The step of clustering the target image based on a preset clustering algorithm to obtain the first grayscale value of the target grayscale includes: Determine the size of the target grayscale and the preset grayscale; If the target gray level is determined to be smaller than the preset gray level, the target image is clustered based on the preset clustering algorithm to obtain the first gray value of the target gray level.
3. The method according to claim 1, characterized in that, The process of reducing the order of the target image to obtain the index map includes: The first preset number of bits of the grayscale value byte data to be reduced in the target image corresponding to the pixel are set as the target index value. The first preset number of bits are determined according to the target grayscale. The target index value points to the target index position. Set the remaining number of bits in the grayscale value byte data to be downgraded as the error value; The error value is distributed to the grayscale value to be reduced in each direction corresponding to the pixel around the pixel according to a preset ratio. The index map is obtained by reducing the order of each pixel in the target image.
4. The method according to claim 1, characterized in that, After performing a reduction-order process on the target image to obtain an index map, the method further includes: The index graph is compressed; The compressed index diagram and the index array are sent to the printing unit; Decompress the compressed index map; The second grayscale value is indexed according to the target index position pointed to by the index map after decompression, and then printed according to the indexed second grayscale value.
5. The method according to any one of claims 1 or 4, characterized in that, The step of printing based on the indexed second grayscale value includes: The target index position is indexed by the target index value corresponding to each pixel in the index image, and the second gray value is indexed according to the target index position; The second grayscale value obtained from the index is assigned to the corresponding pixel in the index image, and the index image after assignment is printed.
6. The method according to claim 2, characterized in that, The method includes: When it is determined that the target gray level is greater than the preset gray level, the printing device is restricted from responding to the printing command; When the target gray level is determined to be equal to the preset gray level, the target image can be clustered based on a preset clustering algorithm, depending on the requirements.
7. The method according to claim 2, characterized in that, Before determining the size of the target grayscale and the preset grayscale, the method includes: Convert the image to be detected into a grayscale image; The grayscale image is scaled according to the printing size to obtain the target image; Set the target grayscale corresponding to the target image.
8. The method according to claim 2, characterized in that, Clustering the target image based on the preset clustering algorithm to obtain the first grayscale value of the target grayscale includes: Perform histogram statistics on the target image to obtain the target histogram; The target histogram is clustered based on a preset clustering algorithm to obtain the first gray value of the target gray level.
9. A printing apparatus based on image grayscale processing, characterized in that, include: A clustering unit is used to cluster the target image based on a preset clustering algorithm to obtain the first gray value of the target gray level, wherein the target gray level is the order used to print the target image; A construction unit is configured to construct an index array based on the first grayscale value and the second grayscale value, wherein the second grayscale value is a grayscale value supported by the printing device, and the number of the second grayscale values is consistent with the number of preset grayscale levels. The index array is used to index the second grayscale value, and the preset grayscale level is the number of grayscale printing levels supported by the printing device. A processing unit is configured to perform a reduction processing on the target image to obtain an index map, the index map pointing to the target index position of the index array; the index map contains a target index value corresponding to each pixel, and each target index value is set based on the first preset number of bits of the grayscale value byte data of the corresponding pixel in the target image to be reduced, the first preset number of bits being determined according to the target grayscale; A printing unit is configured to index the second grayscale value according to the target index position, and print according to the indexed second grayscale value; The construction of the index array based on the first grayscale value and the second grayscale value includes: Construct a first array based on the first grayscale value of the target grayscale; Construct a second array based on the second grayscale value of the preset grayscale; Starting from the first gray value at the first position in the first array, calculate the difference between the first gray value and each second gray value in the second array in turn; Determine the target position of the second grayscale value corresponding to the minimum difference in the second array; The target position is used as the first element of the index array until all the first grayscale values in the first array have been traversed.
10. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.
11. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-7.
12. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method according to any one of claims 1-7.
Citation Information
Patent Citations
Grayscale image processing method and device and printer
CN111901497A