This paper presents a novel color indexing technique for segmentation and edge detection of objects with a background whose color appears to be very close to the objects. To enhance the discriminability of different colors, each color on the image is first nonlinearly mapped into an enhanced color model in a six-dimensional color space. Then, by solving a linear least square problem which involves only two multiplications and one inversion of a six by six matrix, the present approach converts a color image into a gray image with an optimally enhanced contrast of the gray level between the object and its background so that segmentation and edge detection can be performed using conventional techniques existed for gray images, and thereby considerably salves computational effort especially when comparing to vector order methods, entropy methods and invariant object recognition. Experiments also show that the presented color segmentation technique has a better performance than those operating on any three-dimensional color space. To illustrate one of many possible applications of the present technique in real industrial problems, the present technique is applied to detect missing devices and mis-aligned devices on a printed circuit board (PCB) with the aid of morphological operations and our unique design of go-nogo gages. Experiments show that the present approach is significantly more efficient and effective than the existing industrial algorithms known to the authors.