Skip to content

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

This question's explanation and your answers so far.

問92
頻出度★☆☆

文字や図形を白黒で縦 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 図4の三つのディジタル画像をそれぞれ右に90度回転させたとき, 回転前の画素データを圧縮した結果の文字数から, 回転後の画素データを圧縮した結果の文字数を引いた値が大きい順に並べたものはどれか。ここで, 文字数にはコンマを含める。

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

問 92

  • Incorrectア

    This option puts them in the order Image ①, Image ②, Image ③, but the difference for Image ② is −17, the smallest of the three. When Image ② is rotated, its white band turns from running horizontally to extending vertically and the runs become fragmented, so the count increases from 76 characters to 93 characters. It therefore comes last, not second. The one in second place is Image ③, whose difference is 0.

  • イ

    正解 The compression rule is: line up the pixels in row order from row 1 column 1 through row 7 column 7, merge each block in which the same color continues (a run) into a single item written as “color + number of repetitions”, omit the number when the run length is 1, and separate the items with commas. The character count is therefore determined by how long the same color continues along the scanning direction (horizontally). Actually compressing each image gives the following. - Image ①: only the central column (column 4) forms a white band connected vertically, and horizontally the color changes at almost every pixel, so there are many runs: 93 characters. - Image ②: in rows 3 and 5, columns 2 to 6 are black in a row, and in row 4, columns 2 to 6 are white in a row, so long runs appear horizontally: 76 characters. - Image ③: rows 3 and 5 have three white pixels in a row and row 4 has five white pixels in a row, which falls in between: 84 characters. What matters here is that Image ① and Image ② are related to each other by a 90-degree rotation to the right, and that Image ③ keeps the same shape even after a 90-degree rotation to the right (it is rotationally symmetric). A pixel at row i, column j before rotation moves to row j, column (8-i) after rotation, so rotating actually turns Image ① into the shape of Image ②, Image ② into the shape of Image ①, and Image ③ into the shape of Image ③. Therefore “character count before rotation - character count after rotation” is: - Image ①: 93 - 76 = +17 - Image ②: 76 - 93 = −17 - Image ③: 84 - 84 = 0 Arranged in descending order, this gives Image ①, Image ③, Image ②. The correct answer is therefore “イ”.

  • Incorrectウ

    This option puts Image ② first, but the character count of Image ② increases after rotation (76 to 93), so its difference is negative and it can never come first. The one that comes first is Image ①, whose count drops sharply from 93 to 76 through the rotation.

  • Incorrectエ

    The order Image ②, Image ③, Image ① is exactly the reverse of the correct order (Image ①, Image ③, Image ②). It is the mistake you make when you sort by the smallest difference first; the question asks for descending order, so it does not apply.

ここがポイント
  • With run-length encoding (a lossless compression method), the longer the same color continues along the scanning direction, the fewer items there are and the smaller the character count. Rotating an image by 90 degrees changes the relationship between the pattern and the scanning direction, so even the same image gives a different character count after compression.
  • For a 7x7 image, a 90-degree rotation to the right maps “row i, column j before rotation” to “row j, column (8-i) after rotation”. An image whose shape does not change when rotated (rotationally symmetric) keeps the same character count after compression, so its difference is 0.
用語

Your answers