Skip to content

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

This question's explanation and your answers so far.

問91
頻出度★★☆

文字や図形を白黒で縦 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 ディジタル画像を右に90度回転させる処理を流れ図で表すとき, 図3のaに入れる適切な字句はどれか。 図3 ディジタル画像を右に90度回転させる処理

開始
  iでの繰返し(i=1,2,…,7)
    jでの繰返し(j=1,2,…,7)
      回転前のi行j列の画素を回転後の[ a ]の画素に設定する
    jでの繰返し
  iでの繰返し
終了
出典 平成23年度 秋期 ITパスポート試験 問91
解説

問 91

  • Incorrectア

    “Row (8-i), column j” reverses only the row number to 8-i and leaves the column number j as it is. Because no swap of rows and columns takes place, this is not a rotation but a vertical flip (vertical mirror) that turns the image upside down. In fact, under this formula the top-left pixel at row 1, column 1 before rotation moves to row 7, column 1 (bottom left), whereas in Figure 3, which rotates the image 90 degrees to the right, it should come to row 1, column 7 (top right), so it does not match the figure.

  • Incorrectイ

    “Row (8-j), column i” does swap rows and columns, but it reverses the wrong number. Under this formula the top-left pixel at row 1, column 1 before rotation moves to row 7, column 1 (bottom left), and that is how pixels move when the image is rotated 90 degrees to the left (counterclockwise). The arrow in Figure 3 says “rotate 90 degrees to the right”, so this is the opposite direction and is wrong. Correctly, it is the column side that is reversed, as 8-i, while the row stays j.

  • Incorrectウ

    “Row i, column (8-j)” reverses only the column number to 8-j and leaves the row number i as it is. This too has no swap of rows and columns, so it does not amount to a rotation; it is only a horizontal flip (horizontal mirror) that turns the image left-right. Under this formula the top-left pixel at row 1, column 1 before rotation does become row 1, column 7, but if you go on to check row 7, column 1 (bottom left), it moves to row 7, column 7 (bottom right), which conflicts with row 1, column 1 (top left) expected from a 90-degree rotation to the right, so it is wrong.

  • エ

    正解 The correct answer is エ “Row j, column (8-i)”. The image in Figure 3 is a square of 7 pixels both vertically and horizontally (rows i=1 to 7, columns j=1 to 7), and when it is turned 90 degrees to the right (clockwise), the original “rows” become “columns” just as they are, and the original “columns” become “rows” just as they are. Rows and columns are therefore swapped, and the pixel at row i, column j before rotation comes to row j after rotation. As for the column number, the topmost row before rotation (i=1) becomes the rightmost column (column 7) after rotation, and the bottom row (i=7) becomes the leftmost column (column 1), so the column number is reversed to 7+1-i = 8-i. To sum up, (row i, column j) → (row j, column (8-i)). Checking with the corners: the top-left pixel at row 1, column 1 before rotation moves to row 1, column 7 (top right) after rotation, since 8-i = 7; the bottom-left pixel at row 7, column 1 before rotation moves to row 1, column 1 (top left), since 8-i = 1; and the top-right pixel at row 1, column 7 before rotation moves to row 7, column 7 (bottom right). All of these agree with how the “before rotation” and “after rotation” pictures in Figure 3 correspond. Therefore what goes into a is “Row j, column (8-i)”.

ここがポイント
  • The coordinate transformation that rotates an N×N image 90 degrees to the right (clockwise) is (row i, column j) → (row j, column (N+1-i)). In this question N=7, so it becomes (row j, column (8-i)). For 90 degrees to the left (counterclockwise) it is (row i, column j) → (row (N+1-j), column i). Always verify which direction it is by checking a corner pixel.
  • Whether or not rows and columns are swapped (i and j exchanged) is exactly what separates a “rotation” from a “flip (mirror)”. Reversing only the row number gives a vertical flip, and reversing only the column number gives a horizontal flip; neither of them is a 90-degree rotation.
  • The double iteration in the flow diagram (the iteration over j from 1 to 7 nested inside the iteration over i from 1 to 7) is a standard pattern that scans every pixel one by one, and it is the coordinate expression in the inner process that decides what the processing means.
用語

Your answers