Re: Extracting pixel values from an image under a polygon (region of interest)
- To: mathgroup at smc.vnet.net
- Subject: [mg115345] Re: Extracting pixel values from an image under a polygon (region of interest)
- From: James Stein <mathgroup at stein.org>
- Date: Sat, 8 Jan 2011 03:39:08 -0500 (EST)
Dear Mac, Two comments: 1. Selecting pixels within a polygon is an interesting, non-trivial problem. If you Google for "point in polygon" (without the quotes), the first several hits are relevant. Your problem probably deals with polygons with non-intersecting sides, so it'll be a bit easier... 2. I'm not sure why you say there "is no PixelTake function or similar." Given a map of type 'Image', 'ImageData[map]' is an array of pixels; each pixel being an list of 3 color components (sometimes a 4th component as well); Is not the Mathematica primitive 'Take' on the ImageData equivalent to your missing 'PixelTake' function? -- James On Fri, Jan 7, 2011 at 1:10 AM, Mac <mwjdavidson at googlemail.com> wrote: > I've tried solving this general scientific image processing problem > for some time, alas without success. Given an image and a polygon with > coordinates describing a region of interest, I would like to extract > all the image pixels falling completely within the boundaries of the > polygon (not necessarily a square). > > As an illustrative example consider the following synthetic image + > region of interest marked in red > > img = Graphics[{Raster[RandomReal[{0, 1}, {10, 10}]], Red, > Opacity[0.5], Polygon[{{0.9, 0.9}, {4, 4.1}, {7, 4.1}, {8, 1}}]}, > Frame -> True] > > I would like to extract all the values of img falling within the > boundary of the red polygon. The real world problem I face is that I > have a radar map of the earth's surface with the pixel values > representing the radar intensity and would like to extract and analyse > all pixels falling within a specific region (say for instance > Greenland). Despite the advances in image processing in Mathematica 8 > I still do not see a solution. There is no PixelTake function or > similar.... > > Anway, any help would be much appreciated. > > Mac > >