|
|
BW2 = imdilate(BW, SE); BW3 = imerode(BW, SE);Where BW is a binary image and SE is a matrix of 1's and 0's defining the shape of the structuring element. A square structuring element can be simply constructed using the MATLAB function ones
For your convenience a small MATLAB function, circularstruct.m, is provided by Dr Peter Kovesi for generating circular structuring elements which you can download.
>> gim = rgb2gray(im);Threshold the image at a level that gives the most pleasing result. Try a dilation followed by erosion to perform a closing operation. Note MATLAB also provides the functions imclose and imopen. Try an open-close noise removal operation to 'clean up' your image. Try a close-open operation and observe the difference.
Experiment with different sized and shaped structuring elements, see if you can create some interesting effects.
This year every unit on campus will be surveyed using the Student Unit Reflective Feedback (SURF) form. The forms will be filled in by students, collected, scanned and then processed to automatically determine the responses. Some examples of scanned forms can be found in the Images directory. Note that these scanned images are quite large. When you display them under MATLAB they will be considerably reduced in size. You can use the magnify tool at the top of the figure window to zoom in and see features in more detail.
A key step in the processing of these images is the location of the 'landmark' squares at the corners. Once the centres of these have been found a coordinate system can be defined that allow one to readily locate the response squares and determine what responses have been selected.
% LOCATELANDMARKS - locates landmarks on SURF form % % Usage: [tl, tr, bl, br] = locatelandmarks(im) % % Argument: im - Image to be processed, assumed binary. % % Returns: tl, tr, bl, br % - Coordinates of the centroids of the top-left, top-right, % bottom-left and bottom-right landmarks respectively. % These coordinates are returned as column vectors in the % form [row; col] for each landmark. % % The function should also display the image with the centroids of the % landmarks overlayed.
There are a number of ways one could do this. Here are some suggested steps.
bw = ~bw; % The ~ operator performs a logical not operation.
% Image values of 0 become 1 and vice-versa.
You can use the find function to return the row and column coordinates of all the pixels in an object. If you have two arrays, r and c, containing the row and column coordinates of the pixels in a blob then the pixel with the minimum value of (r+c) will be the one that is closest to the top left corner. Thus the top left blob will be the one with the smallest of all the minimum values of (r+c). Similarly the top-right pixel will be the one with the smallest value of (r-c). By using different linear combinations of the row and column coordinates you can test for distances with respect to any direction.
Note that unfortunately the Institutional Research Unit has written their name across the bottom left of the form complicating the identification of the bottom-left landmark. - You can have a think about this!
There are several images of SURF forms in the Images directory, note that surf01 and surf02 are slightly smaller in scale than the others, see if your code can cope with them all.
The following should be included in your portfolio:
This material can be placed in a special directory in your area for subsequent incorporation into a portfolio.