Re: Circular neighborhood for ImageApply

*To*: mathgroup at smc.vnet.net*Subject*: [mg115064] Re: Circular neighborhood for ImageApply*From*: Shadi Ashnai <shadi at wolfram.com>*Date*: Thu, 30 Dec 2010 04:09:40 -0500 (EST)

Hi Adrian, In ImageFilter you cannot specify a non-rectangular neighborhood yet. The following code would only count the zero pixels inside the disk and divide by the size of the disk: disksize = Total[DiskMatrix[r], 2]; ImageFilter[Count[DiskMatrix[r] - #, 1., 2]/disksize &, ColorConvert[i, "Grayscale"], r] Another suggestion would be to remove disks smaller than your radius by doing: Closing[i, DiskMatrix[6]] If you got Mathematica 8, you can simply compute the center of each foreground object (remaining disks) by either of the following: 1) MaxDetect[ DistanceTransform[ image ] ] (* computes the ultimate erosion and returns an image consisting of the centers *) 2) ComponentMeasurements[ image, "Centroid" ] (* returns the coordinate of the centers *) Best, Shadi Ashnai Wolfram Research Inc. From: "Adrian Boyko" <adrianboyko at gmail.com> To: mathgroup at smc.vnet.net Sent: Tuesday, December 28, 2010 5:52:36 AM Subject: [mg115064] [mg115022] Circular neighborhood for ImageApply Usual disclaimer: I'm a casual home user of Mathematica, so please forgive what might seem like silly questions. I'm using ImageFilter like this: ImageFilter[1.0*Count[Flatten[#], 0.]/Length[Flatten[#]] &, ColorConvert[binaryImage, "Grayscale"], r] I.e. I'm trying to replace each pixel with the ratio of 0 pixels and 1 pixels in its square neighborhood. I'm doing this because I'm trying to find the center of disks (of an expected radius) in a scanned image, and this works reasonably well. But, since I'm actually looking for disks I think it would be better to find the ratio in the pixel's _disk_ (not square) neighborhood. It seems like there ought to be a simple way to work DiskMatrix[3] into my expression, and extra processing time isn't an issue. Any ideas? Is there some operator I can apply to # and DiskMatrix[3] which would mask out the neighborhood values outside the disk? I think ImageMultiply ought to work like an ImageAnd if all my pixel values are 0 or 1, but I haven't had any luck with it. On a tangent, I have another filter that ought to be looking for the ratio in a ring neighborhood between r1 and r2. Maybe the answer to my first question will also tell me how to combine DiskMatrix[r1] and DiskMatrix[r2] to get RingMatrix[r1,r2]. Any help will be greatly appreciated. Thanks, Adrian P.S. I'm considering the upgrade to Mathematica 8. Since I have a CUDA-compatible graphics card, is it safe to assume that version 8 will _automatically_ utilize it when executing these sorts of operations? Or would I need to code differently to take advantage of it?