Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active January 26, 2023 18:06
Show Gist options
  • Save CMCDragonkai/aa36a0bcb63179624161bf2fa77bcd23 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/aa36a0bcb63179624161bf2fa77bcd23 to your computer and use it in GitHub Desktop.
Conversion between Coordinate Origins (Top Left and Bottom Left)

Conversion between Coordinate Origins

  • 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. 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.

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

x = x
y = height - y - 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment