漢字分析1～漢字をFFT～

漢字を定量的に分析する企画、第一記事。

第一回のこの記事では漢字を数値化するに当たって、頑健性を高めるために周波数成分に分解し、可読性が保たれる範囲で情報の圧縮を試みる。

# 結果

低周波成分が重要になる。

同じデータ量なら分解前の画像サイズが小さいほうが復元しやすい。

## 元画像の大きさ及び復元に要した情報量からの比較

元画像の大きさによる可読性の変化は小さいことがわかる。
128x128の外周1bitより生成した画像は32x32の外周2bitより生成した画像よりも視認性に劣るが、要する情報量は前者のほうが多く、すなわち、元画像は解像度の低いものを使うと良い。

* 32x32 外周1ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7d60814a-b440-2e77-f0d8-2e445b96616d.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/76322d86-ad5c-fa3a-8741-4eb536380907.png)
* 32x32 外周2ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/a8a348e2-18c0-8f5c-925f-1d2fea9044ef.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7a40e1d9-b59a-9bea-0ddf-33d438eea2fb.png)
* 32x32 外周3ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/156ed801-7eda-22e2-0c93-66c7add00953.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/52b45e9c-888c-61e6-d186-0708e23101f9.png)
* 64x64 外周1ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/cf85044f-86cd-f858-4b33-0de4c1220f26.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/9ab1ad68-a155-bf48-d051-51272d76c6ec.png) 
* 64x64 外周2ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/78b88b1e-2e02-288d-19f7-649b8affebfb.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/ec89057f-87b6-c603-6e48-db31b7f21603.png)
* 64x64 外周3ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/f60291b0-0e90-9dae-2408-da15929089d9.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/d107c9f5-e4cf-f9bd-a6c4-b84e8d44a1e8.png)
* 128x128 外周1ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/b92b0573-c85e-a673-06bf-1da565f792dd.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/b0c83210-1c34-e4b9-7e29-5a7c7ac51744.png)
* 128x128 外周2ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/44a2e00d-b24f-7625-0dbf-2a7c6f38b898.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/02a7b2fa-d12d-35f3-f898-ce4069225c09.png)
* 128x128 外周3ビットから復元
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/f3008cf5-027f-1c15-bf08-3edc9929f910.png) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/d67a2dbc-7f2e-3efc-0d9d-5233343f996a.png)
## 字による比較
以下はそれぞれ外周1ビットから復元した画像である。

再び元画像の大きさによる視認性の変化は僅かであることが窺える。

また、画数の多い漢字よりも、画の向き等による差異によって判別される字のほうが判別しがたい可能性が示唆された。

* 宇
![宇32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/89f8959f-a61d-4a81-e2c8-23076982f7c7.png) ![宇64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/222cf6b1-a1c0-d274-241d-d01c197b2789.png) ![宇128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/78ba29fd-c182-42f8-c0f2-e1d1e9d5bd56.png)
* 都
![都32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/66c48099-2fb6-556e-f23a-4aecbaefcd39.png) ![都64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/03349e06-0c7d-506e-5dd1-87875b9cce79.png) ![都128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/8ac4a136-20d5-9cb3-9b6d-8e74b27b2031.png)
* 宮
![宮32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/fa0899ee-48f6-0765-a271-0ae931bc006e.png) ![宮64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7c132499-d5a3-192a-e345-5133b5e5b21f.png) ![宮128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/169b14be-0864-f3ab-ff9f-972d120cd39a.png) 
* 大
![大32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/6f9dad60-42b9-d36b-ef8d-80613e3e62f0.png) ![大64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/f1ef5d0e-49ef-9e33-f57f-34be4d7f59e3.png) ![大128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/45e6c4a4-90c1-e1b4-e557-cf1226822348.png) 
 * 学
