Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. ap alternate boundary pairs in matrix

ap alternate boundary pairs in matrix

Scheduled Pinned Locked Moved Managed C++/CLI
tutorial
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doraemon Kids
    wrote on last edited by
    #1

    Image Transformation
    Digital images are represented as a matrix and each element in the matrix represents the RGB value of a pixel. Given the pixel values of a nXn image. Write a code to transform the image into another image by alternate swap of edge pixels. That is for example, given a 4 X 4 image as follows:

    1 2 3 4

    5 6 7 8

    9 10 11 12

    13 14 15 16

    The edge elements of the above image are 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9 and 5. The following steps are involved in the transformation:

    1 and 3 are swapped

    1 and 8 are swapped

    1 and 16 are swapped

    1 and 14 are swapped

    1 and 9 are swapped

    After doing alternate swap of edge elements the pixel values of the image looks as follows:

    3 2 8 4

    5 6 7 16

    1 10 11 12

    13 9 15 14

    And given an image of dimension 5 X 5 as follows:

    2 4 5 6 3

    3 11 12 7 9

    7 15 13 8 1

    2 21 25 13 14

    17 10 16 19 3

    Should transform as:

    5 4 3 6 1

    3 11 12 7 9

    2 15 13 8 3

    2 21 25 13 14

    7 10 17 19 16

    Input Format

    First line contains the dimension of the matrix, n

    Next nxn lines contain the elements of the matrix in row major order. That is the elements in the first row are given followed by second row and so on

    Output Format

    Print the transformed nxn matrix in ‘n’ lines

    Each line contains the elements of a row separated by a tab.

    Note: There is a tab at the end of each line

    L 1 Reply Last reply
    0
    • D Doraemon Kids

      Image Transformation
      Digital images are represented as a matrix and each element in the matrix represents the RGB value of a pixel. Given the pixel values of a nXn image. Write a code to transform the image into another image by alternate swap of edge pixels. That is for example, given a 4 X 4 image as follows:

      1 2 3 4

      5 6 7 8

      9 10 11 12

      13 14 15 16

      The edge elements of the above image are 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9 and 5. The following steps are involved in the transformation:

      1 and 3 are swapped

      1 and 8 are swapped

      1 and 16 are swapped

      1 and 14 are swapped

      1 and 9 are swapped

      After doing alternate swap of edge elements the pixel values of the image looks as follows:

      3 2 8 4

      5 6 7 16

      1 10 11 12

      13 9 15 14

      And given an image of dimension 5 X 5 as follows:

      2 4 5 6 3

      3 11 12 7 9

      7 15 13 8 1

      2 21 25 13 14

      17 10 16 19 3

      Should transform as:

      5 4 3 6 1

      3 11 12 7 9

      2 15 13 8 3

      2 21 25 13 14

      7 10 17 19 16

      Input Format

      First line contains the dimension of the matrix, n

      Next nxn lines contain the elements of the matrix in row major order. That is the elements in the first row are given followed by second row and so on

      Output Format

      Print the transformed nxn matrix in ‘n’ lines

      Each line contains the elements of a row separated by a tab.

      Note: There is a tab at the end of each line

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You already [osted this question at Alternate swapping of boundary elements of square matrix[^]. Please do not cross post.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups