# Can anyone please explain image pixel coordinate plane?

**URL:** <https://forum.opencv.org/t/can-anyone-please-explain-image-pixel-coordinate-plane/7737>\
**Category:** Uncategorized\
**Created:** [February 27, 2022, 6:59pm UTC](https://forum.opencv.org/t/can-anyone-please-explain-image-pixel-coordinate-plane/7737 "2022-02-27T18:59:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shlokpurani](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@shlokpurani](https://forum.opencv.org/u/shlokpurani)\
**Post date:** [February 27, 2022, 6:59pm UTC](https://forum.opencv.org/t/can-anyone-please-explain-image-pixel-coordinate-plane/7737/1 "2022-02-27T18:59:48Z")

</div>

I am trying to understand the image pixel coordinate system which is a bit different than the point coordinate system. Sox as far as I know the **y increases from top to bottom** while **x increases from left to right** as every image starts from (0,0) origin to the very topleft most corner and bottomright most corner(1019,664) vary based on the image Please find the attached image below

 ![saved](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/8/8dbb645a384c12c55b30024ea74f3f4c84095332.jpeg)

As you can see the topleft corner has coordinates (x:517, y:321) while bottomright corner has coordinates (x:1018, y:302). So not sure **why y coordinate of bottomright corner is less than y coordinate of topleft**? Here is the code

```auto
if(event == cv2.EVENT_LBUTTONDOWN):
			cv2.circle(dst, (x,y), 3, (0,255,255), 4, cv2.LINE_AA)
			cv2.putText(dst, "x: {x},y:{y}".format(x=x,y=y), (x-250,y), cv2.FONT_HERSHEY_SIMPLEX, 1,(0,100,255),2,cv2.LINE_AA)
			cv2.imshow("Destination Image", dst)

```

The reason I am doing x-250 is just for display purpose. The image coordinate system is the most fundamental concept in Image processing and OpenCV. Can anyone please explain me this concept?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 27, 2022, 8:25pm UTC](https://forum.opencv.org/t/can-anyone-please-explain-image-pixel-coordinate-plane/7737/2 "2022-02-27T20:25:41Z")

</div>

> [@shlokpurani](#):
>
> **y increases from top to bottom** while **x increases from left to right** as every image starts from (0,0) origin to the very topleft most corner and bottomright most corner(1019,664)

that’s all correct.

please show more code, there must be a silly mistake in it

---

<div class="post-metadata">

**Author:** ![shlokpurani](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@shlokpurani](https://forum.opencv.org/u/shlokpurani)\
**Post date:** [February 27, 2022, 8:31pm UTC](https://forum.opencv.org/t/can-anyone-please-explain-image-pixel-coordinate-plane/7737/3 "2022-02-27T20:31:35Z")

</div>

Here is the full code. so what this code does is it will open an imagewindow and when we **left click** anywhere in the image it will show the point where we **leftclicked** and its coordinate. I hope this helps

```auto
import cv2
import numpy as np

counter = 0
points = []
def MouseCallback(event, x, y, flags, userdata):
    global counter
    if(event == cv2.EVENT_LBUTTONDOWN):
        if(counter < 4):
            cv2.circle(dst, (x,y), 3, (0,255,255), 4, cv2.LINE_AA)
            cv2.putText(dst, "x: {x},y:{y}".format(x=x,y=y), (x-250,y), cv2.FONT_HERSHEY_SIMPLEX, 1,(0,100,255),2,cv2.LINE_AA)
            cv2.imshow("Destination Image", dst)
            points.append((x,y))
            counter += 1
            #print(x,y)
            #print(points)
        if(len(points) == 4):
            #roi = dst[:,541:1018]
            #cv2.imshow("winname", roi)
            #print(points)
            array_points = np.array(points)
            #new_points = order_points(array_points)
            print(array_points)
            cv2.imwrite("saved.jpg", dst)
            #top_left_x = min(points, key=itemgetter(1))[0]
            #top_left_y = min(points, key=itemgetter(0))[0]
            #bot_right_x = max(points, key=itemgetter(1))[0]
            #bot_right_y = max(points, key=itemgetter(0))[0]
            
            #height = top_left_y - bot_right_y
            #width = top_left_x - bot_right_x
            #print(y1,x1,y2,x2)
            #roi = dst[top_left_y:bot_right_y+1,top_left_x:bot_right_x+1]
            #cv2.imshow("roi", roi)
dst = cv2.imread("times_square.jpg")
mask = np.zeros((dst.shape[:2]),dtype='uint8')
cv2.imshow("mask", mask)
cv2.imshow("Destination Image", dst)
print(cv2.EVENT_RBUTTONDOWN,"hello")
cv2.setMouseCallback("Destination Image", MouseCallback)
key = cv2.waitKey(0)
if( key == ord('q') ):
    cv2.destroyAllWindows()

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [February 27, 2022, 10:57pm UTC](https://forum.opencv.org/t/can-anyone-please-explain-image-pixel-coordinate-plane/7737/4 "2022-02-27T22:57:13Z")

</div>

the bottom right point **is** higher than the top left one. that means its Y coordinate must be smaller.

why did you assert otherwise? you should question your perception more often.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/45796ba8d8b78f44ea4d577b7641185dc6cf629a.jpeg)
