Matrix translation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Crirus

    Matrix translation

    I have a 512x512 matrix.
    I need a rutine that give me a transformed matrix from the curent one, with
    a given point in the middle of the matrix, I mean 256x256.

    Any thoughts?

    Crirus


  • Herfried K. Wagner [MVP]

    #2
    Re: Matrix translation

    "Crirus" <Crirus@datagro up.ro> scripsit:[color=blue]
    > I have a 512x512 matrix.
    > I need a rutine that give me a transformed matrix from the curent one, with
    > a given point in the middle of the matrix, I mean 256x256.[/color]

    Do you use the 'System.Drawing .Drawing2D.Matr ix' class?

    --
    Herfried K. Wagner
    MVP · VB Classic, VB.NET
    <http://www.mvps.org/dotnet>

    Comment

    • Crirus

      #3
      Re: Matrix translation

      Nope, I mean a 256 x 256 array of values..not a matrix like that


      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:bljd08$d2s i2$1@ID-208219.news.uni-berlin.de...[color=blue]
      > "Crirus" <Crirus@datagro up.ro> scripsit:[color=green]
      > > I have a 512x512 matrix.
      > > I need a rutine that give me a transformed matrix from the curent one,[/color][/color]
      with[color=blue][color=green]
      > > a given point in the middle of the matrix, I mean 256x256.[/color]
      >
      > Do you use the 'System.Drawing .Drawing2D.Matr ix' class?
      >
      > --
      > Herfried K. Wagner
      > MVP · VB Classic, VB.NET
      > <http://www.mvps.org/dotnet>[/color]


      Comment

      • One Handed Man

        #4
        OK, let me understand you correctly please.

        OK, let me understand you correctly please.

        You start with

        Dim yourArray( 512,512) as Point

        'and end up with

        Dim transformedArra y( 256,256) as Point

        And you say that you want a point at the centre ?

        My Questions

        1.) What transformation is taking/supposed to place? and are you asking how
        to acheive this ?

        2.) With an even numbered x,y lengths you cannot acheive true centre, you
        would need 257 or 255 ( with a centre of 229 or 228 ).

        Please clarify


        OHM




        Crirus wrote:[color=blue]
        > Nope, I mean a 256 x 256 array of values..not a matrix like that
        >
        >
        > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        > news:bljd08$d2s i2$1@ID-208219.news.uni-berlin.de...[color=green]
        >> "Crirus" <Crirus@datagro up.ro> scripsit:[color=darkred]
        >>> I have a 512x512 matrix.
        >>> I need a rutine that give me a transformed matrix from the curent
        >>> one, with a given point in the middle of the matrix, I mean 256x256.[/color]
        >>
        >> Do you use the 'System.Drawing .Drawing2D.Matr ix' class?
        >>
        >> --
        >> Herfried K. Wagner
        >> MVP · VB Classic, VB.NET
        >> <http://www.mvps.org/dotnet>[/color][/color]


        Comment

        • Crirus

          #5
          Re: OK, let me understand you correctly please.

          Ok, few mistakes...
          The array is one and only 512 x512 starting from 0 so tere are 513 elements
          on each dimension
          I need another 512x512 array with a specified element in the 128x128
          position

          like this:

          suppose (x,y) is the element at x,y position in the array

          First 5x5 array()

          (0,0)(1,0)(2,0) (3,0)(4,0)
          (0,1)(1,1)(2,1) (3,1)(4,1)
          (0,2)(1,2)(2,2) (3,2)(4,2)
          (0,3)(1,3)(2,3) (3,3)(4,3)
          (0,4)(1,4)(2,4) (3,4)(4,4)

          Let say I need (1,3) element at the center

          so the new array will be:


          (4,1)(0,1)(1,1) (2,1)(3,1)
          (4,2)(0,2)(1,2) (2,2)(3,2)
          (4,3)(0,3)(1,3) (2,3)(3,3)
          (4,4)(0,4)(1,4) (2,4)(3,4)
          (4,0)(0,0)(1,0) (2,0)(3,0)


          that transformation is what I need...


          "One Handed Man" <Bombay@Duck.ne t> wrote in message
          news:bljh66$oan $1@sparta.btint ernet.com...[color=blue]
          > OK, let me understand you correctly please.
          >
          > You start with
          >
          > Dim yourArray( 512,512) as Point
          >
          > 'and end up with
          >
          > Dim transformedArra y( 256,256) as Point
          >
          > And you say that you want a point at the centre ?
          >
          > My Questions
          >
          > 1.) What transformation is taking/supposed to place? and are you asking[/color]
          how[color=blue]
          > to acheive this ?
          >
          > 2.) With an even numbered x,y lengths you cannot acheive true centre, you
          > would need 257 or 255 ( with a centre of 229 or 228 ).
          >
          > Please clarify
          >
          >
          > OHM
          >
          >
          >
          >
          > Crirus wrote:[color=green]
          > > Nope, I mean a 256 x 256 array of values..not a matrix like that
          > >
          > >
          > > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          > > news:bljd08$d2s i2$1@ID-208219.news.uni-berlin.de...[color=darkred]
          > >> "Crirus" <Crirus@datagro up.ro> scripsit:
          > >>> I have a 512x512 matrix.
          > >>> I need a rutine that give me a transformed matrix from the curent
          > >>> one, with a given point in the middle of the matrix, I mean 256x256.
          > >>
          > >> Do you use the 'System.Drawing .Drawing2D.Matr ix' class?
          > >>
          > >> --
          > >> Herfried K. Wagner
          > >> MVP · VB Classic, VB.NET
          > >> <http://www.mvps.org/dotnet>[/color][/color]
          >
          >[/color]


          Comment

          • Crirus

            #6
            Re: Matrix translation

            I did it!
            Thanks for help intention:

            This is the ideea:

            For i As Integer = 0 To Width - 1
            For j As Integer = 0 To Height - 1
            x = i + (((Width - 1) / 2) - thisPoint.X)
            y = j + (((Height - 1) / 2) - thisPoint.Y)
            If x < 0 Then x = Width + x
            If y < 0 Then y = Height + y
            If x >= Width Then x = x - Width
            If y >= Height Then y = y - Height
            oldArray(x, y)=NewArray(i, j)
            Next
            Next



            "Crirus" <Crirus@datagro up.ro> wrote in message
            news:OIgjbaXiDH A.1684@TK2MSFTN GP12.phx.gbl...[color=blue]
            > I have a 512x512 matrix.
            > I need a rutine that give me a transformed matrix from the curent one,[/color]
            with[color=blue]
            > a given point in the middle of the matrix, I mean 256x256.
            >
            > Any thoughts?
            >
            > Crirus
            >
            >[/color]


            Comment

            • EricJ

              #7
              Re: OK, let me understand you correctly please.

              you could try something like this (code not tested) but look out for index
              out of bound errors

              dim x2,y2 as integer
              for x as int = p1 -128 to p1 +128
              for y as int = p2 -128 to p2 + 128
              arr2(x2,y2) = arr1(x,y)
              y2+=1
              loop
              x2 +=1
              loop

              "Crirus" <Crirus@datagro up.ro> wrote in message
              news:uqA5N1ZiDH A.1864@TK2MSFTN GP10.phx.gbl...[color=blue]
              > Ok, few mistakes...
              > The array is one and only 512 x512 starting from 0 so tere are 513[/color]
              elements[color=blue]
              > on each dimension
              > I need another 512x512 array with a specified element in the 128x128
              > position
              >
              > like this:
              >
              > suppose (x,y) is the element at x,y position in the array
              >
              > First 5x5 array()
              >
              > (0,0)(1,0)(2,0) (3,0)(4,0)
              > (0,1)(1,1)(2,1) (3,1)(4,1)
              > (0,2)(1,2)(2,2) (3,2)(4,2)
              > (0,3)(1,3)(2,3) (3,3)(4,3)
              > (0,4)(1,4)(2,4) (3,4)(4,4)
              >
              > Let say I need (1,3) element at the center
              >
              > so the new array will be:
              >
              >
              > (4,1)(0,1)(1,1) (2,1)(3,1)
              > (4,2)(0,2)(1,2) (2,2)(3,2)
              > (4,3)(0,3)(1,3) (2,3)(3,3)
              > (4,4)(0,4)(1,4) (2,4)(3,4)
              > (4,0)(0,0)(1,0) (2,0)(3,0)
              >
              >
              > that transformation is what I need...
              >
              >
              > "One Handed Man" <Bombay@Duck.ne t> wrote in message
              > news:bljh66$oan $1@sparta.btint ernet.com...[color=green]
              > > OK, let me understand you correctly please.
              > >
              > > You start with
              > >
              > > Dim yourArray( 512,512) as Point
              > >
              > > 'and end up with
              > >
              > > Dim transformedArra y( 256,256) as Point
              > >
              > > And you say that you want a point at the centre ?
              > >
              > > My Questions
              > >
              > > 1.) What transformation is taking/supposed to place? and are you asking[/color]
              > how[color=green]
              > > to acheive this ?
              > >
              > > 2.) With an even numbered x,y lengths you cannot acheive true centre,[/color][/color]
              you[color=blue][color=green]
              > > would need 257 or 255 ( with a centre of 229 or 228 ).
              > >
              > > Please clarify
              > >
              > >
              > > OHM
              > >
              > >
              > >
              > >
              > > Crirus wrote:[color=darkred]
              > > > Nope, I mean a 256 x 256 array of values..not a matrix like that
              > > >
              > > >
              > > > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
              > > > news:bljd08$d2s i2$1@ID-208219.news.uni-berlin.de...
              > > >> "Crirus" <Crirus@datagro up.ro> scripsit:
              > > >>> I have a 512x512 matrix.
              > > >>> I need a rutine that give me a transformed matrix from the curent
              > > >>> one, with a given point in the middle of the matrix, I mean 256x256.
              > > >>
              > > >> Do you use the 'System.Drawing .Drawing2D.Matr ix' class?
              > > >>
              > > >> --
              > > >> Herfried K. Wagner
              > > >> MVP · VB Classic, VB.NET
              > > >> <http://www.mvps.org/dotnet>[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Fergus Cooney

                #8
                Re: Matrix translation

                Hi Crirus,

                There is unlikely to be anything in the Framework.

                Can you give us any more information about what kind of transform you are
                talking about - out of a universe of possibilities? The more you can specify,
                the more likely someone will understand the requirement.

                Regards,
                Fergus


                Comment

                • Dmitriy Lapshin [C# / .NET MVP]

                  #9
                  Re: OK, let me understand you correctly please.

                  Hi,

                  This seems to be simple as long as allocating yet another couple of
                  megabytes shouldn't be an issue. So, allocate a destination array of the
                  same size. Then, start looping over rows and columns of the source array
                  (i.e. outer and inner loops). Within the inner loop body,
                  assuming that loop indexes were named row and col:

                  Dim newRow As Integer = (row + 128) Mod 512
                  Dim newCol As Integer = (col + 128) Mod 512

                  NewArray(newRow , newCol) = OldArray(row, col)

                  --
                  Dmitriy Lapshin [C# / .NET MVP]
                  X-Unity Test Studio

                  Bring the power of unit testing to VS .NET IDE


                  "Crirus" <Crirus@datagro up.ro> wrote in message
                  news:uqA5N1ZiDH A.1864@TK2MSFTN GP10.phx.gbl...[color=blue]
                  > Ok, few mistakes...
                  > The array is one and only 512 x512 starting from 0 so tere are 513[/color]
                  elements[color=blue]
                  > on each dimension
                  > I need another 512x512 array with a specified element in the 128x128
                  > position
                  >
                  > like this:
                  >
                  > suppose (x,y) is the element at x,y position in the array
                  >
                  > First 5x5 array()
                  >
                  > (0,0)(1,0)(2,0) (3,0)(4,0)
                  > (0,1)(1,1)(2,1) (3,1)(4,1)
                  > (0,2)(1,2)(2,2) (3,2)(4,2)
                  > (0,3)(1,3)(2,3) (3,3)(4,3)
                  > (0,4)(1,4)(2,4) (3,4)(4,4)
                  >
                  > Let say I need (1,3) element at the center
                  >
                  > so the new array will be:
                  >
                  >
                  > (4,1)(0,1)(1,1) (2,1)(3,1)
                  > (4,2)(0,2)(1,2) (2,2)(3,2)
                  > (4,3)(0,3)(1,3) (2,3)(3,3)
                  > (4,4)(0,4)(1,4) (2,4)(3,4)
                  > (4,0)(0,0)(1,0) (2,0)(3,0)
                  >
                  >
                  > that transformation is what I need...
                  >
                  >
                  > "One Handed Man" <Bombay@Duck.ne t> wrote in message
                  > news:bljh66$oan $1@sparta.btint ernet.com...[color=green]
                  > > OK, let me understand you correctly please.
                  > >
                  > > You start with
                  > >
                  > > Dim yourArray( 512,512) as Point
                  > >
                  > > 'and end up with
                  > >
                  > > Dim transformedArra y( 256,256) as Point
                  > >
                  > > And you say that you want a point at the centre ?
                  > >
                  > > My Questions
                  > >
                  > > 1.) What transformation is taking/supposed to place? and are you asking[/color]
                  > how[color=green]
                  > > to acheive this ?
                  > >
                  > > 2.) With an even numbered x,y lengths you cannot acheive true centre,[/color][/color]
                  you[color=blue][color=green]
                  > > would need 257 or 255 ( with a centre of 229 or 228 ).
                  > >
                  > > Please clarify
                  > >
                  > >
                  > > OHM
                  > >
                  > >
                  > >
                  > >
                  > > Crirus wrote:[color=darkred]
                  > > > Nope, I mean a 256 x 256 array of values..not a matrix like that
                  > > >
                  > > >
                  > > > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                  > > > news:bljd08$d2s i2$1@ID-208219.news.uni-berlin.de...
                  > > >> "Crirus" <Crirus@datagro up.ro> scripsit:
                  > > >>> I have a 512x512 matrix.
                  > > >>> I need a rutine that give me a transformed matrix from the curent
                  > > >>> one, with a given point in the middle of the matrix, I mean 256x256.
                  > > >>
                  > > >> Do you use the 'System.Drawing .Drawing2D.Matr ix' class?
                  > > >>
                  > > >> --
                  > > >> Herfried K. Wagner
                  > > >> MVP · VB Classic, VB.NET
                  > > >> <http://www.mvps.org/dotnet>[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]

                  Comment

                  • Fergus Cooney

                    #10
                    Re: Matrix translation

                    Hi Crirus,

                    Here's a version using Modulo arithmetic rather than Ifs to do the
                    wraparound. I've done two flavours - one if you prefer rows and columns, the
                    other if you prefer Xs and Ys. ;-)

                    Regards,
                    Fergus

                    <code info="Row, Col version>
                    Public Sub MoveToCentre (ByRef aVals(,) As Object, _
                    CentreRow As Integer, CentreCol As Integer)
                    Dim Width As Integer = aVals.GetUpperB ound(0)
                    Dim Height As Integer = aVals.GetUpperB ound(1)

                    Dim RowMod As Integer = Width + 1
                    Dim ColMod As Integer = Height + 1

                    Dim RowOffset As Integer = Width \ 2 + CentreRow + 1
                    Dim ColOffset As Integer = Height \ 2 + CentreCol + 1

                    Dim aNewVals (Width, Height) As Object
                    Dim Row As Integer
                    Dim Col As Integer
                    For Row = 0 To Height
                    For Col = 0 To Width
                    Dim SrcRow As Integer = (Row + RowOffset) Mod RowMod
                    Dim SrcCol As Integer = (Col + ColOffset) Mod ColMod
                    aNewVals (Row, Col) = aVals (SrcRow, SrcCol)
                    Next
                    Next
                    aVals = aNewVals
                    End Sub
                    </code>

                    <code info="X, Y version>
                    Public Sub MoveToCentre (ByRef aVals(,) As Object, _
                    CentreX As Integer, CentreY As Integer)
                    Dim W As Integer = aVals.GetUpperB ound(0)
                    Dim H As Integer = aVals.GetUpperB ound(1)

                    Dim XMod As Integer = W + 1
                    Dim YMod As Integer = H + 1

                    Dim dX As Integer = W \ 2 + CentreX + 1
                    Dim dY As Integer = H \ 2 + CentreY + 1

                    Dim aNewVals (W, H) As Object
                    Dim I As Integer
                    Dim J As Integer
                    For I = 0 To W
                    For J = 0 To H
                    aNewVals (I, J) _
                    = aVals ((I + dX) Mod XMod, (J + dY) Mod YMod)
                    Next
                    Next
                    aVals = aNewVals
                    End Sub

                    </code>


                    Comment

                    • Fergus Cooney

                      #11
                      Re: Matrix translation

                      Hi Me,

                      Damn server - several hours behind!! :-((

                      Regards,
                      Myself


                      Comment

                      Working...