 Good morning and welcome back. I have some questions here. I will try and answer them. Question from online university is actually an observation that I send my question through email to workshop support. Just please check it and answer the same. Yes, I will do that. Unfortunately, I do not have access to email here directly, but I will get to the workshop support. The second question is technical from Amruta Puri. Can all recursive functions be mapped to an iterative operation? Generally, the answer is yes. They can be. Although the resultant implementation may not remain as elegant as you see in a recursive implementation. You may want to use some specialized data structures to implement recursion. Stacks are particularly important in this context. There was one more question there. Yes, it was from Pune. Can we do our project in C++? The answer unfortunately is no. I will tell you the reason. The projects that you will do later on till April are supposed to contribute to the contents of this subject portal. Since this subject, as we have all agreed, is around the basic programming which is universally in this country taught using C or a procedural language. Therefore, we will restrict the projects for this particular thing in C program. As I promised earlier, we shall have a separate workshop on object-oriented programming during which time you will be free to do a project in either C++ or Java, depending upon whatever we choose. Let us get back to the discussion. As I had mentioned, there is a query that image processing or image representation and handling should be discussed in some greater details. That is what I am going to do today. First, I will describe the mechanisms available for representing digital images. Then, we take a specific image type namely the fingerprint image and see what kind of analysis can be done of that image. First, some basics. Image is represented in some standard digital file formats. There are tools and utilities to handle these formats. We will be discussing a particular file representation called XPM representation. This is not a very popular representation for handling large images. It was meant for a different purpose which I shall explain, but it is an extremely simple representation to understand. We will then look at a sample program which uses an image represented in this XPM format and does something useful with it. Tomorrow morning, I hope to demonstrate to you how fingerprint images are retrieved from a scanner and how scanner software and application programmer interfaces are used to write a program which connects the scanner to my computer and we can actually capture fingerprint images. Now, please understand that a digital image could blow up in size very, very quickly. Consider a modern camera which you often designate in terms of number of megapixels that it is able to capture. A 12 megapixel camera that means a camera which can take a picture containing 12 million pixels can produce an image with the size of 36 million bytes. Why? Because each pixel will typically a color image pixel will have value for red, value for blue, value for green each represented in an 8-bit number. Consequently, each pixel will be represented by 3 bytes and you will end up with a huge image of 36 megabytes. Clearly, it is not conducive to handle such large sizes for individual images and some compression becomes necessary. Compression can either be lossy or it can be lossless. There are many formats. The two most popular ones is a JPEG format. Almost all photographs that you see sold on digital machines are JPEG photographs. It is a lossy format but it gives very acceptable quality. In fact, reasonably good quality. Bitmap format can be completely lossless although it also provides for compression. As I said, compression need not always be lossy. There are several other formats available. Incidentally, a file containing an image which is in JPEG format will typically have an extension not JPEG or not JPG. Similarly, a bitmap format which was sort of defined first by Microsoft in a very popular format has an extension dot BMP. There are many other formats also. We now describe a peculiar format which is called XPM format. The most file formats hold binary data because a value let us say 0 to 255 as an intensity value for a black and white image is best reprinted as a 1 byte number. But these data values are not visible to us because they are not in a printable format. They are in internal binary format. Consequently, they need to be read by a machine. They need to be processed by a machine. All that we can see is a photographic output or a digital output again in terms of internal representation which is converted by some utilities such as Photoshop, photo editors or photo displaying tools which can display that image on a digital screen. There was a need felt of what we call editable format specially to create icons using normal text editing. Icon are short symbols. You know which are typically used in advertising agency. So in 1989 a group of people in France defined this format. Group Bull Research Center. Bull incidentally was one of the large computer manufacturing company and they had a very, very well established research center that is where these people were working. This format is very peculiar in that it is an ASCII format. So actually you can print the contents of a file as ASCII characters and you can actually see what the contents are because the description is simplistic and still well contained. So let us look at what this format looks like. This format has lines of text describing an image. The first line incidentally all lines of text together will actually form a component of a ASCII program. So that is how this format is defined. The first line always contains the word XPM enclosed in slash star star slash. You will notice that this is nothing but a comment in scene. The second line says static care star some name, PIXMAP name like my major image or whatever. Notice that this is an array and this is being defined as equal to opening brass followed by string, string, string, string, string. So in fact this is nothing but a pointer to an array of strings. So this is effectively then a two dimensional array. The picture is a two dimensional array. The first element is a row. So there are number of rows which will be equal to the number of lines in the image file and number of columns. Each column will correspond to a string here. The first string is value string. The next string is color string. There could be multiple colors used to represent individual pixels. So these are not colors but actually color codes and then there are many lines corresponding to pixels. So if you have an M by N image you will have M rows of N pixels each. Each pixel is represented not by a single value but by one or more ASCII characters. Consequently the number of characters describing one row of image could have many more characters than the number of pixels that you have. If one pixel is represented by two characters then you will have twice as many number and so on. We will look at an actual image in a short while to understand exactly how this XPM format works. So to recapitulate the first line of a file containing XPM format image will contain the word XPM preceded by slash star and followed by star slash. The next line will be a fixed line which says static care star and this will be a name. Typically it is not uncommon to give the same name as the file name in which the image is stored. That file name typically has an extension dot XPM and in terms of semantics this whole structure defines contents of a C program. So all of this can be incorporated in a C program. In fact that is how programs were written to handle these images. The image itself becomes part of a structure of a C program. This has subsequently number of lines. First it has a single line called value string. We shall see what exactly that value string is. Then we have one or more lines describing the color codes and then you have as many lines as there are rows in the image. Let us look at some details. First of all what is a value string? The value string contains values width, height, number of colors and characters per pixel and these values are four values 1, 2, 3, 4 separated by blanks and these values are enclosed in double quotation mark at the beginning and double quotation mark at the end followed by a comma. So this is actually a string. The next one is called a color string which is array of key and color values and each element of this string is something like key, then a color code C and an excitation value of the color again written as a string. So there are three items in the string, a key code. The key will consist of one or more ASCII characters chosen by you arbitrarily and these ASCII character codes will represent a particular color. The color value itself is given by this excitation. How many bytes will be there in key? Well that will be determined by the value string characters per pixel. If you have said that there will be one character per pixel the key will be one byte long or one character long. This will have to be a printable character by the way. So one character does not give you too many printable characters about 126, 127 if you use ASCII code. It is not uncommon to have two characters representing a pixel because combination of two characters can represent literally thousands of values. So this then is the color code character followed by the hexadecimal value of the color. If you are using two characters per pixel these two could be absolutely any arbitrary characters of your choice. You can say x dot a, a, b, t, z, q whatever you choose. Wherever that combination occurs in the actual pixel representation that is supposed to mean this particular hexadecimal value of the color. So consequently you have as many lines as different color codes you have or effectively as different gray level possible or color level possible in your image pixels. Please note that each picture can have its own color code. I have utilized this fact to define my own color code here and then there are pixel strings. How many pixel strings? Well if the picture is width, number wide and height number rows then this pixel strings will be as many pixel strings per row. So if height is height then there will be height number of rows and each row will contain width multiplied by the cast per pixel characters. Essentially then pixel string is also a string and notice how the string is written. It starts with a double code then it has these series of characters. These will represent by the way the actual color code corresponding to a pixel. So for example if x dot x and dot is used to represent let us say certain value of red, certain value of blue, certain value of green then wherever x dot occurs it will mean that that pixel is of the same color. And this combination will depend upon the kind of color coding that you have used and the kind of actual values that exist in the digitized image originally captured. But suffice it to say that even each pixel string is written actually as a string. It has a double or first of here at the beginning, it has a double or first of here at the end and a comma. So these are comma separated strings that you will find in XPM file. Here is a sample image. This is called a dot image by the way. Incidentally the image is restricted to this area. So this is actually the image. It in fact looks like a dot if the aspect ratio is correct. But look at how and in fact if you interpret this and show it on a screen you will actually see a small dot here. So let us see what this file contains. The first line is an XPM comment. The second line is static care star dot. Dot is the name of the file. This is an array. This is followed by a value string which reads 5521. If you recall what the various data items were in this line, the first one is width, the second one is height. So it is a 5 by 5 image. That means this has 5 rows of pixels and in each row there are 5 pixels. In fact it is a very small image of 5 pixels by 5 pixels or 25 pixels and that is why you will see when you represent this as a digital image you will see a dot. Notice the color coding scheme that they have used. It says two characters are used to represent each color. There are two colors in the whole scheme and one character is used to represent colors. That means the pixels here are capable of showing only two colors. They need not be black and white by the way. For example one color can be red, one can be blue, one can be black, another can be magenta, whatever be your choice. That is the reason why a two color image can be represented by this and can be correctly interpreted. So once again it says this is a 5 pixel by 5 pixel image. It has two colors and each color is represented by one character. This is now followed by the color code key strings. So let us see what these strings are. This is the first one. This string has a dot. That means dot is a symbol used to represent a color. What is that color? The color is given as an hexadecimal code 0 0 0 0 0 0 0. That means this color is all zeros and what is all zeros? All zeros is black. So the dot represents a black. Here you have an X. What does X represent? This code says X is a color with a value hexadecimal ff 0 0 0 0 0. Typically these are sort of hexadecimal numbers. So that means this is one byte, this is second byte, this is third byte. And traditionally the first byte is supposed to represent the intensity of red, second byte of green and third byte of blue. Since green and blue components are zero, this color is actually red. Consequently you have a black and red image. The black is represented by a dot and the red is represented by X. This is followed by 5 rows of 5 pixels each. Notice what these pixels contain. Dot dot X dot dot. That means the first pixel color is black, second pixel color is black, third pixel color is red, fourth is black, fifth is black. This one has first as black, next three rows one black. This one has all five red. This one has one black, three rows one black. And this one has two blacks, one red, two blacks. It is a very simplistic image. It is an icon of a dot. But you can see that this simple coding scheme can be extended to represent the most complex image that you can come across. So for example, instead of a 5 by 5 image, you may have a 500 by 500 image or 300 by 400 image. Instead of two colors, you may have 1000 colors. Depends upon what kind of different colors you want to represent. And instead of using one character to represent a particular color value, you can have two characters represent a color value. You generally do not need three characters. Two ASCII characters in combination give you adequately large number of colors to be represented. Suppose we had gray scale images. I had mentioned last time that gray scale image is nothing but a black and white image. Incidentally fingerprint images are all gray scale images. So each pixel is a shade of black to white. It is not pure black and white. A black and white is called a monochrome or monotone image. So monotonous that means either black or white. Every pixel has only two colors. And a gray scale image has shades of gray, shades of white, shades of black, whatever. And gray scales can be represented as a 1 byte pixel value internal. So the numerical value associated with the pixel can be between 0 to 255. It adequately represents a gray scale image. But if we want to represent a gray scale image using an XPM format, then what you can do is that first you can represent a gray scale by choosing color keys or color codes which are identical red, green and blue pixel components. Please remember that 0 red, 0 green, 0 blue will mean black. FF red, FF green and FF blue will mean white. And an equal combination in any other value will mean a different shade of gray. For example hex 0 0 0 0 0 is black, hex FF FF FF FF is white and hex 808080 is an intermediate shade between black and white. So all shades of gray can be represented in this mechanism by using actual colors. Of course you have to say this is the color value that you would like to have a pixel to have. You will have to give a code in terms of one or more ASCII characters. Clearly one ASCII character will not be sufficient. So you will use two ASCII characters to represent a color. And once you have decided what is going to be your color coding scheme, you can then based on the actual values of the pixel of the gray scale image, you can convert that pixel value in the appropriate key combination of two characters and then write those many characters in your file resulting into an XPM file representation of a gray scale image. Here is a sample fingerprint XPM file. So this has slash star XPM star slash static care star 80 0 percent 2. This is an arbitrary file name that I have given. This means left thumb. Zero error trial that is the first time you capture. Person 2 means person number 2. This is, this would roughly be the file name that you will use although it is not mandated. Now the string itself says width height encolors cares per pixel. This is included as a command. And what are the values? 352, 544, 256 and 2. What does it mean? To recall from our previous explanation, 352 is the width. 544 is the height. That means this particular picture has 544 rows and each row has 352 pixels. We are saying that totally there will be 256 colors. Obviously it is a gray scale. So 0 to 255 will be the colors and each color will be 0 0 1 0 1 0 1 0 2 0 2 0 2. Remember what I said, red, green and blue in exactly equal measure will constitute a gray shape. And finally this value string says that each of these 256 colors will be represented by two ASCII characters. Which two characters? Experient format does not say that you have to use these specific characters to represent this color. It says use absolutely any combination of two characters that you want. However, please define in the same file what that particular code means. For example, I have chosen to use capital A and small a to represent full black. So this is where AA is defined as colors 0 0. Capital A small b is defined as colors 0 1 0 1 0 1. Capital A and small c is defined as this color. And since this is going to successfully go over from 0 to 255, 255 remember in hexadecimal will be ff ff ff. So the scheme that I have chosen is extremely simplistic. Although I will write these details in an xpm file. But by looking at the code I can very quickly determine what the color is. Why? What I am doing is I am keeping capital A constant for the first set of letters and varying a b c d e f g h etcetera. Not 26 times, not up to 0, but say 25 characters in arbitrary choice. After finishing the first 25 characters of the small alphabet, I change the first character on the left hand side from a to b. And next 25 are reprinted as b a b b b c b d etcetera. The subsequent next 25 are reprinted c a c b etcetera etcetera. And I continue this till I have reprinted all 255 elements. Observe that this simple coding scheme permits me to quickly calculate the gray value of a pixel given its code. We shall see in the program how exactly these calculations are done very simply. Here is a fingerprint image of a person. You might see it as slightly blurred image and that happens because the image is a gray scale image. So it is neither white nor black. You will notice that the background is all white. There are in between blackish lines, but not fully black lines. Now what you would like to do is you would like to sort of stretch it first and digitize it to a black and white image. So if you do what we call a histogram equalization and convert this image into a pure binary image, 0 or 1, you may get a picture of this type. This is another picture. So these are fingerprints of two different persons. I have used this illustration to tell you a well known fact that fingerprints are unique. As you can see here, although both are fingerprints, this fingerprint has a pattern which is significantly different from the pattern that you see on this fingerprint. And anybody by visual inspection can say, look this fingerprint belongs to somebody else, this fingerprint belongs to somebody else. Even if you have fingerprint of the same person taken at different times, here is a set of images captured at different times. Both these fingerprints belong to the same person. By the way an expert can see very clearly that they are similar. However, it is interesting to note from a digital image point of view that there is a slight tilt in one image with respect to another one. There is a slight shift also. Consequently, these particular patterns that you see here somewhere around this excess, you will see that these patterns here are somewhere around this excess. That means this particular fingerprint it was kept on the scanner was kept at a slight angle and not the entire surface was covered exactly in the same way as this surface was covered. This in fact is the greatest problem in handling digital images. Ordinarily, when we compare two entities, we are used to comparing exact values. Is value of m equal to n? If it is, we say they are same, otherwise they are not same. In this we will be tempted to say that if we have let us say 500 by 300 image, then each pixel point we can compare with the corresponding pixel point. And if all pixel points agree in value, we say the image is same. Very unfortunately image analysis completely prohibits this kind of simplistic comparison because a very small change in the image could cause huge differences in comparison. This small change of about 5 degrees change in the orientation of these two fingers will ensure that a point to point comparison of pixels will never be able to establish equality. Consequently, we have to look for patterns on the finger. And these are the patterns that we are talking about. These patterns incidentally are called minutiae. Say minutiae are patterns which are characterized or identified because what you see here as these lines, these are called ridge lines and valleys. There are sort of technical terminology which will not go into the details. Suffice it to say from a computer programming perspective that even if we represent these two images as a two dimensional array of pixels of grayscales, a pixel by pixel comparison is completely ruled out for any kind of establishing the fact whether these two fingerprints are of the same person or different person. But that is a later issue. First we consider whether the quality of the image that you get by this process is adequate in a grayscale. The answer is no because there is very little clarity. We would like to therefore enhance this image. You will remember we had talked about contrast enhancement by equalizing the histogram. The best technique for a grayscale image which is actually a fingerprint kind of pattern and not really a scenery or something is to convert 0 to 255 values into 0 and 1 value. When you do that, the processing of grayscale image will convert this into a bi-tonal image. Now how do you convert it into a bi-tonal image? Very simple. You have values ranging from 0 to 255. You can arbitrarily decide that any pixel value which is less than 128, it is black, otherwise it is white. Or you may use a better threshold such that the average pixel value in the image is used as threshold. This exercise is very simple to do. You take an image, read the xpm file decoding the cores that have been used and convert the pixel image into internal values. Internal binary values, each value we put into 1 byte and there are as many bytes as there are height multiplied by width number of pixels. Now having this digital representation, you can simply look at each pixel. If the pixel value is greater than certain threshold, you may announce it to be white. If it is less than certain threshold, you may announce it to be black. Visibly the quality of the image improves significantly as can be seen by a few slides here. So here again is image of a fingerprint of a person. Incidentally, I have used dot bmp5 in my slides. You can take these out, convert them into jpeg. You can convert them into xpm file. However, most modern tools like photoshop, photo editors or photo display tools etc. are not capable of displaying xpm file directly. But almost all these tools come with a conversion. So you can say convert this into bmp, this into jpeg, jpeg into this or whatever. That is what I have used to display it for your benefit. Digitally of course, it is a set of values organized as a two dimensional matrix whose dimensions are defined by width and height of the particular image. So if this is the image of the fingerprint of a person, then by converting a grayscale image into a monotone image or a bi-tonal image, 01 image, you will get something of this sort. Well, instead of the picture becoming clearer, we seem to have lost clarity. This picture appears to be better. Why this has happened? This has happened because we have arbitrarily chosen to generate this image by using a threshold which is 120. The threshold cannot be arbitrarily set. The threshold has to be set in the context of the actual pixel values that you observe in an image. And as I mentioned earlier, using the average is a much better mechanism of getting a sharper image. If we do that, the monotone image with threshold equal to 120 becomes like this. The right hand side image is a thresholded monotone. Two things are noticeable. Every pixel in this image is either pure white or pure black. Consequently, the ridges and the valleys which we could briefly identify here are very prominently visible here. This is regarded as a much better digital image to handle in the context of fingerprint analysis. Is the threshold 180 correct? Well, we do not know. It depends upon the average pixel value here. So what I have done is I have written a program to calculate the average pixel value here and use that as a threshold consequently getting this image. You will all agree that this image is still much sharper. All that we are going to see today is to write a C program to get a fingerprint image in XPM format. Read that image, calculate the histogram, find out the average value and using that average value as a threshold, create another XPM file which is actually a binary file which is 015. And as demonstrated here, let us look at these three successive figures one after another. This first one uses 128 as an arbitrary threshold. This is the second one and this is the third one which actually uses the average pixel value. Is this the complete thing about fingerprint analysis? By no means. This is just the beginning. Please notice that the fingerprint that you now see while the minutiae and other things and the ridges etc may be slightly more prominently observable, we are not going to use human beings to analyze these images. The pattern recognition etc whatever, we hope to do it automatically using digital computers. Consequently, there are subsequent steps that are required to analyze this image automatically further. For the purposes of this workshop, we are going to limit ourselves to construction of a C program which does the limited task that I mentioned. Namely, read a grayscale fingerprint image, convert it into internal digital values of whatever m by n pixels depending upon width and height, then calculate the histogram, find out the average and use thresholding to get a sharper image. The subsequent steps by the way would be to isolate these ridges very clearly. You can see that these are thick ridges. The black is very thick here. What it means is there are several ones in adjacent rows and columns. That is why you have this thick line. The patterns which we wish to locate on a fingerprint, which we would later on wish to compare with other fingerprints, these patterns called minutiae, arches, whatever, whatever. There are n number and there is a huge amount of literature. In fact, you can again go to Wikipedia and look at digital fingerprint analysis. You will get many more interesting details or that would require image thinning for example. So, you replace all neighboring ones which appear in a bunch by one line of consecutive bunch. So, you are thinning that thing. Once you are thin lines, you can actually use directional pattern extraction or you can do identification of minutiae and their coordinates and so on. It is an extremely complex, very rich research area. We will leave that for those who are interested to read it up either through image processing books or through even popular sites like Wikipedia. Here is another captured image. Again you can see this is a grayscale image and this is its monotone version. I hope you will agree that the clarity is far superior when you convert it in this fashion. So, now we will quickly go through a program which converts a grayscale image to monotone. First, let us recapitulate the algorithm that we are going to use. We know the XPM format. So, we will use that XPM format knowledge to read the data from an image file containing a fingerprint data into our computer's memory. We will declare an image appropriately as an array which has the total number of pixels equal to width and height. The width and height information we are going to collect out of the same file anyway. Here are some comments which indicate that first I wrote this program for my CS11 course. This was written in C++ by the way. I have rewritten it in C for the IST workshop. Please note the last line copyright under creative commons. The creative commons license which we use says that this program can be distributed happily, can be dissected, can be modified as long as the copyright is retained in your program. I have included stdio.h and string.h as two header files which are required to handle this problem. Here is a host of variables and arrays that I have defined. I will describe a few important variables and structures and arrays. Unsigned char star image. So, I have defining a pointer which I am incidentally calling image but this pointer points to a character kind of entity. Now it is very obvious that the word image will mean that it will be storing one of the two images either the grayscale image or the input image and clearly the image will mean a large number of bytes. What am I doing here? I am merely declaring a character type pointer which is called image. I have another pointer which is referring to mono image. So, obviously I imply that this image will somehow be equal to the full flesh grayscale image and the second one will be containing the monotone image that I will generate out of my logic. But wait the image is supposed to be a large array preferably a two dimensional array. Here I am declaring only two pointers. This is where you will recall our discussion on dynamic memory allocation. Please note that individual pictures, digital pictures even in XPM format that I would like to analyze using this kind of program could have greatly varying heights and width. I do not therefore wish to define a fixed size array to hold my images. What if tomorrow I get an image which is slightly larger or what if I consistently get images which are just one tenth the size that I allocate and most of the memory goes free. That is why I will use dynamic memory allocation to associate memory with each one of these image and mono image respective. Then I have unsigned in n-width, n-height, n-colors, num, care per symbol. Notice that these are nothing but the values that you will appear in the second line of your XPM file. There I have defined simple variables such as C H C H 1 C H 2 unsigned int is defined as a value. Unsigned int will mean that the value can be between 0 to 255 and I specifically define a variable called v0 to mean 0 value and v255 to mean 255 value. Why do I do that? Because I know ultimately in my monochrome image the only values which should be visible are 0 and 255. Of course because my final file is going to be in XPM format the values will not be visible as 0 and 255 but they will be visible at some color code that we shall decide. I have some of columns, average, some of rows, etc, etc. Obviously I use them to calculate the statistical pattern of the image values in pixels. I have long int, hist which stands for histogram as we have seen earlier it has 256 elements and then we have pass to represent position, average, some whatever whatever you have these are various indices. Care, file line string 2000. I am defining a very large array of characters to represent a string which will come out of a single line in the file. That is why arbitrarily I have named this array to be file line string. I do expect a line to be very large. Note that this is not a simple text line that you usually see in your books or screens which is less than 80 bytes long. This is actually a string which will hold the complete set of pixels for one row of that image and if a pixel is represented by two characters then I will have twice as many entries into this array. Consequently this size has been arbitrarily defined as 2000 elements. Then I have variables or arrays again character arrays which will define a file name. The file name s simply means that the file name string is what is represented by a 20 character array. Then I have a mono file name which I have simply defined as m minus. So why I am doing that? I am actually going to construct the file name of my final file using mono file name and whatever file name user has given. So effectively if I call the original file as person1.xpm where person1 is the name of the file. Then what I will produce using this program will be called m dash person1.xpm. This m standing for monotone. This is an interesting technique and often resorted to namely that the file name itself is considered to be a very meaningful information and once you have a new file generated out of an existing file in a different format you tend to retain the name of that file as it was and either add a prefix or a suffix to that. In this particular case I am adding a well known prefix m dash. Well known meaning well easily understood and easily remembered prefix. So all the monotone files will be m dash something at the end of my program. Here are some more comments. First files are assumed to be in dot xpm format for gray scale image. The color palette is chosen arbitrary. Why I have chosen arbitrary is the color palette because if I have certain logic in my color palette then I do not even have to read the entire color palette. I know by that logic that what two characters will represent what color. For example I have given here in comments that my color palette is defined as we are having keeping capital in the first position a a a b a c etcetera then b a b b c etcetera. First character changes after every 25 symbols. Second character a b c d f g h up to y then again it is repeated and so on. You will soon see the reason for doing this simplistic codification because given any two characters when we read those two characters for a particular pixel in the image you can calculate the corresponding numerical value without ever referring to the color code. Ordinarily you will have to store all the color codes of an xpm file into an internal array and whenever you get a pixel value represented by some two characters you will have to compare these two characters with the entire color code array. Here because the simplistic choice I can actually do a numeric mapping very easily. Second for the output file I decide that I have a monotone image I have only two colors. So I will represent white by dot and black by x something that we saw very briefly in the representation of a dot image that we saw. So generating and representing a monotone image is far simpler. I have only two colors each coded by x and zero and obviously one of them will be all zeros and the others will be all f's. Let us very quickly go through the logic. First we get a file name for input fingerprint image we assume dot xpm extension. So I print a message give a file name and I correct that file name. Now I have five star image in file one and star image out file one. I am going to need two files in my program. One file is an input file which will be connected to the input image that I get in grayscale. The other file which will be connected to any physical external file which will be called image out file. This is going to be my monotonous image. What do I do here? Given a file name I open that file. We have seen that yesterday in the file operations that when I give this as the string name string then a file with that name should exist in the directory in which you are executing this program or means I am opening it for reading. Observe the syntax. I say image file one is equal to f open this, this, this. If the file actually exists which means I have not made a mistake in typing the name or something then that file will be available for further reading and so on. However if the image in file one is not equal to null then and only then I proceed further. Why this null? Well a null pointer indicates some sort of problem in the operations. In this particular case if a file pointer ever becomes null that means it is unable to find the file locate the file or hold the file or whatever. In such situation I say the image file is found and opened. Now I have to read the image file. What am I reading? I am actually reading an xpm format which means the first three lines are well just commands except one which contains the value. The most important information, width of image, height of image, the number of colors that the image has in this case they will be of course 256 and the number of characters that I used to represent each color. In this case I should actually be reading this data from the image file but I have myself created that file in the first place and therefore I know which two characters will represent which color in my image. When I say color I mean that gray scale shape. So here is what I do if image in file has opened properly then I give a message that I have found and opened the file then I skip the first three lines. Why? First three lines contain first a command with xpm written inside, second where some problem whatever the information that you had and the third one is again another command. So I just skip these lines I get from image file one I get a string. Notice that I am using f get s. f get s will get me a string from the designated file pointer which is written at the last column. How many characters should it read? Ordinarily this f get s will read as many characters as appear before the end of line symbol because it is still regarded as a text file. However if there is no end of line or new line character and you really have a large record this f get s will read as many as 1999 bytes at most and it will automatically insert a backslash zero in the remaining string. However this is simpler than what it appears to be. So in this way we have actually got a name for a file which stores the xpm photographs. Next line is height, width, number of pixels etc. So I again get a string. I can read these four values directly by the way from that line because we know how to read 3, 4, 5 values from input. The trouble is that ordinarily when I ask for three values you will be giving me three values separated by black. But here the situation is slightly different in the sense that I am using an f get s thing to get the string from an image file and from that string I will interpret the value of height, width and number of pixels. So what am I doing? This string does not contain just four numerical values. Let us go back a bit and just examine what this string would contain. Look at this string. This string has double apostrophe, one value blank, another value blank, third value blank, fourth value and a double apostrophe. Now if such a line is fed as an input line from my keyboard my scan a function etc. will be unable to extract very very important information such as this has 352 columns, 544 rows. Each pixel has 256 values and each pixel is reprinted by two characters. I may miss giving you this information and therefore instead of reading this string directly from a file I read this entire thing into a separate string then I personally take care of removing this opening double quote and possibly the last double quote and then whatever pure values remain I will read them as if I am reading them from file. Please remember we explained it yesterday I think. Get S will get you a string from standard input STD in. F get S will get you a string from a file which has been named and opened and in this particular case by getting the string separating out this double quote appears to be a far easy mechanism of processing this file. So let us quickly go over to the program which we left halfway through. So this is of course the coning scheme and so on and this is the program. I have skipped the first three lines here now I read height, width and number of pixels from the next line. So I get a character string first. Now I scan the character string from 0th position. This line obviously is bound to have two double apostrophes. Fun as the starting point and one at the end point. I have a very simple job. Go through every character of this string. The moment you find a character which is double apostrophe stop there. After that are going to be your values, width, height, num color and num care. This is exactly the logic that has been implemented here. All that I do is I start with I equal to 0 and while I is not equal to apostrophe. I am now looking for the second apostrophe. I will keep transferring characters one by one from whatever I have read into the department of CAC characters. So I have two position counters L pass and S pass. And I use these L pass and S pass to pass over the indices which are relevant here to capture the value. So I say while line I not equal to double apostrophe simply keep incrementing I. I will find someone where some character which suddenly is this apostrophe. The moment I have detected this double apostrophe double quote I know that my actual values will start flowing in from it. So I start assembling string byte by byte from the first occurrence of this double quote mark to the last occurrence preferably and store that somewhere else. What am I doing? In the second array I transfer characters from line to S. Line is what I have got. S is what I wish to create. Once I complete this my job is actually over. I will transfer these characters S pass equal to 0 line of S pass equal to double quote S pass plus plus L pass plus plus. You can verify that this code works correctly without any problem. And finally when all characters are pushed into S. Now S may have 15 characters, 20 characters, 30 characters but it will not be regarded as a string unless it is terminated by a backslash gene. So after reading as many characters from the string that you want till you get this double quote from this point onwards you start pushing L pass character into S pass character and you keep updating these numbers till such time that you get the second double quote which is at the end of the file. At which point you set backslash 0 as the contents of that particular place. Consequently you have a proper string even in your S. Notice the use of S scan F. As I mentioned to you earlier scan F is a family a function of a family which reads data from your keyboard. If I say F scan F I will be reading data from a named file for which I will have to provide a file pointer. When I say S scan F I am doing neither. S scan F will read data from a string and that string itself is designated as part of the S scan F instruction that you will see here. What it has is width, height, number of colors and num care. JPG and JPEG are same or not is a question from SJCITS. Yes, they are same. There is no difference. It is just a different file extension that you use. Thank you. We will meet after the break.