Confused about the pixels on the screen

2 ビュー (過去 30 日間)
Pan
Pan 2012 年 8 月 6 日
回答済み: Vidhi Agarwal 2025 年 6 月 9 日
Dear all,
I am confused about depicting a pixel on the screen.
Is each individual pixel treated as a small square? If this is the case, a coordinate (e.g. [100 100]) only depicts one corner of the specific pixel (top-left corner?), is this correct?
Let's say I want to depict a rectangle onto the screen. Assume the destinationRect is [100 100 200 200], then how many pixels will the rectangle contain? 101*101? or 100*100?
Could any one please help me with this problem?
Best, Pan

回答 (1 件)

Vidhi Agarwal
Vidhi Agarwal 2025 年 6 月 9 日
Hi @Pan,
Yes, each pixel is treated as a unit square, typically with integer-indexed top-left corner coordinates. Coordinate [100, 100] refers to the top-left corner of the pixel at row 100, column 100 (if using image coordinate convention) or x = 100, y = 100 (if using screen coordinates). In MATLAB, this coordinate refers to the top-left corner of the pixel. For a rectangle defined as [100 100 200 200], how many pixels are included depends on the interpretation of the coordinates.
MATLAB often uses the format: [x1, y1, x2, y2]
But in many MATLAB functions (e.g., rectangle), the form is instead: [x, y, width, height]
If [100 100 200 200] is interpreted as [x1 y1 x2 y2], then:
  • Pixels included = (200 - 100 + 1)^2 = 10201
If interpreted as [x, y, width, height]:
  • Pixels included = 200 * 200 = 40000
Hope this helps!

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by