Image Processing Tools and Techniques
From SoftwarePractice.org
Imread
Imread reads any grayscale or color image from the filename specified. The image is read as an array and value returned. If the image is a grayscale then a matrix of 2-by-2 is returned else its coloured then the array returned is 3 dimensions in length. The syntax for the function is A=Imread(Filename,Format) Where Filename is the name of the file to read and format is format of that image. This code dealt only with grayscaled images
'Fspecial
Fspecial can create various sorts of filters like average disk, sobel, unsharp. It creates a 2 dimensional array of the filter specified. The syntax used is
Image = fspecial(type)
Where type is the type of filter used.In this project we have used filters such as 'unsharp' and 'motion'.
Edge Detection
Edge detection technology is used to characterise the location in an image where the contrast of the image changes. This function works by looking for sharp contrast changes in an image which is done by taking the first and second derivatives of the image data and looks for the highest rate of change and marks it as an edge. It helps in preserving important structural information and reduction of less significant information of the image by means of filters. Edges are usually of a higher contrast than the rest of the image. The edge reflects boundaries of an image and hence requires image processing tools. There are various methods for edge detection. These are Sobel, Prewitt, Roberts Cross and Canny. For the purpose of this project we researched on Sobel and Prewitt
Sobel
Sobel is a discrete differential operator which is used to calculate approximate value of the gradient of image intensity. Sobel operator at each point of the image has a corresponding gradient vector. The gradient is the point in a 2D image where horizontal and vertical components are given by the derivatives. This gives the rate of change from light to dark and vice versa. The image represents an edge if the changes in orientation are abrupt otherwise if the image has gradual change from dark to light then the changes are smooth and the edges may not be very evident. The gradient also represents the largest possible pixel change in direction of the image. The picture below shows the computation of Sobel operator on the original image. First image is the original image and the second image is computationally changed using Sobel operator. Only the evident changes in the original picture are highlighted.
(Source:Fisher, 2003)
Prewitt
Prewitt edge detector is used to estimate the magnitude and direction of the image. It determines the image derivatives in x and y. This method takes the kernels and rotates its coefficients 8 times each time in steps of 45o. The 8 coefficients are convolved with each other and this process is highly time consuming and is not very accurate. The image picked up is the one with maximum response which is found out by calculating the value of next pixel in output magnitude image. Although Prewitt was researched on but was not used in the project as Sobel was found to be more efficient and easier to implement.
The image below shows an image computed using the Prewitt edge detector.
(Source:Fisher, 2003)
Imfilter
Imfilter is used to filter a multidimensional array with a multidimensional filter. The result obtained is of same size as the array specified. The parameters specified carry out the multidimensional filtering. The syntax for this is
A = Imfilter(Y, Z, type1, type2,…)
The values of type1 can be symmetric, replicate, circular, correlate, and type2 canbe corr conv etc.
Replicate
This parameter rounds array value lying outside the bounds to the next integer border value. The syntax of which is as follows:
A = imfilter(Y, Z, ‘replicate’)
Conv
This parameter helps in calculation of multidimensional filter by means of convolution. An example of syntax using this is
A = imfilter(Y, Z, ‘conv’) where A is a filter with convolution of Y and Z
Corr
Correlation is the type of filtering which covolves the two arrays without any flipping. An example of syntax using this is A = imfilter(Y, Z, ‘corr’) where A is a filter with convolution of Y and Z without any flipping of arrays.\
Unsharp
The unsharp filter in Matlab works using the unsharp masking technique which has been used in photography since 1930s. This is a type of fspecial filter which returns a 3-by-3 unsharp image which enhances the contrast. The syntax used for this is
Image = fspecial(‘unsharp’, alpha)
Where unsharp is the type of fspecial filter created from the negative Laplacian filter and alpha is the parameter which controls the shape of Laplacian. The value fo alpha ranges from 0.1 to 1.0 and the default value is 0.2
It works by creating a blurred vision of the original image and compares the two images. The difference between the two images is greater than the specified threshold (alpha = 0.1 in our case) then the blurred image is subtracted from the original creating a sharper image. Through trial and error the smallest value of alpha worked best in this case as any blurring that we were trying to reduce was only a couple of pixels wide at the most.
Wiener Filter
Wiener Filter is an adaptive filter as it is capable of adjusting itself to be the best possible filter for the data given. It filters out the 'noise' which it assumes that the image has recieved using statistical methods and data given as in this case, LEN and Theta. LEN is the width in Pixels and Theta is the angle by which image is rotated. Using this information Wiener filter assumes the noise that may have been obtained if it was exposed to those values. However, the motion filter on Matlab which is a Wiener filter did not work as well as expected. When tested with Theta which is the angle of rotaion majority of the times the image turned out to be worse than before. This is why Theta was fixed to the optimal value and LEN was also fixed to a value that worked well on majority of the barcodes with that fixed Theta.
Motion filter
The 'motion' filter is used to deblur images using the Wiener filtering process.To call this function, we need to use the following code:
PSF = fspecial('motion',LEN,THETA);
LEN and THETA are predefined parameters.'LEN' represents the length of the image in pixels accross which the filtering must happen and 'THETA' is the angle by which the image needs to be deblurred.
Imshow
This function is used to display the picture in greyscale or RGB as specified. The various parameters for the function are DisplayRange, Xdata, Ydata etc. The syntrax for this is A = imshow(filename)
Imrotate
This function is used to rotate the picture by the specified degrees of angle counter-clockwise around its centre point. The syntax for the function is A =Imrotate(picture, angle) where picture is the filename of the image and that is rotated by the degrees of angle.
Imcrop
Imcrop crops the image to the specified dimensions. There are two ways of cropping a picture: interactively and non interactively. For this project non interactive method is chosen.The sytax is as follows:
A = imcrop(picture,rect)
Where picture is the image to be cropped and rect is the vector with four elements in the form [xmin ymin width height] and these values are specified in spatial coordinates.
Return to Barcode Recognition Main Page
Reference
The Matworks, Image Processing toolbox help, URL: http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox, last visited 7th November 2006.
Fisher, 2003, 'Compass Edge Detector', URL: http://homepages.inf.ed.ac.uk/rbf/HIPR2/prewitt.htm, last visited 8th November 2006.




