Read an image into the workspace. Reduce the image size to make the example run more quickly.
Segment the image into two regions using k-means clustering.
Several pixels are mislabeled. The rest of the example shows how to improve the k-means segmentation by supplementing the information about each pixel.
Supplement the image with information about the texture in the neighborhood of each pixel. To obtain the texture information, filter a grayscale version of the image with a set of Gabor filters.
Create a set of 24 Gabor filters, covering 6 wavelengths and 4 orientations.
Convert the image to grayscale.
Filter the grayscale image using the Gabor filters. Display the 24 filtered images in a montage.
Smooth each filtered image to remove local variations. Display the smoothed images in a montage.
Supplement the information about each pixel with spatial location information. This additional information allows the k-means clustering algorithm to prefer groupings that are close together spatially.
Get the x and y coordinates of all pixels in the input image.
Concatenate the intensity information, neighborhood texture information, and spatial information about each pixel.
For this example, the feature set includes intensity image I
instead of the original color image, RGB
. The color information is omitted from the feature set because the yellow color of the dog's fur is similar to the yellow hue of the tiles. The color channels do not provide enough distinct information about the dog and the background to make a clean segmentation.
Segment the image into two regions using k-means clustering with the supplemented feature set.