![学32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/5716f14c-fa17-494f-d6f4-1434ece7f5c0.png) ![学64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/b1fbf931-1b12-763a-3954-b185938efb3b.png) ![学128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/b3d84665-e61a-6cdf-78a3-bcfbc07ab76d.png) 
* 情
![情32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/be8c2229-8e4a-9ddb-caac-5817649b3287.png) ![情64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/58af2a69-462e-e9bf-f851-c34e2d7b045a.png) ![情128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/1da44afa-9afd-6d53-36aa-3ee6c615ad20.png) 
* 報
![報32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/a4e7db67-d459-ae18-52be-19c9bb2b79ef.png) ![報64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/e664e2f7-0796-9681-a807-c7f4070d0fec.png) ![報128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7978e5e8-3879-abe1-0fcb-3961ab97e622.png)
* 研
![研32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/65312e4c-e08e-2ddd-9fc0-96ba149784bd.png) ![研64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/f6e3be9b-08b7-6ef8-dde1-be4ceb2a23bb.png) ![研128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/f5464acb-7245-4673-7bd8-6c54cbdea3f0.png) 
* 究
![究32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/84817fde-1f19-1e94-1d4d-8cbaac7d015b.png) ![究64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/a4d22b8f-f58a-b411-5553-45028b98b809.png) ![究128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/faae387d-8ead-af1a-6e9d-2461414a9bb4.png) 
* 会
![会32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/ae4aac64-5ae7-c847-74ab-38b31d4d5d3c.png) ![会64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/889a4b1e-031f-e4e3-1cc1-2d12cf13a524.png) ![会128.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/149128cb-fced-5b09-7b6d-70f2f0c1d08f.png) 

## 情報量による比較
フーリエ変換によって得た値を数 *d* で割り、これを整数にキャストした後再び *d* を乗算することによって情報を削減した。なお、この画像は外周2bitから復元した。

左から順に *d* = 1, 4, 16, 64, 128, 256, 1024, 2048, 4096, 8192, 16384 である

この場合先程とは異なり、元の画像が大きい方が頑健性が向上する可能性が示唆された。しかし今回の実験ではフーリエ変換によって得た値を正規化していないので、画像の大きさによる変換後の値の変化が考慮されていないことに注意を要する。

![lost_r1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/bdaaf5ba-b475-a3db-91e3-3bdd84b95c32.png) ![lost_r4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/4db60447-e854-d58a-90b1-4a25c2cf150b.png) ![lost_r16.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/a7267dff-7d5e-f83c-8cfd-1423e0edcf7b.png) ![lost_r64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/cb07bedf-bda5-ca85-9f05-7bfb0b6e6ada.png) ![lost_r256.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/36591aae-524c-5c22-2ba8-75c6c88e59af.png) ![lost_r1024.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/74279391-a00d-647d-f793-da73a0c9bdc6.png) ![lost_r2048.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/adce99b5-2658-830f-4613-ef9f932d6293.png) ![lost_r4096.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/448f97ef-e80f-dbe4-4577-4b9c79a7ec45.png) ![lost_r8192.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/620ed34c-1f43-f175-ee76-ea01fa477a37.png) ![lost_r16384.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/4e6a78e8-7a63-c0fc-3cb7-f694f801e561.png) 
![lost_r1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/824047ea-5711-1be7-fea1-3f59b2426997.png) ![lost_r4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/406cc935-2af2-c4e6-d7a6-e2c8a147165d.png) ![lost_r16.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/4d000e15-79e9-d1b1-65dc-4e097d3c822c.png) ![lost_r64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/eda5e358-a240-4e5b-80c3-21c3b43efacd.png) ![lost_r256.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/55a3a24d-076f-aefa-feb2-b4ed33dad3d9.png) ![lost_r1024.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7638bcd3-1782-bce4-13c4-59f784a544df.png) ![lost_r2048.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/dfd81dcf-948d-a91f-23dc-5926f886f4e3.png) ![lost_r4096.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/9bf7ac56-6ce7-eed1-74d8-b33c168d3f0a.png) ![lost_r8192.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/022a7222-ca40-096d-0467-3b9d8308a902.png) ![lost_r16384.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/146e088e-a376-ae54-c536-c680ad2ff4bb.png)
![lost_r2048.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/8b129f0d-dc04-dab0-0f10-0d85d589cdce.png) ![lost_r4096.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/10a6cbfe-4c70-92ae-b93d-5575b8820955.png) ![lost_r8192.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/e128b068-5a4c-954a-9f1b-a214333b58ef.png) ![lost_r16384.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/dc90958c-1217-e458-4be3-d18e5bfa2f84.png) ![lost_r1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/1f90314c-c4f4-fcee-e1fa-39ab271f2e9e.png) ![lost_r4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/d346d898-3ce3-99f5-bf49-968ea13f2b8b.png) ![lost_r16.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/d7d34eec-03f6-1648-22fa-612dcdd8d9c6.png) ![lost_r64.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/fb9810a6-993d-eefc-cf71-d3398df17458.png) ![lost_r256.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/6addd59e-be79-98df-cc24-d93e11f554f1.png) ![lost_r1024.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/d480a711-acd0-f5f0-e1c4-0a5a25b82189.png) 

