Python Forum

Full Version: General pointer to start
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Let's say I have a large rectangular picture & each pixel s either 1 or 0 (white/black). How to write a function which takes 2 parameters:
1. Data structure holding the matix of black & white pixel
2. a tuple(x,y) for the position of the start pixel

This function should return the size of black and while area to which that pixel belongs.

any idea where to start?
Your question is somewhat unclear to me.
The first pixel is always at 0,0
And each pixel has 3+1 components, ([A]RGB), in the case of B&W they are (0,0,0) or (255,255,255)
You are probably defining the image as a bitmap and that holds the array of pixels.
The bitmap has a length and a width in pixels.

Paul
as an example, given the region of the image below and selecting the pixel in the middle as a starting point (2,2) (in bold), how do I calculate the area to which point (2,2) belongs?

0 0 0 0 0
0 1 1 0 0
0 1 1 0 0
0 1 0 1 0
0 0 0 0 0
Hi ,
So your question is to find a square region, when the middle is known (and the number of pixels in a row is not even.)
Top left is 0,0, (2 - 2 = 0)
Bottom right must be 4,4. (2 + 2 =4)
2 nested loops will find every pixel in the area.
If you are talking about a selection in a large bitmap, then we do not have enough data.
Paul