Case study #1: find the ball

Load two color images of a ball in a room

img1 = ReadImage["ball1.ppm"] ; img2 = ReadImage["ball2.ppm"] ; scale = 1 ;

Display images

g1 = ShowImage[img1, scale, 255, 0, DisplayFunctionIdentity] ; g2 = ShowImage[img2, sc ... 4;Identity] ; Show[GraphicsArray[{g1, g2}], ImageSizeDimensions[img1][[2]] * scale * 2] ;

[Graphics:../HTMLFiles/index_53.gif]

Load pre-processed image of ball for Gaussian color model

ball = ReadImage["ball_data.ppm"] ;

Show image (for building color model)

ShowImage[ball, 1] ;

[Graphics:../HTMLFiles/index_56.gif]

Build Gaussian color model

Eliminate background pixels from data

rgb = DeleteCases[Partition[Flatten[ball], 3], ball[[1, 1]]] ;

Compute the mean μ and covariance matrix Σ over RGB pixel values

{μ = Mean[rgb] // N, Σ = CovarianceMatrix[rgb] // N} ; MatrixForm /@ {μ, Σ}

{( 94.55378486055777`  ), ( 84.43094642705772`    41.93463380520471`   ... 8499335989377`                      7.416297575654827`    106.13060170664858`   132.4099276652256`

Gaussian color-model based ball detection: image #1

Select image

img = img1 ;

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_62.gif]

Gaussian distance image

gd = GaussianDistanceImage[img, μ, Σ] ; RowBox[{RowBox[{ShowImage, [, RowBox[{Max[gd] - gd, ,, scale, ,, RowBox[{1.5,  , Max[gd]}]}], ]}], ;}]

[Graphics:../HTMLFiles/index_64.gif]

Perform Gaussian-distance thresholding on original image

RowBox[{RowBox[{threshold, =, 22.}], ;}]

gt = GaussianThresholdImage[img, threshold, {μ, Σ}] ; ShowImage[gt, scale] ;

[Graphics:../HTMLFiles/index_67.gif]

Blob finding on noisy threshold image

tmp = BlobFind[gt] ; ShowImage[BlobImage[tmp], scale] ; BlobCount[tmp]

[Graphics:../HTMLFiles/index_69.gif]

78

Clean up binary threshold image (w/Opening operator)

gt2 = Opening[gt, Table[1, {5}, {5}]] ; ShowImage[gt2, scale] ;

[Graphics:../HTMLFiles/index_72.gif]

Blob finding on clenaed-up threshold image

tmp = BlobFind[gt2] ; ShowImage[BlobImage[tmp], scale] ; BlobCount[tmp]

[Graphics:../HTMLFiles/index_74.gif]

1

Superimpose original image with cleaned-up threshold image

ShowImage[BitAnd[gt2, img], scale] ;

[Graphics:../HTMLFiles/index_77.gif]

Gaussian color-model based ball detection: image #2

Select image

img = img2 ;

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_80.gif]

Gaussian distance image

gd = GaussianDistanceImage[img, μ, Σ] ; RowBox[{RowBox[{ShowImage, [, RowBox[{Max[gd] - gd, ,, scale, ,, RowBox[{1.5,  , Max[gd]}]}], ]}], ;}]

[Graphics:../HTMLFiles/index_82.gif]

Perform Gaussian-distance thresholding on original image

RowBox[{RowBox[{threshold, =, 22.}], ;}]

gt = GaussianThresholdImage[img, threshold, {μ, Σ}] ; ShowImage[gt, scale] ;

[Graphics:../HTMLFiles/index_85.gif]

Blob finding on noisy threshold image

tmp = BlobFind[gt] ; ShowImage[BlobImage[tmp], scale] ; BlobCount[tmp]

[Graphics:../HTMLFiles/index_87.gif]

78

Clean up binary threshold image (w/Opening operator)

gt2 = Opening[gt, Table[1, {5}, {5}]] ; ShowImage[gt2, scale] ;

[Graphics:../HTMLFiles/index_90.gif]

Blob finding on clenaed-up threshold image

tmp = BlobFind[gt2] ; ShowImage[BlobImage[tmp], scale] ; BlobCount[tmp]

[Graphics:../HTMLFiles/index_92.gif]

1

Superimpose original image with cleaned-up threshold image

ShowImage[BitAnd[gt2, img], scale] ;

[Graphics:../HTMLFiles/index_95.gif]


Created by Mathematica  (February 5, 2004)