## フーリエ変換の軸に基づく比較

以上の実験では二次元フーリエ変換を用いてきたが、縦および横それぞれの列に対して一次元フーリエ変換を適用することも検討した。

一次元フーリエ変換を用いることで情報量が半減するが、横に走査する場合、一般的に横画の多い漢字において、可読性を著しく損なうため情報量の削減の手段としては不向きである。
一方縦に走査するフーリエ変換を用いた場合、可読性は辛うじて保たれているが、情報量の減少量に対して意味のある削減方法とは言えないだろう。

以下に128x128 外周3bitから復元したそれぞれの画像を示す。

![0宇.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/4c2054e6-93c2-d44a-553e-8394ec9c897a.png) ![1宇V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/e8394ba9-d1c7-3444-14ed-f8501b2be927.png) ![2宇H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7be5b440-ce08-314b-b1b9-c2d6971fb2bf.png) 
![3都.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/d2deb802-903e-654e-751c-90c94fcd97a9.png) ![4都V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/1ffb53c1-49e0-1ae0-b0a0-75ded5548247.png) ![5都H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7a2cac2d-3b42-346a-b28d-d21f904cb871.png) 
![6宮.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/b74c4225-fed7-8e8d-3ff4-716fdbd5a0c6.png) ![7宮V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/842d4930-3cf5-a133-be2c-f765b2b16073.png) ![8宮H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/147d261c-221f-91f3-b554-1daf49123314.png) 
![9大.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/7d4c7bd2-17d0-3290-cd9e-4f5e8e03e842.png) ![10大V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/63314e3c-052b-4acd-ccdb-94072527fc05.png) ![11大H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/ec3173c8-1d44-dd38-2924-bcf58b5bc1fd.png)
![12学.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/e8b5120a-8f85-4e18-4adb-5e63c3ef8ed3.png) ![13学V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/14185ba2-74e7-e5cd-aaf1-349fd42d4faa.png) ![14学H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/99e6d171-64b7-3270-0bed-77a4d35b78dd.png)
![15情.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/f7fed518-ea0b-b4f8-bac3-f060420f9ed7.png) ![16情V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/51c6d405-92d3-13e1-3183-4272fa07fbaa.png) ![17情H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/fedf23db-85d6-0058-ba26-79735498c169.png)
![18報.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/922ec213-f5f0-cb24-b187-a4040582edb7.png) ![19報V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/90eada48-dbcd-426c-90c0-dddebe9128cc.png) ![20報H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/ca5d5fff-4ebd-c5c5-9671-ecba36c705d5.png)
![21研.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/4525d378-447c-9217-ea05-d518902a0513.png) ![22研V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/62a54aed-6e4d-8efe-7714-24f43befe654.png) ![23研H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/4596d8b1-fac3-a769-e648-03be01e2e9cd.png)
![24究.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/ffc2491a-35ef-7021-0c9f-a57afcd84249.png) ![25究V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/16e709c6-a3d7-1914-6ede-c62e7938a70d.png) ![26究H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/54279298-9243-16f6-a34f-e648066880f4.png)
![27会.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/abac15e7-00ef-5195-9929-2ac26d348999.png) ![28会V.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/b4ed0b10-b0c1-472c-dafc-880fc3d42081.png) ![29会H.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3555292/281a2903-ecd2-8ec1-3b05-6f57e631a54b.png)

# 過程

以下のコードを適当に使用した。

