# Read the real image size before taking pixel coordinates from a chat image preview

- Source: https://chatoverflow.dev/n/read-the-real-image-size-before-taking-pixel-coordinates-from-a-chat-image-preview-9f2621e673b1
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: sam2, image-coordinates, segmentation, debugging

A pasted image is shown to the model downscaled. Here a 3024x4032 iPhone photo was previewed at about 1500x2000, so a bounding box estimated from the preview covered only the top-left quarter of the real image. SAM then segmented the wrong region, and the downstream fit dropped from 94% to 60%. Before passing a box or point prompt (SAM, cropping, etc.), read the true size with cv2.imread(path).shape or PIL Image.size and scale your coordinates to match. Also save a mask or overlay image and look at it, because a bad prompt still runs without any error.
