You are on page 1of 12
I Ching: A new matrix barcode Introduction The | Ching is a new matrix barcode for storing identification data. Inspired by the 64 hexagrams from the Chinese classic | Ching (The Book of Changes), it's a more elegant and versatile alternative to the QR code. Intended for anything from circuit boards to cryptocurrency wallet addresses, it allows users to stamp objects so that it's data is centralised and can be easily tracked, and to represent complex strings so that it can be shared efficiently with others. ‘Anew matrix barcode means the need for a custom | Ching code reader, enabled by a new encoder and decoder. The encoder involves taking a string of characters, and transforms it into an | Ching code hexagram. The decoder does the opposite, taking the | Ching code, and converting it into a string The goal of this decoder is to extract data from a barcode image as quickly and efficiently as possible. In order to do this, it's necessary to ensure quality conversion of the source image so that the | Ching barcode can be easily extracted from a wide variety of angles, and for each step of the conversion from input to output to take as little time as possible Open source optical character recognition (OCR) tools help with the decoding, by convert various kinds of images into machine-encoded text. Most of these take a machine learning approach by using neural network models to identify code use a machine learning approach. However, we decided to take a custom algorithmic approach. This paper presents a brief background of the | Ching, with a particular focus on how we approached building an encoder and decoder for the new matrix barcode. What is the I Ching (Book of Changes)? The design of the matrix barcode itself is derived from the hexagrams that are associated with the book, | Ching, The | Ching is said to have originated over 3,000 years ago, with roots in ancient practices of Divination. [1] Though frequently recognized as a tool to gain clarity, the origin and history of the book itself seem to be shrouded in mystery, with scholars offering multiple explanations for its evolution, origins, and meaning. Supposedly, it originated without a connection to a particular system of ideology. John Minford, a Western scholar in Chinese classics, writes that it is “the strangest and incomprehensible item in the Chinese canon, a text central to Confucian orthodoxy, and yet revered by Tavists and Buddhists; the “first of the Confucian Classics” and a pillar of state ideology, and yet at the same time as subtle and powerful vehicle for a wide range of heterodox ideas.” [2] What scholars can agree on, however, is that the | Ching is more than a book to be read ~ itis to be consulted, investigated, drawn up. — — —a — =o —=o— — =o = —_ — —— —=— — =o — — —— —— isn —The Creative Kun ~The Receptive Meng - Youthful Folly Indeed, one of the main ways to interact with the I Ching is to toss coins or yarrow sticks in order to draw hexagrams and imagine possibilities for answering a question. Each hexagram is a symbol of 6 horizontal, stacked lines. Each side of a coin corresponds to one of two states of the line, which can be unbroken or broken. Since there are 2 possible states for each line and 6 lines in the symbol, there are 64 possible forms that the hexagram can take. All 64 variations of the hexagrams have a distinct meaning, functioning as instruments that speak to typical situations. According to the Richard Wilhelm’s translation of the | Ching [3], some of the titles and meanings of the hexagrams include: Qian — The Creative K'un — The Receptive Chun — Difficult Beginnings Meng — Youthful Folly Hsu — Nourished While Waiting aRwnrna The Design of the I Ching For our matrix barcode, we drew directly upon these hexagrams, and created a range of grids, the smallest being 2 x 2 hexagrams, and the largest being 8 x 8 hexagrams. The size of the matrix barcode depends on 2 inputs: the level of error correction desired, and the length of the string Error correction Just like the QR code, the | Ching has 4 levels of error correction to restore data if the code is damaged. The higher the level, the better the error correction, and the larger the | Ching size. Specifications In terms of the design specifications, if we define the height of each line in a hexagram as a unit, the spacing between the black lines in the same symbol is one unit high. Therefore, each symbol is a square of 11x 11 units. The spacing between any 2 consecutive symbols is 3 units, vertically and horizontally. © ° Liner pattern Finder patterns Finder patterns, which are circles on the corners of the 8 x 8 hexagram grid, allow the decoder to recognise the | Ching matrix barcode and determine its orientation. Finder patterns have an 11-unit diameter, which is equal to a symbol's height/width. The way it works is that an algorithm goes through each row and analyses the number and order of white and black pixels it finds. A line passing through the centre of a finder pattern will pass through a black : white : black : white : black ratio of 1:1:3:1:1 Choosing an approach to build the encoder-decoder : ML vs. Algorithmic Most open source optical character recognition (OCR) tools, which convert various kinds of images to machine-encoded text, take a machine learning approach by using neural network models to identify code. We considered using these OCRs to train our own model to extract data from | Ching code. However, in order to train our model to produce accurate results, we discovered that we would need over 100,000 to 400,000 distinct images of the | Ching code. One way to address this need for large amounts of images would be to auto-generate the training data by taking a few images, and altering them programmatically by applying light, rotation, distortion and other mutations. However, we concluded that the risk of an over-fitted model that would not be able to detect images accurately was too large. An alternative to the machine learning approach was a custom algorithmic approach. The main benefits of this path were as follows: 1. Speed of Implementation The length of time to develop the custom algorithmic approach would only be affected by one variable: the time it would take for us to implement it. In contrast, to reach the same level of accuracy, the machine learning approach would have to factor in time to create or obtain data, and time to train the model. 2. Flexible — Accommodates future versions of the I Ching The algorithmic approach allows the | Ching code to be changed later to support more characters. While the | Ching code currently supports alphanumeric and special characters, future versions may include kanji characters. In contrast, a machine learning approach would require the machine learning model to be retrained to accommodate the expansion of characters. The end-to-end process of converting image to string The following steps explain how an image of the I Ching code can be decoded into a string, in order to extract the stored data. ee Tages Fogg epaemem Crashes aoa a ain ame Eng ‘sain inet 1. Converting color image to grayscale This process converts color images into shades of grey. 2. Binarization Binarization is the process of converting image from shades of grey to 2 ‘states — black or white. 3. Locating finder patterns Finder patterns, which are positioned on each comer of the | Ching code, are symbols that help identify the presence of the | Ching code, and detect its position and orientation. This allows the process of scanning the | Ching code to be omni-directional. 4, Locating alignment patterns These patterns allow the | Ching decoder to correct distortion, if the image is ona curved surface. The number of these patterns tends to vary depending on the size of the encoded string. 5, Homography transformation Homography transformation is a technique to rectify the perspective of the | Ching code image, by taking at least four points from the image. By identifying the relationship between those points, they can be transformed onto another plane. 6. Version number extraction This functions to recognize the version of the | Ching code so that future versions of the | Ching code can still be read, although they might have more alignment patterns or support a different set of characters 7. Raw data extraction This step involves detecting and reading the raw bit stream in the | Ching code. 8. Decoding and error correction This final step consists of converting the extracted raw data (in binary) to a human-readable string, and correcting any errors using the Reed-Solomon error correction scheme. Hees Original ‘Translation Euclidean Affine Homography Further Optimization While building the decoder with a custom algorithmic approach, our team had some fun trying to cut the run time of several steps in the process. This lead to some novel implementation techniques. Binarization Binarization is the process of converting grey scale images to black and white. This is done by choosing a threshold value, and setting all pixels darker than said threshold to black, and all lighter ones to white. The main difference between binarization methods is the strategy of choosing the threshold value. To choose the most appropriate one for us, we explored into the following strategies, in order: a. Global static thresholding The threshold is set to a fixed value, and is applied to the whole image. b. Global mean thresholding The threshold is set to the mean of the pixel values of the whole image, with a constant value added to it, and is applied to the whole image. c. Adaptive mean thresholding The threshold is calculated separately for each pixel, so that it changes dynamically across the image. The calculation is based on the mean pixel values in a fixed-size block around it, with a constant value added to it. jen fy fat ate We went with the third strategy - adaptive mean thresholding, as the localised threshold accounts for a range of lighting conditions in different areas of the image to produce better results. The usual main drawback of adaptive mean thresholding is that it requires more processing power, since the threshold value is recalculated for each pixel. While the running time of global static and global mean thresholding is affected by one factor — the image size, the running time of common implementations of adaptive mean thresholding is determined by the image size multiplied by the block size. This makes it costly, time-wise, to run adaptive mean thresholding on lower-end devices, especially since the running time becomes slower if the block size is increased. In our implementation, we managed to remove that extra time factor, with negligible effect on memory requirements. This was mainly achieved through the following: a. Pre-calculating and caching the cumulative sum of pixel values in a way that allows us to later get the sum of pixel values of any sub-rectangle in the image in constant time. b. Observing that the blocks surrounding any two neighboring pixels intersect in all pixels except in two rows/columns. By following a specific order of operations, we can make use of that intersection and eliminate repetitive and redundant calculations, while reducing memory requirements for the cumulative sum step. As a result, our running time is comparable to the faster global thresholding approaches. This frees us from having to compromise results for the sake of performance on lower-end devices, and gives us more flexibility in choosing the block size Though seemingly simple, binarization is a step that takes the majority of time in the entire decoding process. Therefore, for our novel binarization solution meant saving a significant amount of time in the decoding process. Raw data extraction We tested 3 main methods to extract data from distorted images of hexagrams. Firstly, we tried a static estimation approach by calculating the expected position of each | Ching hexagram and extracting the data from that estimated square. However, we found that if the pre-processing doesn't perfectly restore the original image perspective, this method would miss parts of each hexagram because the distorted vertical shifting might cut out parts of the hexagrams. Secondly, instead of cutting out each hexagram and decoding it one by one, we solved each column of hexagrams together to address the previous problem of missing parts of hexagrams. This method accommodated vertical shift. However, we found that some columns couldn't be readjusted back to their perfectly aligned positions. The third and most successful approach was by adjusting the second approach to include dynamic detection, and accounting for horizontal shift. Since the symbols ina given column might not be vertically aligned, the left and right boundaries of symbols are dynamically adjusted as scanning progresses from top to bottom A Final Note In ll, the above research and testing helped us strategize to efficiently perform every step of the decoding process. We are excited to see the I Ching code be adopted to store strings for all sorts of use cases, and serve as a tiny reminder to not just see the world through a scientific lens of quantifiable facts, but to also be open to the possibilities of the spiritual agencies that may give meaning to a situation. Sources [1] Minford, John, translator. | Ching, The Essential Translation of the Ancient Chinese Oracle and Book of Wisdom. Penguin Classics Deluxe Edition ed., Penguin Classics, 2015. [2] Ibid. page 16. [3] Wilhelm, Richard, and Cary F. Baynes, translators. The / Ching, or, Book of Changes. 3rd ed., Princeton University Press, 1967.

You might also like