[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Proposed additions to Transform: connected components, upper and lower thresholding, and centroids
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Proposed additions to Transform: connected components, upper and lower thresholding, and centroids
- From: "René Dudfield" <renesd@xxxxxxxxx>
- Date: Tue, 17 Jun 2008 11:26:27 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 16 Jun 2008 21:27:53 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=8yxbxS+bJWJnVMiYDLP7X7dRBbUQHs+2exJTXvfWsxk=; b=YhHNyCOV+KHa2hTCRi3Pd2LqjtjmhJ3E6sSEnNk9LZAe3JSNhg3ZNPgdxE9ZcblGk6 zeJoii5zuusu7qoKBLTxG02PcZR7bWiVJ4Rsnj055W+pth2yUFzDt07wH6qKr3bV5aWp W7297cIazQhb0wv3TtG2wmGKQo7tbFD8OP3gE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=QWfOZzcJJu5eg74jE0aO2SWplq93emKLtH8bqPj/vnt2jdevZJQVspKAqfULFubOe/ QHaJ4Qd8/iXBbuR3U7PPDq/wW9wFN9r5QBlLKw2Obia76wWPz4N/pPO8Zls7vvXTOs9u W/XSrM+Yu3OohVATvAbUz41n6bml0G8qM8VLY=
- In-reply-to: <a7215bb70806161749h1b51c2bx23ab557744c732ab@xxxxxxxxxxxxxx>
- References: <a7215bb70806161749h1b51c2bx23ab557744c732ab@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hello,
a few notes below.
On Tue, Jun 17, 2008 at 10:49 AM, Nirav Patel <olpc@xxxxxxxxxxxxxx> wrote:
> As part of my project to add computer vision stuff to pygame, I'd like
> to write a function or functions that do the following.
>
> For vision purposes, it would be very useful to have thresholding with
> both upper and lower boundaries, returning both the number of pixels
> within the threshold and the centroid of those pixels. This is a
> trivial addition to the existing transform.threshold() function, but
> is it acceptable to modify the input options and the output of an
> existing function? Would it break compatibility with existing pygame
> games? Would it make sense to have a second function so similar to an
> existing one?
>
You could modify the existing function if the old functionality stays
the same. Probably by adding another default argument. We try not to
break existing functionality.
I think the current one can use just one distance from the color. So
it's both a lower, and upper threshold. I'm just wondering if it
could be used already to do what you want?
> The other function, which is also similar (and could even just be an
> option in thresholding), is thresholding with connected component
> detection. This would involve supplying an upper and lower threshold,
> a Surface, and optionally a mask. The function would find the largest
> blob of pixels in the Surface within the threshold, make a mask of
> those pixels if desired, and return the centroid and number of pixels
> in the blob.
>
Currently this can sort of be done by making a mask from the
thresholded image. Mask has a get_bounding_rect() function. Doing
the get_bounding_rect on a mask turns out to be fast because you
process way less data -- as mask is 1 bit per pixel. Then you can
sort the bounding rects on size to find the largest one.
I'm not sure if that will be suitable for your task though, but I
think maybe you could do things this way.
> It could also be useful to have multiple connected component
> detection, for "multi-touch" without having to use different colored
> objects (or if you are using IR LEDs like the Wii does), but I'm not
> sure how to handle that in a single pass of the array. Actually, I'm
> not really sure how I'm going to handle both detection and creating a
> mask in a single pass either. It may be necessary to store the
> starting pixel, ending pixel, and size of each connected component on
> the first pass, keeping track of which was the largest yet, and then
> have a shorter second pass to create the mask that only starts at the
> starting pixel and ends at the ending pixel.
>
Multiple areas can be found like above with Mask.get_bounding_rect().
Doing everything in one pass is hard... but if you reduce the data
down -- by using a mask -- then the second pass can act on 32x less
data.
eg, a 1024x1024 image:
>>>(1024 * 1024 * 4) / 32.
131072.0
So that is 4MB on the first pass down to 131KB of data to process on
the second pass.
> Any comments, reality checks, questions, or suggestions would be
> greatly appreciated.
>
> Nirav
>