MATLAB Examples

# Missing Planes

Government intelligence agencies need to continually analyze thousands of images of enemy territory. They are always looking for change - for instance, has the enemy relocated any of its planes, perhaps to prepare for attack? This example looks at developing an algorithm that can be used to make it faster and more fool-proof for the analysts to spot missing planes.

## Import first image and display

```planes1 = imread('planes1.jpg'); figure;imshow(planes1); ```

## Import second image and display

```planes2 = imread('planes2.jpg'); figure;imshow(planes2); ```

## Compute the difference and display

```D = planes1 - planes2; figure;imshow(D); ```

## Threshold

```Dbw = D > 20; imshow(Dbw); shg; ```

## Remove the noise (pixel groups smaller than 10)

We will next use an Image Processing Toolbox function to remove all small groups of pixels.

```Dbw = bwareaopen(Dbw, 10); % Get rid of regions less than 10 pixels imshow(Dbw); ```

## Dilate

We will also spread the objects to make them more identifyable.

```se1=strel('square',3); Dbw=imdilate(Dbw,se1); imshow(Dbw); ```

## Identify objects

Then we will use another function to identify, count and get the positions of the objects in the image.

```[L,NumDiffs] = bwlabel(Dbw); NumDiffs s = regionprops(L,'all') c = [s.Centroid]; ```
```NumDiffs = 3 s = 3x1 struct array with fields: Area Centroid BoundingBox SubarrayIdx MajorAxisLength MinorAxisLength Eccentricity Orientation ConvexHull ConvexImage ConvexArea Image FilledImage FilledArea EulerNumber Extrema EquivDiameter Solidity Extent PixelIdxList PixelList Perimeter ```

## Display first image and highlight change areas

Finally, we will display the first image and highlight where we think there was a change.

```imshow(planes1); for i = 1 : NumDiffs h=rectangle('Position',[c(2*i-1)-15 c(2*i)-15 30 30],'Curvature',[1 1],'LineWidth',2); set(h,'EdgeColor',[1 1 0]); end ```

## Display second image and confirm changes

Which we can confirm plotting the second image and see that we have correctly detected that three planes have gone.

```imshow(planes2); for i = 1 : NumDiffs h=rectangle('Position',[c(2*i-1)-15 c(2*i)-15 30 30],'Curvature',[1 1],'LineWidth',2,'EdgeColor',[1 1 0]); end ```