Starting from:
$30

$24

Lab 2: Offline Signature Verification Solution

Lab Task




Take one Ref signature from downloaded dataset1 and perform the following tasks:




Develop a bounding box around the signature content.



Find out the centroid of the signature.



Segment signature from centroid vertically and horizontally (the signature will be divided into four pieces)



Calculate black to white transitions for each of the four segments.







































In case you are unable to download the dataset, you can use any image of a signature to perform this lab.












CS370: Artificial Intelligence Page 2













Description




In this section, we will walk through the lab tasks and see how to complete them. This walkthrough is to provide you a starting point for your own implementations, and hence is abstract and leaves out many implementation details. You are supposed to figure them out yourself. We will use the following signature as a reference.








































Preprocessing




Convert the signature to a binary (black-and-white) image before extracting features. With PIL, this can be done by using the Image.convert() method. For further information on how to use PIL, refer to PIL handbook at http://www.pythonware.com/media/data/pil-




handbook.pdf. At this point, your signature image should look like this:








































Task 1: Developing a bounding box




In this task, you have to locate the signature in the image and develop a bounding box around the signature content only, ignoring the white space around it.




Algorithm




left := width




right := 0




top := height




bottom := 0




for x in (0, width) and y in (0, height)




color := image.getpixel(x, y)

if color
is 0
if
x right


right := x
if
x < left


left := x
if
y bottom












CS370: Artificial Intelligence Page 3













bottom := y




if y < top




top := y




After completing this task, your signature image should look like this:








































Task 2: Locating the centroid




Centroid is the point where center of mass of the signature image is located. It can be computed using the algorithm given below.




Algorithm




cx := 0




cy := 0




n := 0




for x in (0, width) and y in (0, height):




if image.color(x, y) is 0:




cx := cx + x




cy := cy + y




n := n + 1




cx := cx / n




cy := cy / n




Task 3: Dividing the image at centroid to create four segments




You should have the following at this point:




Bounding box = (left, right, top, bottom)



Centroid = (cx, cy)



You now have to divide the image into four segments. The four segments can be computed by locating the boundaries of each of the four segments:




(left, cx, top, cy) are the boundaries of top-left segment



(cx, right, top, cy) are the boundaries of top-right segment



(left, cx, cy, bottom) are the boundaries of bottom-left segment



(cx, right, cy, bottom) are the boundaries of bottom-right



segment After completing this task, your signature image should look like this:













CS370: Artificial Intelligence Page 4














































Task 4: Finding black to white transitions




In this lab task, you have to find black to white transitions for each of the four segments/ blocks of the signature you made in Task3. That is, you have to calculate the number of white pixels in the neighborhood (use 8-connectivity) of each black pixel in the image. For details about pixel connectivity, refer to your famous friend










Algorithm




prev := image.color(0,0)




n := 0




for x in (1, width) and y in (1, height):




curr = image.color(x,y)




if curr is 255 and prev is 0




n := n + 1




prev := curr




Completion check




On successful completion of the lab tasks, you should have the following:




Bounding box of the signature in image



B = (left, right, top, bottom)



Coordinates of centroid of the signature



C = (cx, cy)



Four values of black to white transitions, for each of the four segments



T = (TL, TR, BL, BR)



Deliverables




Submit single word file having source code and output on LMS. Your submission should follow the following naming convention: YourName_RegNo_Section_lab02





































CS370: Artificial Intelligence Page 5



















































































































































































































CS370: Artificial Intelligence Page 6

More products