図1は,8×8画素の白黒の画像例である。この図に対して,白を0,黒を1として表すと,図2に示すように8ビットのビット列が8行あるディジタルデータとして,画像データを表現することができる。 文字データしか送れない通信で画像データを送ろうとする場合,画像データを文字データであるかのように変換して通信する必要がある。 また,文字データと比べてデータ量の大きい画像データを効率よく通信するために,データを圧縮して送るという工夫がなされる。図2のビット列を左上から順に見ていくと,0が10個続き,次に1が34個続き,その次に0が20個続いていることが分かる。この同じ値が続く個数のことをランレングスという。これを利用して画像データを圧縮する方法を考える。 次に示す画像データの表現方法は,画像データの情報量を圧縮することを目的とする変換である。図2に示す画像データは,何ビットで表現されるか。 〔画像データの表現方法〕 (1) 画像データをランレングスで表現し,それらの値を最大15の範囲で区切っていく。例えば,ランレングスが20の場合は,15と5の二つのランレングスに分ける。 (2) 白と黒のランレングスをそれぞれ4ビットの2進数で表し,常に“白と黒”の8ビットの組みとして表現する。例えば,白のランレングスが15と5というように続く場合は,その間にランレングス0(2進数では0000)の黒を補い,白のランレングス15と黒のランレングス0の組みを作る。このように,白又は黒が続く場合は間に黒又は白,黒で始まる場合は先頭に白,白で終わる場合は末尾に黒のランレングス0を補うことで,常に白と黒の8ビットの組みを作る。
平成24年度 秋期 ITパスポート試験 問94
This question's explanation and your answers so far.
問 94
※ Our check while writing this explanation could not fully confirm the published answer; scoring follows IPA's official key.
Incorrectア
12 bits corresponds to representing the three runs “white 10, black 34, white 20” with 4 bits each without dividing them or forming pairs, that is 3 x 4 = 12. It applies neither the division within a maximum of 15 in step (1) nor the “always an 8-bit pair of white and black” of step (2). Besides, 34 and 20 cannot be expressed in 4 bits (maximum 15) in the first place, so this way of counting itself breaks the stated rules.
Incorrectイ
24 bits is 3 x 8 = 24, obtained by counting the three runs “white 10, black 34, white 20” at 8 bits per run without dividing them. That is the answer to Question 95, which encodes the same Figure 2 with a different method, not the method of this question. Here step (1) divides values within a maximum of 15, so black 34 splits into 15, 15 and 4 and white 20 splits into 15 and 5; there are simply more than 3 runs.
- ウ
正解 Read the bit string in Figure 2 as one continuous sequence, from the top row down, left to right: 00000000 / 00111111 / 11111111 / 11111111 / 11111111 / 11110000 / 00000000 / 00000000 Counting 0 as white and 1 as black: - there are ten 0s (the 8 bits of row 1 + the first 2 bits of row 2) - there are thirty-four 1s (the remaining 6 bits of row 2 + the 24 bits of rows 3 to 5 + the first 4 bits of row 6) - there are twenty 0s (the remaining 4 bits of row 6 + the 16 bits of rows 7 and 8) and 10 + 34 + 20 = 64 pixels = 8 x 8, which matches. So the run lengths are “white 10 -> black 34 -> white 20”. Step (1): Divide the values within a maximum range of 15. White 10 stays as it is, black 34 splits into 15 + 15 + 4, and white 20 splits into 15 + 5, giving white 10 / black 15 / black 15 / black 4 / white 15 / white 5 which is 6 run lengths. Step (2): Turn these into 8-bit pairs that are always “white and black”. The sequence starts with white, so no white 0 is needed at the front. Pair 1: white 10, black 15 ... this is a white-then-black order, so it forms one pair as it is Pair 2: white 0, black 15 ... black continues, so a white run length of 0 is inserted between them Pair 3: white 0, black 4 ... black continues again, so a white 0 is inserted Pair 4: white 15, black 0 ... white continues, so a black run length of 0 is inserted between them Pair 5: white 5, black 0 ... it ends with white, so a black run length of 0 is added at the end That makes 5 pairs. One pair is 8 bits (4 bits for white + 4 bits for black), so 5 pairs x 8 bits = 40 bits Therefore the correct answer is ウ, 40. The actual bit string is 10101111 00001111 00000100 11110000 01010000 (white 10 = 1010, black 15 = 1111, white 0 = 0000, black 4 = 0100, white 15 = 1111, black 0 = 0000), which is indeed 40 bits. The original 64 bits have shrunk to 40 bits, and that is exactly what makes this method a compression.
Incorrectエ
48 bits comes from treating each of the 6 run lengths obtained after the division in step (1) (white 10 / black 15 / black 15 / black 4 / white 15 / white 5) as an independent pair and mechanically counting 6 x 8 = 48. But step (2) inserts a run length of 0 as padding only in three cases: when the same color continues (a 0 of the opposite color goes between them), when the sequence begins with black (a white 0 goes at the front), and when it ends with white (a black 0 goes at the end). Where the color switches naturally from white to black, no padding is needed. In this question the leading white 10 and black 15 are exactly such a white-then-black order, so those two combine into one pair. Because of that one pair, the number of pairs is 5 rather than 6, and the answer is 40 rather than 48.
- Run-length encoding is a lossless compression that groups the length over which the same value continues and expresses it as “color and count”. The starting point is to turn the image data into a sequence of white and black runs (here: white 10 -> black 34 -> white 20), and reading that correctly off the figure is what decides the question.
- This kind of rule-based question is not about memorization: apply the given procedure mechanically, in order. (1) Divide within a maximum of 15 and fix the number of runs. (2) From the constraint of “always a pair of white and black”, insert run lengths of 0 as padding when a color continues, when it begins with black, or when it ends with white, and count the pairs. Finally compute pairs x 8 bits.