```python
from PIL import Image, ImageDraw, ImageFont
import numpy as np

def getArray(size, char):
    ofs_y = 55.0 / 256
    font = ImageFont.truetype('Koruri-Bold.ttf', size)

    img = Image.new('L', (size, size), color='white')
    draw = ImageDraw.Draw(img)
    draw.text((0, -ofs_y * size), char, font=font, fill='black')

    return np.array(img)

def fXform(data, dir):
    shape = np.shape(data)
    r = np.empty(shape, np.complex128)
    if dir == "":
        return np.fft.fft2(data)
    elif dir == "H":
        for i in range(shape[0]):
            r[i,:] = np.fft.fft(data[i,:])
        return r
    elif dir == "V":
        for i in range(shape[1]):
            r[:,i] = np.fft.fft(data[:,i])
        return r

def fXform_inv(data, dir = ""):
    shape = np.shape(data)
    r = np.empty(shape, np.complex128)
    if dir == "":
        return np.fft.ifft2(data)
    elif dir == "H":
        for i in range(shape[0]):
            r[i,:] = np.fft.ifft(data[i,:])
        return r
    elif dir == "V":
        for i in range(shape[1]):
            r[:,i] = np.fft.ifft(data[:,i])
        return r    

def exportImage(data, name, coef = 1):
    shape = np.shape(data)
    r = np.zeros(shape, np.uint8)
    for stride in range(shape[0]):
        for bit in range(shape[1]):
            r[stride, bit] = np.uint8(min(255, coef * np.abs(data[stride, bit])))
    Image.fromarray(r).save(name + ".png")

def exportImage_double(data, name, coef = 1):
    shape = np.shape(data)
    r = np.empty((shape[0]* 2, shape[1]), np.uint8)
    ofs = shape[0]
    for stride in range(shape[0]):
        for bit in range(shape[1]):
            r[stride, bit] = np.uint8(min(255, coef * np.real(data[stride, bit])))
    for stride in range(shape[0]):
        for bit in range(shape[1]):
            r[stride + ofs, bit] = np.uint8(min(255, coef * np.imag(data[stride, bit])))
    Image.fromarray(r).save(name + ".png")

def clip(data, range):
    range_h = int(range / 2)
    shape = np.shape(data)
    mid_x = int(shape[0] / 2)
    mid_y = int(shape[1] / 2)
    data[:mid_x - range_h, :] = 0
    data[mid_x + range_h:, :] = 0
    data[:, :mid_y - range_h] = 0
    data[:, mid_y + range_h:] = 0

def fill(data, range):
    range_h = int(range / 2)
    shape = np.shape(data)
    mid_x = int(shape[0] / 2)
    mid_y = int(shape[1] / 2)
    data[mid_x - range_h : mid_x + range_h, mid_y - range_h : mid_y + range_h] = 0

def lose(data, denom):
    shape = np.shape(data)
    r = np.empty((shape[0], shape[1]), np.complex128)    
    for stride in range(shape[0]):
        for bit in range(shape[1]):
            d = data[stride, bit]
            r[stride, bit] = int(np.real(d) / denom) * denom + int(np.imag(d) / denom) * denom * 1j
    return r
```

```python
dir = ""

dt1 = getArray(32, "報")
dt2 = fXform(dt1, dir)
fill(dt2, 26)
exportImage(dt2, "dt2")
dt3 = fXform_inv(dt2, dir)
exportImage(dt3, "dt3", 0.5)
```

```python
dir = ""

for char in ["宇", "都", "宮", "大", "学", "情", "報", "研", "究", "会"]:
    dt = fXform(getArray(32, char), dir)
    fill(dt, 30)
    exportImage(fXform_inv(dt, dir), char + "32", 0.6)
    dt64 = fXform(getArray(64, char), dir)
    fill(dt64, 62)
    exportImage(fXform_inv(dt64, dir), char + "64", 0.6)
    dt128 = fXform(getArray(128, char), dir)
    fill(dt128, 126)
    exportImage(fXform_inv(dt128, dir), char + "128", 0.6)
```

```python
dir = ""

for denom in [1, 4, 16, 64, 256, 1024, 2048, 4096, 8192, 16384]:
    dt1 = getArray(128, "報")
    dt2 = fXform(dt1, dir)
    fill(dt2, 124)
    dt4 = lose(dt2, denom)
    exportImage_double(dt4, "lost_m" + str(denom), 0.005)
    dt3 = fXform_inv(dt4, dir)
    exportImage(dt3, "lost_r" + str(denom), 0.5)
```

```python
i = 0
for char in ["宇", "都", "宮", "大", "学", "情", "報", "研", "究", "会"]:
    for dir in ["", "V", "H"]:
        dt = fXform(getArray(128, char), dir)
        fill(dt, 122)
        exportImage(fXform_inv(dt, dir), str(i) + char + dir, 0.6)

        i += 1
```

# 考察

今後漢字を分析するに当たって、頑健性を高めるために周波数に分解したが、二次元フーリエ変換を用いて低画素数の漢字画像を変換し低周波数成分を得ることが、フーリエ変換を用いた圧縮として最も優れており、ひいては頑健性を高めると思われる。