Case study #2: find the graduate student

Load a foreground and background image of a hallway

img1 = ReadImage["hall1.ppm"] ; img2 = ReadImage["hall2.ppm"] ; scale = 1 ;

Display images

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

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

Example processing steps #1

Smooth both images (Gaussian filtering)

RowBox[{RowBox[{gf, =, RowBox[{RowBox[{GaussianFilter, [, RowBox[{11, ,, 1.25}], ]}],  , //,   ... 4;Identity] ; Show[GraphicsArray[{g1, g2}], ImageSizeDimensions[img1][[2]] * scale * 2] ;

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

Subtract background from foreground image

ShowImage[diff = Abs[s2 - s1], scale, 100] ;

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

Threshold difference image

Threshold image

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

th = ThresholdImage[diff, threshold] ; ShowImage[th, scale] ;

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

Blob finding on unprocessed threshold image

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

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

9

Manipulate binary threshold image

Closing operator

th2 = Closing[th, Table[1, {5}, {5}]] ; ShowImage[th2, scale] ;

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

Dilation operator

th3 = Dilation[th2, Table[1, {3}, {3}]] ; ShowImage[th3, scale] ;

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

Blob finding on processed threshold image

blb = BlobFind[th3] ; ShowImage[BlobImage[blb], scale] ; BlobCount[blb]

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

5

Keep only largest detected blob

bl2 = KeepLargestBlob[blb] ; ShowImage[BlobImage[bl2], scale] ;

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

Superimpose original image with cleaned-up threshold image

v = bl2 //Flatten// Frequencies // Last // Last ; bl2 = bl2 /. v255 ; ShowImage[BitAnd[bl2, img2], scale, 100] ;

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

Example processing steps #2

Subtract background from foreground image

ShowImage[diff = Abs[img2 - img1], scale, 100] ;

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

Threshold difference image

Threshold image

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

th = ThresholdImage[diff, threshold] ; ShowImage[th, scale] ;

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

Blob finding on unprocessed threshold image

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

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

108

Manipulate binary threshold image

Median filter

th2 = MedianFilter[th, 3] ; ShowImage[th2, scale] ;

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

Closing operator

th3 = Closing[th2, Table[1, {7}, {7}]] ; ShowImage[th3, scale] ;

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

Blob finding on processed threshold image

blb = BlobFind[th3] ; ShowImage[BlobImage[blb], scale] ; BlobCount[blb]

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

4

Keep only largest detected blob

bl2 = KeepLargestBlob[blb] ; ShowImage[BlobImage[bl2], scale] ;

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

Superimpose original image with cleaned-up threshold image

v = bl2 //Flatten// Frequencies // Last // Last ; bl2 = bl2 /. v255 ; ShowImage[BitAnd[bl2, img2], scale, 100] ;

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


Created by Mathematica  (February 5, 2004)