# Introduction mbigram is a typographical design that can be read in multiple orientations as shown in Fig. 1, where a word 'ambigram' is written in a rotationally symmetric manner. There are other types of ambigrams such as mirror, perceptual shift and 3D ambigrams [1]. Langdon [2], [3] has made a lot of interesting ambigrams for a long time. Those ambigramic artworks give pleasure to the viewers, and provide great inspiration for artists and engineers. Inspired by such successful ambigrams, in this paper we suggest an application of the idea of ambigram to an ambigramic interpretation of a bit sequence. In other words, we propose a method for describing two images with a bit sequence, which is a digital ambigram that can be seen as one of the two images if the bit sequence is read forward direction, or as another image if the bit sequence is read backward direction. The proposed ambigramic images are compared with the graphics interchange format (GIF) images [4], and the effectiveness of the proposed method is demonstrated in the experiments using natural images, where an image quality measure is used for evaluating the quality of halftone images including palette-based images such as GIF images. The rest of this paper is organized as follows: Section 2 describes the proposed algorithm for generating ambigramic bit sequences. Section 3 shows experimental results. Finally, Section 4 concludes this paper. # II. # Proposed Ambigramic Image Data Structure In this section, we propose a method for formatting image data into an ambigramic data structure, which is recorded in a binary file. Assume that two images are given as an input data as A = [a ij ] and B = [b ij ], where a ij and b ij denote color vectors at the pixel position (i; j) in the images A and B, respectively, for i = 1; 2; : : : ;m and j = 1; 2; : : : ; n, i.e., A and B are the same size. Then we attempt to store A and B in a storage as a single file. Figure 2 illustrates the situation, where A and B are represented by a bit sequence, and stored in some place of a storage. If we read the bit sequence from left to right, then we see the image A. On the other hand, if we read it from right to left, then we see the image B. The procedure for constructing such a bit sequence from A and B is described as follows. Abstract-We propose an image file format that can be read in two ways, where two images are recorded in a single file as a bit sequence, and the forward reading the bit sequence makes one of the two images visible, or the backward reading makes another image visible. Such a way of looking at a binary data in two ways resembles that of an ambigram, which is a piece of calligraphy that can be read in two ways by rotating it or introducing other perspectives. The proposed ambigramic image file format is compared with the graphics interchange format (GIF) experimentally, and the results show the better quality of the ambigramic images than that of GIF images. where the horizontally adjacent pixels are separated by semicolons. Next, we reverse the order of the bit sequence in (2) as follows: where note that the third subscripts (1:4) is also reversed as (4:1), e.g., ?? 1,1,4:1 ?? denotes ?? 1,1,4 ?? ?? 1,1,3 ?? ?? 1,1,2 ?? ?? 1,1,1 ?? . Then we combine ( 1) and ( 3) as follows: The proposed error diffusion algorithm is described as follows. For one image A, all pixels are processed in a standard raster scan order, and at the same time, for another image B, all pixels are processed in the inverse raster scan order. For the first pixel in image A, the original color vector a 1,1 changes to Where k and l denote relative indices to access the neighboring pixels, and w k,l denotes error diffusion coefficients or error filter [5]. On the other hand, for the last pixel in image B, the original color vector b m,n changes to Subtracting b ?m,n from b m,n , we define an error vector by which is diffused to unprocessed neighboring pixels as where note that the sign of the relative indices k and l is reversed except in w k,l because of the inverse raster scan. After the above error diffusion procedures in ( 7) and (10), we proceed to the next pixels a 1,2 and b m,n?1 , and the error diffusion procedures are repeated until the end of the scan. r A 1,1,1:4 , g A 1,1,1:4 , b A 1,1,1:4 ; r A 1,2,1:4 , g A 1,2,1:4 , b A 1,2,1:4 ; ? ? ? ? ? ? ; r A m,n,1:4 , g A m,n,1:4 , b A m,n,1:4 (1) r B 1,1,1:4 , g B 1,1,1:4 , b B 1,1,1:4 ; r B 1,2,1:4 , g B 1,2,1:4 , b B 1,2,1:4 ; ? ? ? ? ? ? ; r B m,n,1:4 , g B m,n,1:4 , b B m,n,1:4 (2) b B m,n,4:1 , g B m,n,4:1 , r B m,n,4:1 ; ? ? ? ? ? ? ; b B 1,2,4:1 , g B 1,2,4:1 , r B 1,2,4:1 ; b B 1,1,4:1 , g B 1,1,4:1 , r B 1,1,4:1 (3) (r A 1,1,1:4 |b B m,n,4:1 ) 2 ,(g A 1,1,1:4 |g B m,n,4:1 ) 2 , (b A 1,1,1:4 |r B m,n,4:1 ) 2 ; ? ? ? ; (r A m,n,1:4 |b B 1,1,4:1 ) 2 ,(g A m,n,1:4 |g B 1,1,4:1 ) 2 , (b A m,n,1:4 |r B 1,1,4:1 ) 2 (4) ã1,1 = ? ? (r A 1,1,1:4 |b B m,n,4:1 ) 2 (g A 1,1,1:4 |g B m,n,4:1 ) 2 (b A 1,1,1:4 |r B m,n,4:1 ) 2 ? ? . (5) e A 1,1 = a 1,1 ? ã1,1 ,(6)a 1+k,1+l a 1+k,1+l + w k,l e A 1,1 ,(7) bm,n = ? ? (r B m,n,1:4 |b A 1,1,4:1 ) 2 (g B m,n,1:4 |g A 1,1,4:1 ) 2 (b B m,n,1:4 |r A 1,1,4:1 ) 2 ? ? . (8) Algorithm 1 Constructing ambigramic bit sequence for i 1 to m do 6: i R m + 1 ? i 7: for j 1 to n do 8: j R n + 1 ? j 9: Round the elements of a ij and b i R ,j R to 8-bit integers 10: ãij ? ? (r A i,j,1:4 |b B i R ,j R ,4:1 ) 2 (g A i,j,1:4 |g B i R ,j R ,4:1 ) 2 (b A i,j,1:4 |r B i R ,j R ,4:1 ) 2 ? ? 11: bi R ,j R ? ? (r B i R ,j R ,1:4 |b A i,j,4:1 ) 2 (g B i R ,j R ,1:4 |g A i,j,4:1 ) 2 (b B i R ,j R ,1:4 |r A i,j,4:1 ) 2 ? ? 12: e A ij a ij ? ãij 13: e B i R ,j R b i R ,j R ? bi R ,j R 14: for (k, l) ? KL ij do 15: a i+k,j+l a i+k,j+l + w k,l e A i,j 16: b i R ?k,j R ?l b i R ?k,j R ?l + w k,l e B i R ,j Rb m?k,n?l b m?k,n?l + w k,l e B m,n ,(9) © 2021 Global Journals # Global Journal of Computer Science and Technology Volume XXI Issue I Version I # ( ) Year 2021 An Ambigramic Image File Format # F Our basic principle is to preserve more significant bits of the original image data in the resultant ambigramic image file. Following this principle, we first extract four MSBs from both A and B as follows: which can be viewed as an ambigramic bit sequence, because if we read the bit sequence in (4) from left to right then the four MSBs in every pixel show the image A, on the other hand, if we read it from right to left then the four LSBs in every pixel are inversely read to show the image B. However, the resultant images can be corrupted by the replacement of the original four LSBs with others. To alleviate such a quality deterioration in the images, we next propose an error diffusion algorithm for generating better bit sequence, which improves the visual quality of the images. Subtracting ã 1,1 from a 1,1 , we define an error vector by which is diffused to unprocessed neighboring pixels as ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? The proposed error diffusion procedure is summarized in Algorithm 1, where the function 'zeros_like' returns an array of zeros being the same III. # Experimental Results In this section, we demonstrate the performance of the proposed method for formatting image data into an ambigramic data structure. First, we show an example of the proposed ambigramic image data with two images selected from the standard image database SIDBA [6]. Figures 3(a 5(c) and (d) show the graphics interchange format (GIF) images, and the GIF format is widely used on the Web due to its wide support and portability [4]. Figures 5 (e) and (f) show the results of the proposed ambigramic method without error diffusion (ED), where a daruma (dharma) doll and a beckoning cat can be seen as well as the above GIF images. Figures 5(g) and (h) show the results with ED (Algorithm 1), where we used Floyd and Steinberg's error filter [7] for w k,l in ( 7) and (10) as shown in Fig. 6 where "#" denotes the current pixel being processed, and "-" denotes the past pixel, and the visual quality is improved compared with the former results (e) and (f). The GIF images are palette-based ones each of which has a palette table of 256 colors. That is, the GIF images are a sort of halftone images [5] as well as the proposed ambigramic images. To evaluate the quality of those images objectively and quantitatively, we present a parameter-free measure based on integral image [8]. -# w 0,1 = First, we compute the integral images of both reference (original) R and test (format-converted) T images, which are denoted as = [ ] and =[ ], respectively. Then we compute the signal-to-noise ratio (SNR) [9] of the integral images and as follows: ISNR(R, T ) = SNR R, T(11) = 10 log 10 m i=1 n j=1 r2 ij m i=1 n j=1 (r ij ? tij ) 2 . (12) format for both images, which demonstrates the effectiveness of the proposed algorithm. Additionally, we examine the applicability of the proposed algorithm to natural images shown in Fig. 8, where Fig. 8(a) shows five pairs of natural images where the top row shows the first images A, and the second row shows the corresponding second ones B. Figures 8(b), (c) and (d) show the corresponding formatconverted images by GIF, the proposed ambigramic method without ED and Algorithm 1. Although, in Fig. 8(c), we can see false contours, they are removed in Fig. 8(d). The ISNR values for those images in Fig. 8 are summarized in Table 1, where the proposed Algorithm 1 achieves higher values than the GIF images and ambigramic images without ED. # Conclusions In this paper, we proposed an algorithm for formatting an ambigramic image file into which two images of the same size are recorded. If we read it forward direction, then we see the first image, on the other hand, if we read it backward direction, then we see the second one. We compared the proposed ambigramic image file format with the GIF format which has acquired a widespread use on the Web, and demonstrated that the proposed ambigramic images achieved higher quality than the GIF images based on an image quality measure. Experimental results showed that the proposed algorithm is also applicable to natural images. An Ambigramic Image File Format # F We call this measure the integral image-based SNR (ISNR). For the format-converted images in Fig. 5, their ISNRs are plotted in Fig. 7, where the vertical and horizontal axes denote the ISNR value and image name, respectively, and green, yellow and orange bars denote the file formats, GIF, ambigramic format without ED and the final ambigramic format by Algorithm 1, respectively. Algorithm 1 achieves higher ISNR values than GIF 1![Figure 1: Example of ambigram](image-2.png "Figure 1 :") 2![Figure 2: Illustration of an ambigramic bit sequence](image-3.png "Figure 2 :") 1![procedure AMBIGRAMIC(A, B) 2: à zeros like(A) where A = [a ij ] 3: B zeros like(B) where B = [b ij ]](image-4.png "1 :") ![20: return à = [ã ij ] and/or B = [ bi,j ] 21: end procedure e B m,n = b m,n ? bm,n ,](image-5.png "") ![) and (b) show the two standard images from SIDBA. Assume that Figs. 3(a) and (b) are images A and B, ambigramic images à = [ã ij ] and B = [b ?ij ]as shown in Figs.3(c) and(d), which can be saved as an ambigramic bit sequence, the forward reading of which shows Fig.3(c), and the backford reading shows Fig.3(d). For example, the RGB values at the top left pixel of Fig.3(c) and at the bottom right pixel of Fig.3(d) are shown in Fig. 4, where the top left and the bottom right pixels ã 11 and mn have the RGB values (232; 130; 116) and (46; 65; 23), which are also expressed as binary numbers. If we reverse the order of the bit sequences of RGB values in ã ij , then we have the bit sequences of BGR values in b ?mn , and vice versa.](image-6.png "") 3![Figure 3: Original images (a) and (b) converted into ambigramic data (c) and (d)](image-7.png "Figure 3 :") 4![Figure 4: Comparison of pixel values Figures 5(a) and (b) show two original images each of which has 640 480 pixels, and the following figures show the format-converted images from the original ones (a) and (b). Figures5(c) and(d) show the graphics interchange format (GIF) images, and the GIF format is widely used on the Web due to its wide support and portability[4]. Figures5 (e) and (f)show the results of the proposed ambigramic method without error diffusion (ED), where a daruma (dharma) doll and a beckoning cat can be seen as well as the above GIF images. Figures5(g) and (h) show the results with ED (Algorithm 1), where we used Floyd and Steinberg's error filter[7] for w k,l in (7) and (10) as shown in Fig.6where "#" denotes the current pixel being processed, and "-" denotes the past pixel, and the visual quality is improved compared with the former results (e) and (f).](image-8.png "Figure 4 :") ![GIF image A (d) GIF image B size as the argument array, A.shape is a property to get the array dimensions of A, and KL ij denotes a set of the pair of the relative indices k and l satisfying 1 ? i + k ? m and 1 ? j + l ? n. (e) A ? without ED (f) B ? without ED (g) à by Alg. 1 (h) B ? by Alg. 1](image-9.png "F") 5![Figure 5: Examples of file format conversion](image-10.png "Figure 5 :") 6![Figure 6: Error diffusion coefficients by Floyd-Steinberg](image-11.png "Figure 6 :") 7![Figure 7: Integral image-based SNR (ISNR)](image-12.png "Figure 7 :") 1Pair 1 Pair 2 Pair 3 Pair 4 Pair 5GIF image A49.9749.3946.8048.41 50.13GIF image B46.5150.9646.2648.82 47.08A? without ED 38.0546.9733.5947.34 45.28B? without ED 34.8745.5635.4650.90 40.00A? by Alg. 173.9360.8182.4895.21 75.76B? by Alg. 163.6188.9253.0994.37 85.13IV. ## Acknowledgments This work was supported by JSPS KAKENHI Grant Number JP16H03019. * Ambigram -Wikipedia, the free encyclopedia Wikipedia Online; accessed 06-March-2020 * Ambigrams, logos, & word art JohnLangdon ac- cessed 07 1996. February-2019 * Wordplay: The Philosophy, Art, and Science of Ambigrams JLangdon 2005 Bantam * GIF -Wikipedia, the free encyclopedia Wikipedia Online; accessed 06-March-2020 * LDaniel GonzaloRLau Arce Modern Digital Halftoning Boca Ra-ton, FL, USA CRC Press, Inc 2007 Second Edition * Man-agement of the standard image database for image pro-cessing researches (sidba) MSakauchi YOhsawa MSone MOnoe ITEJ Technical Report 8 38 1984 * An Adaptive Al-gorithm for Spatial Greyscale RobertWFloyd LouisSteinberg Proceedings of the So-ciety for Information Display the So-ciety for Information Display 1976 17 * Robust real-time object detection PaulViola MichaelJones International Journal of Computer Vision 57 2 2002 * Signal-to-noise ratio -Wikipedia, the free encyclopedia Wikipedia 2020 Online; accessed 06-March-2020 * Original images (b) GIF images (c) Ambigramic images without ED * Ambigramic images by Algorithm 1