In this lab, we were given page of text in which we were to use the hit or miss transform to count the number of b's in the image.
After we scanned in this image, the next step was to grab a letter b from the image to use as a mask.
The problem we initially encountered is that all the b's were not identical,
so when we eroded the image by the b, only one of the b's showed a white
spot. To solve this problem, we dilated the image by the mask:
A = [1 1 1]
[1 1 1]
[1 1 1]
We then performed the erosion by the 'b' mask shown above. The image below is the results of the erosion.
As you can see, there are five dots on the image. If you compare this image to the original image at the top of the web page, you can see that these five dots correspond to the locations of the five b's.
Here is our source code also:
Im = imread('scan.tif');
Ib = imread('b.tif');
Dilate = [1 1 1; 1 1 1; 1 1 1];
Im = logical(uint8(1 - double(Im)));
Ib = logical(uint8(1 - double(Ib)));
Im = dilate(Im, Dilate);
Im = erode(Im, Ib);