Skip to content

平成23年度 秋期 ITパスポート試験 問90

This question's explanation and your answers so far.

問90
頻出度★☆☆

文字や図形を白黒で縦 7 画素,横 7 画素のディジタル画像で表すとき,数字の“0”を図 1 のように表現する。このディジタル画像を画素データとして出力する処理,画素データを圧縮する処理及びディジタル画像を回転させる処理について考える。 図 1 数字の“0”のディジタル画像

1列2列3列4列5列6列7列
1行□□■■■□□
2行□■□□□■□
3行□■□□□■□
4行□■□□□■□
5行□■□□□■□
6行□■□□□■□
7行□□■■■□□

画素データを出力する処理の概要と圧縮する処理の概要は,次のとおりである。 〔画素データを出力する処理の概要〕 (1) 画素の色が白のときは“w”,黒のときは“b”を画素データとして出力する。 (2) 1 行 1 列,1 行 2 列,…,1 行 7 列,2 行 1 列,2 行 2 列,…,7 行 7 列の順番に各位置の画素データを出力する。 (3) 画素データを出力する際は,各画素データの間をコンマ“,”で区切る。 (4) 図 1 の画素データを出力した結果は次のとおりになり,文字数はコンマを含めて 97 文字になる。 w,w,b,b,b,w,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,w,b,b,b,w,w 〔画素データを圧縮する処理の概要〕 (1) 同じ色の画素データが連続する場合,“w”又は“b”の後に連続する画素の数をつなげて出力する。例えば,“b,b,b”は“b3”になる。 (2) 図 1 の画素データを圧縮した結果の出力は次のとおりになり,文字数はコンマを含めて 64 文字になる。 w2,b3,w3,b,w3,b,w2,b,w3,b,w2,b,w3,b,w2,b,w3,b,w2,b,w3,b,w3,b3,w2 図2で示すディジタル画像の画素データを圧縮した結果の文字数は,コンマを含めて何文字か。

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

問 90

  • Incorrectア

    34 is the value you get if you overlook the single black pixel at row 1 column 4 — the top end of the vertical bar — and read the whole of row 1 as white. Read that way, the leading run merges into 9 white pixels and the compressed result becomes w9,b2,w6,b,w6,b,w6,b,w6,b,w5,b3,w2, which is 13 runs, that is 22 characters plus 12 commas = 34 characters. In the actual Figure 2, row 1 column 4 is black too, so the beginning splits into w3 and b and the count does not come to 34.

  • イ

    正解 The compression rule is run-length encoding: a stretch of the same color is collapsed into “a letter for the color (w for white, b for black) + the number of consecutive pixels”, and the pieces of data are separated by commas. When the run length is 1, no number is written — just b or w (this is exactly how the compression example w2,b3,w3,b,… in Figure 1 of question set A is written). The scanning order is row 1 column 1 → row 1 column 7 → row 2 column 1 → … → row 7 column 7 as one continuous sequence, so the key point is that even when the row changes, a color that keeps going is still merged into a single run. In the 7×7 pixels of Figure 2, row 1 is □□□■□□□, row 2 is □□■■□□□, rows 3 to 6 are □□□■□□□, and row 7 is □□■■■□□. Laying these out in order from the top left and merging them gives white 3, black 1, white 5 (the 3 pixels at the right of row 1 join the 2 pixels at the left of row 2), black 2, white 6, black 1, white 6, black 1, white 6, black 1, white 6, black 1, white 5, black 3, white 2, so the compressed result is w3,b,w5,b2,w6,b,w6,b,w6,b,w6,b,w5,b3,w2. The run lengths add up to 49, which matches the 7×7 pixels, so you can confirm that nothing was miscounted. As for the character count, the 10 tokens w3, w5, b2, w6, w6, w6, w6, w5, b3, w2 are 2 characters each, giving 20 characters, and the 5 stand-alone b tokens give 5 characters, for 25 characters in total. The separating commas come between the 15 runs, so there are 15−1=14 of them. Therefore 25+14=39 characters, and the correct answer is イ.

  • Incorrectウ

    42 is the value you get if you cut a run that continues across a row boundary at one place. For example, if the 3 white pixels at the end of row 1 and the 2 white pixels at the start of row 2 are not joined but split into two runs, w3 and w2, the number of runs increases by one, which adds 2 characters and 1 comma and gives 39+3=42 characters. The output order is one continuous sequence in which row 1 column 7 is immediately followed by row 2 column 1, so you must not cut it at a row boundary.

  • Incorrectエ

    44 is the value you get if you dutifully write b1 or w1 even for pixels whose run length is 1. Then all 15 runs are 2 characters each, giving 15×2=30 characters, and adding the 14 commas makes 44 characters. In the compression example in Figure 1 of question set A, an isolated black pixel is written as b, not b1, because the rule is to omit the number when the run length is 1, so the count does not come to 44.

ここがポイント
  • Run-length encoding is a lossless compression method that replaces a stretch of the same value with “the value + the number of repetitions”. The point of this question is whether you can correctly read off from the example in Figure 1 the local rule that no count is written when the run length is 1; overlooking it leads to 44 characters (エ).
  • The pixels are scanned from row 1 column 1 to the right, and when a row ends the scan moves to column 1 of the next row, forming one continuous sequence, so when the same color continues across a row boundary it is still merged into a single run. When counting characters, do not forget to add the separating commas (number of runs − 1), and check your work by confirming that the run lengths add up to the total of 49 pixels.
用語

Your answers