SoftwarePractice.org: Home | Courseware | Wiki | Archive

Angular Rotation

From SoftwarePractice.org

Contents

Angular Rotation Process

Analysis of Angular Rotation within our program contains two function - for upsidedown barcodes and for images turned on an angle.


Image: angul1.jpg


Functions: anglex, rotate_bc

anglex.m


Image:anglex.jpg


Not all barcodes will be perfectly aligned for recognition and conversion. Hence, this function rotates the barcode image if it is angled.

Angled Image: Image: fig1.jpg


If the image is a .jpg file, it is converted into a 2 dimensional array for use within the edge function. Using the canny filter of the edge function, we are able to detect the edges of the image, to aid in determining the angle in which the image has been rotated.

Edge Detection: Image: fig2.jpg


The crux of this function is based on the Radon function within the image processing toolbox. This function computes projections of the image at various angles. The associated peaks within the transform indicate the presence of lines within the image. It thus determines and returns the angle (thetap) and offset value (xpp) which corresponds to the maximum value within the Radon transform. The computed values are associated with the strongest line prevalent within the image.

Radon transform image: Image: rad.jpg

Theoretically, the Radon Transform is similar to the Fourier Transforms. The mathematical definition of this transform is as follows:

Image: Inline1.gif = Image: Inline3.gif = Image: Inline6.gif = Image: Inline9.gif

In these equations, p is the angular slope of the line, and t is the offset, or intercept of the line.


Looking at the angle and offset values for each image that is processed, we are able to rotate image by the corresponding amount using the imrotate function in conjunction with bilinear interpolation. Using bilinear interpolation results in the output pixel position calculated as the weighted average of the pixels in the neighbouring 2-by-2 area, based on the distance these pixels are from the analysed location. A flag is set to this function as not all images are able to be rotated properly due to distortion lines evident within some images.

Resultant Image: Image: outp.jpg


To view the corresponding Matlab code: anglex.m Code

rotate_bc.m


Image:rotate.jpg


Image: UpsideDown.jpg

The predominant idea was the determine how the barcode was being identified as being upside down. UPC-A barcodes have a property which enables programs to determine this. In particular, it is known that The barcode is split into left and right. That is, 6 digits on the left, and 6 digits on the right. Each side is different from the other due to the fact the binary codes are ones complements; as well as the presence of odd parity and even parity within the left and right side binary codes, respectively.

What we did was to convert the image into its component of binary bits. Firstly, we analyse the first 7 bits (first digit) on the image's left, after the 1-0-1 start bit. If these first 7 bits are of odd parity, then we know that we are looking at an image which is the correct orientation. However, if it is of an even parity, we are able to flip the image using the fliplr function, so the right is now on the left, and vice versa. Once flipped, we repeat the process again, ensuring that yes, this is supposed to be on the left.

Once the image is the correct way up, we are a able to move onto the next step of processing.


To view the corresponding Matlab code: rotate_bc.m Code


Alternative Methods

Another way of angular rotation of images would be the utilisation of Hough's Transform. This is very similar to the Radon Transform as isolates main features of the image to determine the angle and distance. However, we did not employ this method as it required us to select points within the image for the transform to occur. The underlying notion is that there are an infinite number of potential lines that can pass through any point in the image. Also, it was found to be easier to determine the angular rotation of the image using the Radon Transform, as opposed to Hough's Transform



Back to Team F's Main Page Team F: Barcode Reading from Image

Personal tools