The present invention relates to image processing, and more particularly to color clustering for preprocessing images in machine learning applications.
Image processing can use ultra-low precision algorithms (i.e., reduced precision machine learning) to accelerate inference and training speed on low compute capability devices (e.g., edge devices). For reduced precision machine learning, target color channels are based on a reduced number of bits in images. Current techniques to reduce the precision of images include posterization/masking, K-Means clustering, and accelerated K-Means clustering.
In one embodiment, the present invention provides a computer system that includes a central processing unit (CPU), a memory coupled to the CPU, and one or more computer readable storage media coupled to the CPU. The one or more computer readable storage media collectively contain instructions that are executed by the CPU via the memory to implement a method of color clustering for preprocessing an image. The method includes the computer system determining an initial number of colors by adding an integer margin to K. K is an integer equal to a target number of colors that is less than a total number of colors in a source image. The initial number of colors is less than the total number of colors in the source image. The method further includes the computer system determining a number of bits per channel which is greater than the initial number of colors based on 2{circumflex over ( )}((a number of bits)*(a number of channels))>(K+the integer margin). The method further includes the computer system determining a cross-product on the values of pixels in the source image and the number of bits per channel. The method further includes the computer system rounding the cross-product to integer values. The method further includes the computer system left aligning the rounded cross-product on a specified number of bits. The left aligned rounded cross-product specifies a target image having a number of colors equal to the initial number of colors. The method further includes the computer system determining a count of remaining unique colors in the target image after the determining the cross-product and the left aligning. The method further includes the computer system determining that the count of the remaining unique colors is greater than K. The method further includes repeating the computer system identifying a least frequent color in the target image that has a least frequency among colors in the target image, the computer system determining distances between the least frequent color and other colors in the target image, the computer system determining a least distance among the distances, the least distance being between the least frequent color and a closest color among the other colors, the computer system generating a merged color by merging the least frequent color and the closest color, and the computer system reducing a count of the colors in the target image by replacing the least frequent color and the closest color with the merged color in the colors in the target image, until the count of the colors in the target image is equal to K and the target image is a final target image having K colors.
A computer program product and a method corresponding to the above-summarized computer system are also described and claimed herein.
Reduced precision machine learning applications require target color channels to be based on a reduced number of bits. Current approaches for reducing image precision are (i) computationally expensive and slow or (ii) lose an excessive amount of image quality and image information. The traditional K-Means clustering approach is a common unsupervised machine learning algorithm that creates clusters of pixels to reduce image precision, but the processing time (e.g., for processing video) is slow. Various known accelerated variations on the K-Means algorithm are still based on the discovery of K centroids and therefore spend a significant amount of time on the centroid-pixels distance computations. Other accelerated K-Means approaches enhance speed while sacrificing image quality. Compared to the traditional K-Means approach, simple quantization by integer division and variance quantization are faster, but result in lower quality images.
Embodiments of the present invention address the aforementioned unique challenges of reducing image precision (e.g., four or fewer bits per channel instead of eight bits) by providing an approach for color clustering for preprocessing an image that is fast while retaining a significant amount of image quality and image information. The approach provided by embodiments of the present invention includes applying a cross-product on images to reduce the number of colors and left aligning the result of the cross-product to compute color distance. In one embodiment, the image precision reduction provides a clustering of K colors in a target image by applying the aforementioned cross-product to initially reduce the number of colors in the source image to a number that exceeds K by a specified margin (e.g., a margin of K/2), followed by merging pixels in the target image that have a close color distance until the target image is left with exactly K different colors. As used herein, K is a positive integer. In one embodiment, the process of reducing image precision is one order of magnitude faster than the traditional K-Means approach, while preserving the quality of the image and image information, as indicated in a color histogram.
In one embodiment, the image precision reduction is performed for three channels (e.g., relative to RGB (red-green-blue) images having three channels). In other embodiments, image precision reduction is provided for images having more or less than three channels (e.g., infrared, ultraviolet, etc., as in some satellite images).
Color clustering system 104 receives a source image 114 and a target number of colors 116 for a target image 118 that is generated by color clustering system 104. The target number of colors 116 is also referred to herein as K (i.e., a positive integer less than the total number of colors in source image 114). In one embodiment, cross-product module 106 applies a cross-product on pixel values of source image 114 to generate a cross-product rounded to integer values, which reduces the number of colors from the number of colors in the source image 114 to a reduced, initial number of colors in an initial target image (i.e., reduce the number of colors to an integer count that exceeds K plus a specified margin (e.g., a margin of K/2), where the integer count exceeds K plus the margin by a small, predefined amount).
Left alignment module 108 left aligns the rounded cross-product resulting from cross-product module 106, which provides for a computation of color distances.
Map generation module 110 generates a flat map if the target number of colors 116 is small; i.e., a number less than a predefined threshold number (e.g., a number<4096). If the target number colors is not small, map generation module 110 generates a map with unique colors as an index, with a count of pixels per unique reduced color in target image 118.
Tree module 112 creates a tree whose initial nodes are specified by the colors in the initial target image indicated by the left aligned rounded cross-product provided by cross-product module 106 and left alignment module 108. In one embodiment, tree module 112 (i) determines the least frequent color in the target image 118, (ii) determines the closest color in target image 118 (i.e., the color that is closest in distance to the least frequent color), (iii) creates a merged color that merges the least frequent color and the closest color, and (iv) replaces in target image 118 the least frequent color and the closest color with the merged color. Tree module 112 repeats the aforementioned steps (i) through (iv) until target image 118 is left with K colors.
The functionality of the components shown in
In step 204, color clustering system 104 (see
In step 205, color clustering system 104 (see
2{circumflex over ( )}((number of bits)*(number of channels))>(K+predetermined margin)
In step 206, color clustering system 104 (see
In step 208, color clustering system 104 (see
In one embodiment, to accelerate computation time, color clustering system 104 (see
In step 210, color clustering system 104 (see
In one embodiment, step 210 includes left aligning on an 8 bits value to compute color distance.
For example, for 4 bits 191 round((b‘1011 111’)*15/255)<<4=>176 (b‘1011 000’)
As one example, the following code performs steps 206, 208, and 210.
max_colors_number_for_significant_bits=2**significant_bits−1
# Start with pixel color maximum value at 255 and compute cross product for
# significant_bits bit
for color in range (0,256):
val=(max_colors_number_for_significant_bits*color)/(255)
colors[significant_bits,color]=int(round(val)<(8−significant_bits))
Because the evaluation of the bits per channel count in step 205 may not lead to a left aligned rounded cross-product after step 210 that has a sufficient number of colors, steps 212, 214, and 216, as described below, are needed to ensure a sufficient number of colors.
In step 212, color clustering system 104 (see
In step 214, color clustering system 104 (see
In step 216, color clustering system 104 (see
Returning to step 214, if color clustering system 104 (see
Subsequent to step 214 and prior to step 218, color clustering system 104 (see
For example, the following code provides a color index for a flat map:
int colorindex=((cchannel[2]>>(8−significant))<<(2*significant))|((cchannel[1]>>(8−significant))<<(significant))|(cchannel[0]>>(8−significant))
For example, the following code provides the unique color index for a regular map:
int uniqueindex=cchannel[2]<<2*8+cchannel[1]<<1*8+cchannel[0]<<0*8
In one embodiment, to simplify the key access to the map, color clustering system 104 (see
For example, the three RGB channels are encoded on three bits and left aligned as:
rrr00000
ggg00000
bbb00000
In the three RGB channel example presented above, color clustering system 104 (see
Step 218 starts a loop of an iterative process within the process of
Subsequent to step 214 and prior to step 218, tree module 112 (see
In step 218, color clustering system 104 (see
In one embodiment, prior to step 218, tree module (see
In step 220, color clustering system 104 (see
In step 222, color clustering system 104 (see
In step 224, color clustering system 104 (see
In one or more embodiments, color clustering system 104 (see
In step 226, color clustering system 104 (see
In one embodiment, after the generation of the merged color in step 224 and the replacement of the least frequent color and closest color by the merged color in step 226, color clustering system 104 (see
In one embodiment, for the most populated cross-product cluster with fewer than K clusters, color clustering system 104 (see
In step 228, color clustering system 104 (see
If color clustering system 104 (see
Alternatively, after the Yes branch of step 228 is taken, color clustering system 104 (see
In one embodiment, color clustering system 104 (see
Tree module 112 (see
Tree module 112 (see
After one or more successive iterations of steps 218, 220, 222, 224, 226, and 228 in
Memory 404 includes a known computer readable storage medium, which is described below. In one embodiment, cache memory elements of memory 404 provide temporary storage of at least some program code (e.g., program code 414) in order to reduce the number of times code must be retrieved from bulk storage while instructions of the program code are executed. Moreover, similar to CPU 402, memory 404 may reside at a single physical location, including one or more types of data storage, or be distributed across a plurality of physical systems or a plurality of computer readable storage media in various forms. Further, memory 404 can include data distributed across, for example, a local area network (LAN) or a wide area network (WAN).
I/O interface 406 includes any system for exchanging information to or from an external source. I/O devices 410 include any known type of external device, including a display, keyboard, etc. Bus 408 provides a communication link between each of the components in computer 102, and may include any type of transmission link, including electrical, optical, wireless, etc.
I/O interface 406 also allows computer 102 to store information (e.g., data or program instructions such as program code 414) on and retrieve the information from computer data storage unit 412 or another computer data storage unit (not shown). Computer data storage unit 412 includes one or more known computer readable storage media, where a computer readable storage medium is described below. In one embodiment, computer data storage unit 412 is a non-volatile data storage device, such as, for example, a solid-state drive (SSD), a network-attached storage (NAS) array, a storage area network (SAN) array, a magnetic disk drive (i.e., hard disk drive), or an optical disc drive (e.g., a CD-ROM drive which receives a CD-ROM disk or a DVD drive which receives a DVD disc).
Memory 404 and/or storage unit 412 may store computer program code 414 that includes instructions that are executed by CPU 402 via memory 404 to color cluster for preprocessing an image. Although
Further, memory 404 may include an operating system (not shown) and may include other systems not shown in
As will be appreciated by one skilled in the art, in a first embodiment, the present invention may be a method; in a second embodiment, the present invention may be a system; and in a third embodiment, the present invention may be a computer program product.
Any of the components of an embodiment of the present invention can be deployed, managed, serviced, etc. by a service provider that offers to deploy or integrate computing infrastructure with respect to color clustering for preprocessing an image. Thus, an embodiment of the present invention discloses a process for supporting computer infrastructure, where the process includes providing at least one support service for at least one of integrating, hosting, maintaining and deploying computer-readable code (e.g., program code 414) in a computer system (e.g., computer 102) including one or more processors (e.g., CPU 402), wherein the processor(s) carry out instructions contained in the code causing the computer system to color cluster for preprocessing an image. Another embodiment discloses a process for supporting computer infrastructure, where the process includes integrating computer-readable program code into a computer system including a processor. The step of integrating includes storing the program code in a computer-readable storage device of the computer system through use of the processor. The program code, upon being executed by the processor, implements a method of color clustering for preprocessing an image.
While it is understood that program code 414 for color clustering for preprocessing an image may be deployed by manually loading directly in client, server and proxy computers (not shown) via loading a computer-readable storage medium (e.g., computer data storage unit 412), program code 414 may also be automatically or semi-automatically deployed into computer 102 by sending program code 414 to a central server or a group of central servers. Program code 414 is then downloaded into client computers (e.g., computer 102) that will execute program code 414. Alternatively, program code 414 is sent directly to the client computer via e-mail. Program code 414 is then either detached to a directory on the client computer or loaded into a directory on the client computer by a button on the e-mail that executes a program that detaches program code 414 into a directory. Another alternative is to send program code 414 directly to a directory on the client computer hard drive. In a case in which there are proxy servers, the process selects the proxy server code, determines on which computers to place the proxy servers' code, transmits the proxy server code, and then installs the proxy server code on the proxy computer. Program code 414 is transmitted to the proxy server and then it is stored on the proxy server.
Another embodiment of the invention provides a method that performs the process steps on a subscription, advertising and/or fee basis. That is, a service provider can offer to create, maintain, support, etc. a process of color clustering for preprocessing an image. In this case, the service provider can create, maintain, support, etc. a computer infrastructure that performs the process steps for one or more customers. In return, the service provider can receive payment from the customer(s) under a subscription and/or fee agreement, and/or the service provider can receive payment from the sale of advertising content to one or more third parties.
The present invention may be a system, a method, and/or a computer program product at any possible technical detail level of integration. The computer program product may include a computer readable storage medium (or media) (i.e., memory 404 and computer data storage unit 412) having computer readable program instructions 414 thereon for causing a processor (e.g., CPU 402) to carry out aspects of the present invention.
The computer readable storage medium can be a tangible device that can retain and store instructions (e.g., program code 414) for use by an instruction execution device (e.g., computer 102). The computer readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer readable storage medium includes the following: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire.
Computer readable program instructions (e.g., program code 414) described herein can be downloaded to respective computing/processing devices (e.g., computer 102) from a computer readable storage medium or to an external computer or external storage device (e.g., computer data storage unit 412) via a network (not shown), for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. A network adapter card (not shown) or network interface (not shown) in each computing/processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing/processing device.
Computer readable program instructions (e.g., program code 414) for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, configuration data for integrated circuitry, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++, or the like, and procedural programming languages, such as the “C” programming language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) may execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention.
Aspects of the present invention are described herein with reference to flowchart illustrations (e.g.,
These computer readable program instructions may be provided to a processor (e.g., CPU 402) of a general purpose computer, special purpose computer, or other programmable data processing apparatus (e.g., computer 102) to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium (e.g., computer data storage unit 412) that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions (e.g., program code 414) may also be loaded onto a computer (e.g. computer 102), other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the Figures. For example, two blocks shown in succession may, in fact, be accomplished as one step, executed concurrently, substantially concurrently, in a partially or wholly temporally overlapping manner, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.
While embodiments of the present invention have been described herein for purposes of illustration, many modifications and changes will become apparent to those skilled in the art. Accordingly, the appended claims are intended to encompass all such modifications and changes as fall within the true spirit and scope of this invention.