Skip to content

平成24年度 秋期 ITパスポート試験 問95

This question's explanation and your answers so far.

問95
頻出度★☆☆

図1は,8×8画素の白黒の画像例である。この図に対して,白を0,黒を1として表すと,図2に示すように8ビットのビット列が8行あるディジタルデータとして,画像データを表現することができる。 文字データしか送れない通信で画像データを送ろうとする場合,画像データを文字データであるかのように変換して通信する必要がある。 また,文字データと比べてデータ量の大きい画像データを効率よく通信するために,データを圧縮して送るという工夫がなされる。図2のビット列を左上から順に見ていくと,0が10個続き,次に1が34個続き,その次に0が20個続いていることが分かる。この同じ値が続く個数のことをランレングスという。これを利用して画像データを圧縮する方法を考える。 次に示す画像データの表現方法は,画像データの情報量を圧縮することを目的とする変換である。図2に示す画像データは,何ビットで表現されるか。 〔画像データの表現方法〕 (1) 画像データをランレングスで表現し,それらの値を最大128の範囲で区切る。例えば,ランレングスが200の場合は,128と72の二つのランレングスに分ける。 (2) (1)で表現したそれぞれの値から1を引き,2進数7ビットで表現する。各7ビットに対して,白の場合は0を,黒の場合は1を,それぞれの色情報として先頭ビットに補って各8ビットで表現する。

出典 平成24年度 秋期 ITパスポート試験 問95
解説

問 95

※ Our check while writing this explanation could not fully confirm the published answer; scoring follows IPA's official key.

  • Incorrectア

    7 bits is only the length of the numeric part of a single run length. Step (2) specifies that one bit of color information is added in front of the 7-bit number so that each is expressed in 8 bits, so even one run alone needs 8 bits — and Figure 2 has three runs in the first place. This value confuses the unit amount (one run) with the total amount (the whole image data).

  • Incorrectイ

    8 bits is the code length for one run length. As the make-up of a single run — 1 bit of color information plus 7 bits for the number — it is correct, but what the question asks is the number of bits needed to represent the whole image data in Figure 2. Figure 2 has three runs, white 10, black 34, and white 20, so three times that is needed.

  • Incorrectウ

    21 bits is 3 × 7. Counting three run lengths is correct, but it misses the one bit of color information that is added in front of each run. Step (2) clearly states: add color information to the leading bit — 0 for white and 1 for black — thus representing each as 8 bits. So one run is 8 bits, not 7 bits, and this answer is 3 bits short.

  • エ

    正解 Reading the bit string in Figure 2 from the upper left, white (0) runs for 10 pixels, then black (1) for 34 pixels, then white (0) for 20 pixels. In other words there are three run lengths: white 10 → black 34 → white 20 (10 + 34 + 20 = 64 pixels = 8×8). Step (1): split the run-length values into ranges with a maximum of 128. Since 10, 34, and 20 are all 128 or less, no splitting happens, and there are still three run lengths. Step (2): subtract 1 from each value and express it as a 7-bit binary number, then add one bit of color information at the front (0 for white, 1 for black) to make 8 bits. - White 10 → 10 − 1 = 9 → 0001001 in 7 bits → add 0 for white at the front → 00001001 - Black 34 → 34 − 1 = 33 → 0100001 in 7 bits → add 1 for black at the front → 10100001 - White 20 → 20 − 1 = 19 → 0010011 in 7 bits → add 0 for white at the front → 00010011 There are three run lengths and 8 bits for each, so 3 × 8 = 24 bits. Therefore the correct answer is エ. The original image data was 64 bits, so it has been compressed down to 24 bits (compression ratio 24 ÷ 64 = 37.5%). Incidentally, the reason for subtracting 1 is that a run length is always at least 1 and at most 128, while 7 bits can express only 0 to 127. Shifting 1–128 down to 0–127 makes a run of up to 128 fit in 7 bits.

ここがポイント
  • Run-length encoding is a lossless compression method that encodes how many times the same value repeats in a row. The starting point is to reread the image data as a sequence of color plus repeat count; Figure 2 becomes three runs, white 10 → black 34 → white 20. The total number of bits is found as (number of runs) × (code length per run).
  • For an encoding rule, always check two things: the upper limit for splitting and the code length per run. Here the limit is 128, so 10, 34, and 20 are not split and there are still 3 runs; each run is 7 bits for the number plus 1 bit of color information = 8 bits. Hence 3 × 8 = 24 bits, and the original 64 bits are compressed to 37.5% (compression ratio = size after ÷ size before).
用語

Your answers