How to group individual groups of pixels into a single class

How to group individual groups of pixels into a single class

I have a raster image with certain pixel groups of equal area. Each group represents a single house. I want all the pixels near a group of houses to have the same pixel value, i.e., I want to name that area "residential area". How can I do this? I want something like this done: this image should change to:

Computing the density of houses and thresholding that will give you flexibility to achieve a reproducible solution to your liking.

The flexibility comes about through varying two parameters: the extent ("radius" or "width") of the density kernel and the threshold value.

The density can be computed through convolution with a Gaussian kernel (a "Gaussian blur" in image-processing parlance) or even through repeated focal means (using circular neighborhoods). The thresholding is a simple comparison operation ("less than" or "greater than") to select regions of highest density.

The numeric headings in the figure are the width of the Gaussian kernel in pixels. (The image itself is approximately 750 by 500 pixels.) The dark areas are the regions selected via a suitable threshold. In this case it appears that widths between 20 and 50 or so will give a result conforming to that sketched in the question. Larger widths can cause the regions to merge while smaller widths may keep them separated.

A nice feature of this approach is its interpretability: the regions can be characterized as those areas where the housing density exceeds so-and-so many houses per unit area (square kilometer or square mile, for instance). That makes it more than a mere cartographic tool and enables its use within quantitative analyses.

The figures were produced with Mathematica 9, but the process in a raster GIS such as Spatial Analyst or GRASS will be similar. It can even (easily) be done with most image processing software.

(* Recreate the original housing indicator grid *) i = Import["">

Using focal statistics will give you the desired results.

Lets say the house pixels have a value of 1 and others have a value of 0. Use the focal statistic with the MAXIMUM statistic type with a neighborhood of your liking. The resulting raster will be a residential area of your neighborhood.

I would imagine that the most efficient way would be to 1) convert your "house" values to a point feature class, 2) create a grouping attribute using a minimum distance criteria with the near tool, 3) loop through each group to generate minimum convex polygons using the Minimum Bounding Geometry tool. You can then convert the combined minimum convex polygons back to a raster.

I recently had a similar problem where I needed to recognize clusters of items. I ended up using a hierarchical clustering algorithm provided by the clusterfck library. Demo here.

To apply this to your problem, you'd first traverse the image and make a list of points fitting your criteria.

For drawing the boundaries, you could use any of several techniques: you could compute a convex hull or perhaps use Voronoi cells.

I'm not sure if these algorithms are implemented in the language you're using, but it's not too difficult to do.