Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active March 3, 2026 06:20
Show Gist options
  • Select an option

  • Save CMCDragonkai/aa36a0bcb63179624161bf2fa77bcd23 to your computer and use it in GitHub Desktop.

Select an option

Save CMCDragonkai/aa36a0bcb63179624161bf2fa77bcd23 to your computer and use it in GitHub Desktop.

Revisions

  1. CMCDragonkai revised this gist Apr 16, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion conversion_between_coordinate_origins.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ Remember that images loaded into a matrix uses the height as rows and width as c

    Check if your coordinates are actually sub-pixel coordinates. If they are, confirm where the origin starts within a pixel. This just means your coordinates are actually within a pixel. For example (0, 0) TL can mean TL of the TL pixel or the center of the TL pixel or more weirdly the BL of the TL pixel.

    Usually it should be the TL of the TL pixel. But I've read certain things use the center of the TL pixel instead.
    Usually it should be the TL of the TL pixel. But I've read certain things use the center of the TL pixel instead. This means it is possible to have valid negative subpixel coordinates.

    Where I notate `TL of the TL` this means origin subpixel coordinate starts at the TL of the TL pixel.

  2. CMCDragonkai revised this gist Apr 16, 2018. 1 changed file with 69 additions and 2 deletions.
    71 changes: 69 additions & 2 deletions conversion_between_coordinate_origins.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,80 @@
    # Conversion between Coordinate Origins

    ## Between TL and BL with Origin at (0,0)
    * T - Top
    * B - Bottom
    * L - Left
    * R - Right

    Remember that images loaded into a matrix uses the height as rows and width as columns. So x,y coordinates are flipped y,x to get i,j coordinates.

    ## Subpixel Coordinates

    Check if your coordinates are actually sub-pixel coordinates. If they are, confirm where the origin starts within a pixel. This just means your coordinates are actually within a pixel. For example (0, 0) TL can mean TL of the TL pixel or the center of the TL pixel or more weirdly the BL of the TL pixel.

    Usually it should be the TL of the TL pixel. But I've read certain things use the center of the TL pixel instead.

    Where I notate `TL of the TL` this means origin subpixel coordinate starts at the TL of the TL pixel.

    ## Pixel Coordinates TL <-> BL with Origin at (0,0)

    ```
    x = x
    y = height - y - 1
    ```

    ## Between TL and BL with Origin at (1,1)
    Example:

    ```
    BL 0,0 at a 3x3 Image
    x = 0
    y = 3 - 0 - 1 = 2
    TL = 0,3
    ```

    ## Pixel Coordinates TL <-> BL with Origin at (1,1)

    ```
    x = x
    y = height - y + 1
    ```

    Example:

    ```
    BL 1,1 at 3x3 Image
    x = 1
    y = 3 - 1 + 1 = 3
    TL = 1,3
    ```

    ## Subpixel Coordinates TL <-> BL with Origin (0,0) (TL/BL of the TL/BL)

    ```
    x = x
    y = height - y
    ```

    Example:

    ```
    BL 0,100.65 at 101x101 Image
    x = 0
    y = 101 - 100.65
    TL = 0,0.35
    ```

    ## Subpixel Coordinates TL <-> BL with Origin (1,1) (TL/BL of the TL/BL)

    ```
    x = x
    y = height - y + 1
    ```

    Example:

    ```
    BL 1,101.65 at 101x101 Image
    x = 1
    y = 101 - 101.65 + 1 = 0.35
    TL = 1,0.35
    ```
  3. CMCDragonkai revised this gist Apr 16, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions conversion_between_coordinate_origins.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    # Conversion between Coordinate Origins

    ## BL -> TL or TL -> BL with Origin at (0,0)
    ## Between TL and BL with Origin at (0,0)

    ```
    y = height - y - 1
    ```

    ## BL -> TL or TL -> BL with Origin at (1,1)
    ## Between TL and BL with Origin at (1,1)

    ```
    y = height - y + 1
  4. CMCDragonkai created this gist Apr 16, 2018.
    13 changes: 13 additions & 0 deletions conversion_between_coordinate_origins.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # Conversion between Coordinate Origins

    ## BL -> TL or TL -> BL with Origin at (0,0)

    ```
    y = height - y - 1
    ```

    ## BL -> TL or TL -> BL with Origin at (1,1)

    ```
    y = height - y + 1
    ```