 We will be revisiting some of the concepts that we had studied earlier. In the process, we will take some more examples. As we did last time, here is another example which requires use of two-dimensional arrays. This is about satellite images. There is a large lake located in a portion of land and a satellite image of that area is available. Estimate the area of the lake, so how will you do that? First of all, treat this as a real-life problem rather than a computational problem. In this real-life problem, do you know anything about satellite images? Not much, but the word image will tell you that it should be something like a photograph. Do you know about photographs? Good. Now, if you have a photograph of a land area taken from a very long distance in the z direction, say aerial photograph from an aircraft, satellite is merely an aircraft which is flying at 30,000 kilometers, a airplane flies at 20,000 meters or 30,000 meters, a satellite flies at 30,000 kilometers. Just like you can have a camera on the aircraft, you can have a camera on the satellite. So, some image has been taken. What could be the possible qualities of this image which will tell you something more about what is being captured in the photograph? So, can you speculate now? This is where you start making assumptions. Remember what I told you last time? Real-life problems will not say evaluate this expression and find the value or find out the root of this quadratic up to correct up to four decimal places. Real-life problems do not come like that. In the real-life problems, you have to first figure out that a quadratic has to be solved. You have to frame that quadratic and then solve it. So, here is a similar problem. This is a satellite image. What you have been told is that there is an area in which there is a large lake present and a satellite image is available. Imagine that it is a black and white photograph, not even color image, a black and white photograph. Now, generally, a terrain in which there is a lake will be how is it likely the lake is likely to be in a vast plain area? It is possible but unlike. Most of the lakes are found where the region is hilly region, where there are trees, where there are shrubs, where there are there is a there are rocks, black and brown rocks and so on and suddenly you will find a large water body. So, let us imagine that such is the area. What will be the peculiar characteristic of the photograph that you will see in terms of distinguishing the large water body which is lake versus rest of the area? Can you imagine? Consider the light falling from the sun on this land mass. The reflected light is what you see. Black bodies will reflect what light, hardly any light. Brown bodies will reflect brownish or grayish light. But water body will reflect light which can be seen to be very close to white. Now, it may not be exactly white but it will be brighter than most other points in the picture. So, is it not possible to analyze the picture element values of the light intensity and determine that it appears to us that these picture elements will probably be part of the lake and which are those picture elements which show the brightest possible reflection. You remember the histogram analysis that we had done. In general, you can do a analysis of pixels of any kind and determine that some pixels are higher value and some pixels are lower value around some threshold point. Now, the picture elements which are reflected from the lake need not exactly be white but they will all have values towards 255. All other pixels will have values towards 0 or 50 or 70 or 80. It should be then possible that I determine a threshold value. Elements of picture beyond that value are treated as white. Elements of picture below that value are treated as black. And everything that is white is a water body. You remember the mid-same exam problem where there were white patches in a camera. Can you now find a similarity between this and that problem? There you were to determine the area of the largest white patch. Here we are told there is one large white patch. You have to determine the area. So one problem is all. We know that if somebody gives us a satellite image of land area, I know how to determine which picture points belong to the lake, which picture points do not belong to the lake. That much is simple. But I am asked to estimate the area of the lake. Area is measured how? Square centimeters, square meters, square kilometers, square miles, square feet. In general, area has the dimensional square of something. If I have a rectangular shape, I know how to calculate the area. If I have a triangular shape, how to calculate it? If I have an odd shape like a lake, how will I calculate the area? Yes? This is a real life problem. It has nothing to do with maths. You have to estimate the area of this lake. There is no length multiplied by breadth or there is no circular regions of 2 pi r square, no cylinder, pi r h, etcetera, no regular shape, you have to estimate the area. Imagine you had actually a photograph, physical photograph. One possible thing is you put that photograph on a graph paper. You have the width and height of the entire photograph that represents the total area. On that graph paper, can you not find out if the graph granularity is small enough, every square in the graph is small enough, then how many of those granules fall inside lake and how many fall outside? So those granules which fall inside constitute the lake area. Those which fall outside constitute the outside area. If I can estimate the area of one square on that graph, then by counting the total number of square points inside the lake, I can find out the area of the lake. Now what is a digital image, if not an image drawn on a graph paper with every square as a pixel, so does it not tell you how to estimate the area? If you can find out all pixels which belong to that image, which is the lake, then by just their count multiplied by the area of that pixel is the area of the lake, very good. Now how do you find the area of a pixel? Basically we are saying we will divide this into fine granularity, a digital picture is a grid like this, this is a pixel, what is the area of this pixel, how do you estimate the area of the pixel? Let us say you need some more information about this picture, where this picture is taken. So somebody tells you all right, this picture is taken in the Sayadri mountains near Mumbai as you travel towards Pune and the region is somewhere between Khandala and Lonara. Now this is a large region, so you certainly can visit that place and find out this is the lake and by looking at the photograph this is the area around it, that much is clear. Now what? You still have to find out an area of a pixel, how do you estimate the area of a pixel? So think, have you seen a map, normal map, geographical maps? Maps represent features in that area, a political map will represent boundaries of states and districts, a physical cartographic map will represent hills and other things, a general map would represent roads and some locations of prominent points etcetera. But all maps have one characteristic which none of you seem to have noticed and that is the scale of the map, that one centimeter on this map represents two kilometers, that is how you estimate the distance between the map points, saying from here to here it is three and half centimeters and therefore it should be seven kilometers. If there is a scale on your image you would then be able to know because if there is a scale you can measure the length and width of the total image which is mapped into total number of pixel points that you have. So you know roughly the area of a picture element. But a photograph generally does not come with a scale, the fellow up there in the satellite has no clue on the actual scale, so he will just send you an image. So how do you determine the scale? So let us look at the physical problem of a map, you have given a map, somebody has forgotten to write the scale map, you have got the map now and say let us say take a simpler problem. In a map I want to determine the distance between some two points which are known to me, for example somebody has said this is the map of the region between Khandala and Lonavala or somewhere around that vicinity and let us say two prominent points, one village is there, somewhere here there are some trees and when I go to that region I can see this village and I can see those trees maybe about a kilometer or so. Can I not do the following, can I not go to one of the houses here and start walking towards these trees measuring the distance as I go along? Suppose this turns out to be one kilometer, then I know on the map whatever is the distance in centimeters or whatever is equal to one kilometer, can I not determine the scale of a map like this? I will have to do that, determine the scale, then come back to my digital image and say this digital image is so many centimeters by so many centimeters when I print it, this is divided into so many pixels by so many pixels. Now can I not know what is the area of a pixel? Second, is it right to assume that my pixels are square? Have you generally seen photographs to be square photographs or rectangular photographs? There is an aspect ratio of the photograph some height and width and you may do it as a portrait or landscape but that is the general ratio. So it is not really true that my pixel will be squareish but I will know what is the total height of this area and what is the total width of this area in terms of kilometers now because I have measured this and that will be equal to H number of pixels and W number of pixels, will I not know now exactly the dimensions of individual pixel, the resolution of an individual pixel. So if this is a pixel, let us say let us assume a rectangular pixel it could be like this or like otherwise. Now I will call this as horizontal resolution say resolution H and this is the resolution in width. No it is the other way round. Well horizontal resolution is like this, H is height actually and vertical resolution. So let me call it Rv is the vertical. This will tell me a pixel covers how much area. By the way in general when you talk about satellite images, satellite images already satellites already know what is the resolution of their camera. They also know at what height the satellite is flying. So it is possible to state with a pinpoint accuracy that a digital picture taken by that satellite each pixel will cover so many meters by so many meters that is called the resolution of the ground. In fact the GPS systems that are used by most people offer a resolution of 7 meters. That means you can determine the longitude and latitude of where you are from that GPS equipment using that satellite which is positional view to the accuracy of plus minus 7 meters. And the satellites which are now coming up for the general civilian usage will reduce it further to 6 meters and 5 meters. But such resource computing satellites or what you call digital imaging satellites. These are not satellites meant for general purpose people. These are satellites meant to fly on specific area and they have much higher resolution. One meter by one meter resolution is common in this satellite. And as we progress the resolution is coming out to be smaller and smaller and smaller. But this is additional information not related to this problem. Just wanted to tell you that having thought so much we should understand a little bit more about digital images. Coming back to the problem I would now like you to note we started with a problem statement which says a large lake is located somewhere estimated area if you are given a digital image. Before even you could think of doing any programming you had to resolve so many issues. And without resolving these issues you would not be able to write a correct program because you do not know what assumptions to make. So whenever such problems appear you will have to make assumptions. Some of the assumptions are stated here. One image has W pixels per row and has H rows. So H is the height. You know all digital images you count width in the positive x direction and y increases downwards. Typically that is the way you take origin as the top left corner of the image. So there are W pixels per row and it has H rows. So this is W and this is H. Next each pixel has a resolution. Actually I have made a mistake here it should not be R H we will call it R W sorry. So R W by R V meters and values of W H R W R V are known and are part of the image data. Later on then I will put up a bitmap image format a file called something dot BMP. You will notice that each BMP file has a header of 56 bytes. And those 56 bytes contain a whole lot of information which includes the width and height which includes the horizontal and vertical resolution which includes the color scheme of the image whether it is monochrome or color which includes how many bits per pixel are encoded. All of these information is there in 56 bytes. And this is followed by the actual image data in bytes. That is how the actual images are stored. These are all binary files. They are not stored as your what you call conventional text files and so on. However we generally deal with text files because we are used to inputting data on a keyboard where you type ASCII characters and you expect a C in statement or some such similar statement to take these character strings as 121, 255, 0, 72 etcetera and convert them into integer numbers internal. So that is how we will assume that these values are known as part of the image data and the image data format is something like this. So I have stored it in a text file. Line 1 contains the values of w, h, r, w and r, h. r, w and r, h are irrelevant format determination of which pixels lie on the lake. They are useful only from the point of view of estimating the area in square meters or square kilo w and h however are important because that will determine how will I read the data. And the next assumption says that next line will contain all pixel values in first row. So suppose the first row has 800 pixel value then first value will be written as say 124, 1 blank, 78, 1 blank or 2 blanks whatever normal way in which you feed integer values one after other blank blank blank blank blank and you presume that the enter is placed while editing this data file while preparing this data file only when the entire first row is entered that is possible that is for me. In fact you know that if you use C in statement to read the data in it is not necessary that an entire row be accommodated on one line only. You could actually put only one value per line does not matter. All that the assumption states is that first w number of values will come belonging to first row. Next w number of values belonging to second row. Why it is important because you want to assign in a two dimensional matrix the actual image values appropriate. If w is not known then you would not be able to know how many values to put in the first row and the second row and third row. Of course you may call it 0th row first row second row. With these assumptions now how do you solve the problem? Now this is a programming you have been given a data in a file which is a text file. Let us make assumption about the name of the text file. So what would you like to call it? Let us say image data dot this is the file. Of course if it is a text file and I know I am going to read only this text file and I know I am not going to now prompt the user give value of w, give value of h, give first row pixel values etcetera. Because I am most certainly not going to type out these values on the terminal. Anybody who is lion hearted enough to type 800 by 1200 image pixel values on a terminal nobody would do that. Nobody in the right mind would do that. So you would expect this data to be read from a file. We have made a simplifying assumption that it is a text file and therefore the best thing for us is to write our program and then use input read direction to read all the data because no other data needs to be read real. Only this data is required. So if my program is let us say prog dot CPP then the way I will carry on with this is I will say C plus plus prog dot CPP and I will simply say dot slash a dot out redirect the input from you understand this now. So there is no input to be typed on the keyboard. Whenever input is large you will invariably use this. Later on we shall see that this may not be adequate. Suppose I have to read data from a file and also read data from input. How will you do that? Normally you cannot using the read direction. If you say redirect then every C in statement that you write in your program will take the data only from that file. It will be disconnected from your keyboard. So whatever input you give on the keyboard cannot be taken. If you want to read from both keyboard and the file then in your program you must explicitly open this file and read from that file explicitly using F read statements or F get C F get S or F scan F kind of statement. Then only you will read from that file and then your C in statements will ordinarily come from the keyboard. You will of course not use redirecting. So these are the alternate. So having said this now we need to solve the problem. How do we count the number of pixels in a satellite image which has a value bigger than some threshold T? I have to declare my data structures. How should I declare the picture element values? Let us say I say int P for picture. I have to declare the size of P, number of rows, number of columns. Any suggestions? This is another assumption I am making. Please note that we have assumed h and w values will come from the file but we do not know what those values are. What are the likely values? Again you have to make some assumptions and they have to be realistic assumptions. So reasonable assumptions as I said. Now what is reasonable in this case? So speculate. Think anybody? You tell me what will you speculate? You are speculate so you are not responsible for what you say. 2000 by 2000. Any other numbers? 5000 by 5000. Any other number? Nobody is suggesting 20 by 20. Everybody agrees that 20 by 20 will be a scam. It will not contain a probably good image at all. So we are very clear of what is on the low side. Nobody is suggesting 1 lakh by 1 lakh because mentally inside your thinking you are very clear that 1 lakh by 1 lakh will be too large. So all of you are sort of hearing around somewhere between 2000 and 5000. This is not necessarily based on your actual knowledge of any satellite image but this is based on common sense. You are perfectly justified in writing a program using your common sense but you must explicitly state the assumptions that you are making. You must state that the assumption you are making is that an image at the most is 2000 by 2000 or 5000 by 5000. What is another area on which this will depend? The size anyway. Let us assume 5000 by 5000. What is the total number of points? This 5000 by 5000 represent? 5 into 5 is 25. 6 zeros after 25. How many? Sorry, 20. 2.5 crores. How many million? 25 million points. Each integer value is how many bytes? 4 bytes. 25 million into 4 bytes will require how much of how many of bytes of memory? 100 million bytes. Today you are fortunate because even your small PCs have 2 gigabytes of memory. There was a time when memory of a personal computer used to be 64 kilobytes. 64 kilobytes. Satellites were there even then and people were processing those images. How would they do that? They could not do it putting an entire image in an array. It was not possible. Later on there was a time when the PCs had memories which were typically 64 MB, 128 MB or even 256 MB. Many of you would have seen some older PCs which are 256 MB RAM. In a 256 MB RAM, when there is an operating system, there are some overheads of the compiler libraries and other things and your program code itself, will you always be able to put aside 100 megabytes? Now this is another thought which must occur to you that whatever I am declaring as the size, is it feasible in the computing environment that I have? And even if it is feasible in your computing environment, you must make a note of it so that when other people try to run their program, they should know that they could not run it on a machine with a smaller memory configuration. So that is the minimum they should. We proceed with this now. I am not putting a semicolon here. I am just putting a comma because one style of writing program is to keep adding variable names or array names as I require them in my program. Since no c out needs to be given because I know that I am going to read the data from a file, I can directly read which things I can read W, I can read height, I can read the resolution on the horizontal side and I can read resolution on the vertical side. I have read four values. I must therefore declare all of them and please remember while writing in your programs whether you are writing it for your lab or practice or at home or in an exam and particularly in an exam, do not postpone the declaration of the variables much beyond after you write them. The moment you write them, you go ahead and add that because later on what will happen is something will remain undeclared and one of my TAs will read a half mark very happily for that. So do not make such mistakes. Next what do I read? I have to read now the image data and how is image data organized? W pixels first of the first row, then second row, then third row. How many rows are there? H number of rows. How many columns are there in each W? So it is very simple. Is this ok? Is this statement syntactically correct? The declaration of I and J is not done. Now is it correct? This is another habit I would like you to develop as professional programmers. When you write a portion of the code, then and there itself revisit that code to check whether the semantics or what you want to write is correctly written and check whether all variables are declared or not. This way you will avoid having to come back again and again and cross check. This works in an exam, this works even for writing programs. In fact there are a few programmers I have seen in last 40 years. Every year I see some who write their program once and it works correctly. There is no syntax error, there is no semantic error. That is professional program. Depending upon C plus plus compiler to tell you 200 errors is one way of simplifying your task. But it is a guaranteed way of not becoming an expert programmer who has trained his or her mind to perfection and that is what you should attempt while writing itself. So I have read the picture array now. What do I have to do now? I have to count the total number of pixels which fall within the lake region and that count itself if I print that is an indication of what is the area or if the resolution is given let us say in terms of meters then those number of pixels multiplied by r h and r v will be equal to the area of the lake. So I am going to count the number of pixels which are in the lake. I will need a variable called count. Since I am going to proceed to counting I must start with count equal to 0. This much is very clear. Now what do I do? Again I have to set up an iteration. Now I have to examine each picture point and compare it with what? Please remember at this point in my program I have a certain value of i and a certain value of j. So in that large image I am actually examining i comma j th element. I am at that point. So p i j is well defined and can be accessed at this point. Now this value if it is larger than certain threshold then we have said it belongs to image. If it is smaller than certain threshold we say it does not belong to lake sorry the first one belongs to lake and the other one does not belong to lake. So all that I need to do is if the value of this pixel is greater than that threshold what is that threshold? Made any assumptions suggest sorry 128. So he is doing a very sophisticated estimation that total white would be 255 complete black will be 0. The region is likely to have a pressure of things but he is presuming that all lake pixels will reflect a light intensity which is 128 or more. This is reasonable and this is quite okay but I would suggest in case of digital images two possibilities. One is to make an assumption slightly on the higher side so that because 128 if you look at the black and white or monochrome images 128 while it could be occasionally because of a dull image the lake may reflect that but it could also be the pixel values of some surrounding area particularly a patch of land which is sort of whitish or less brownish. However any number that you assume is perfectly fine as long as it is towards 255. So for example here will the assumption 78 be reasonable? The assumption 255 is more reasonable than 78 although both may be wrong because 255 is an exact white reflection which is unlikely to happen. So we will make here a statement PII greater than let us say we will put it arbitrarily as 200 and here we will state threshold 200 assured. So this is your assumption. Please note that all the assumptions which I have stated there are best written as a part of your program itself. So after you say IO stream and using name space STD either before that or after that nobody prevents you from giving a larger comment which says this program is written by me. It supposedly analyzes an image data from a satellite it identifies the region of a lake and estimates its area following assumptions are made. So whatever English you have written in your notebook you might as well write it in your program and then that becomes your programming style. So your thinking proceeds along with the program writing. However the thinking is done first program writing is done and therefore these assumptions or any statement that you wish to make about your algorithms should precede your program. Ordinarily you may write them on a notebook separately but you may also include the majority of those observations or assumptions in your program. This is called inline documentation as opposed to an external document and one is not the replacement for other. Both are considerably important. Anyway if that is so then what do you want to do? Simple and now you have to calculate. Agreed? So everything is correct. Something else is required here. Area is not declared. Now suddenly it should occur to me that area is not likely to be integer square kilometers. Is it likely to be integer square kilometers? No. In fact any area in real life will have some fractional value. I have made certain assumptions. The resolution of the horizontal scale and the resolution of vertical scale of a pixel I have assumed to be integer. If that is so then that assumption must be stated in terms of integer meters. In real life if you know the total number of pixels and let us go back to the previous slide here. I jumped the gun by several slides. So if this was my assumption made earlier and I had declared in my program R H and R V to be integer then I know that I have perhaps made a compromise somewhere. Having made that compromise I will continue to write here area and close the chapter because my program has ended with very clear understanding that this is the assumption that I have made. Then the resolution better be in terms of centimeters or in terms of whatever unit people are confident of having that integer value as a result. But that is not my responsibility that is somebody else's responsibility. However imagine that you are not merely a programmer but you are also an expert in interpretation of digital images and you are advising let us say the resources ministry of Maharashtra to tell them that this is the area of the land covered by water body. Then you want to be as exact as possible then you will have a team sent to that Khandala-Lonawala region to measure actual area as clearly as possible. Take the total number of pixels and not depend upon R V and R H which is given as that satellite image but determine that independently by actually locating all the boundaries on this point, this point, this point, this point. You will have a scale which will say 1 centimeter is equal to 0.839 kilometers. You will go to that level of resolution because you want to be exact as exact as possible. This is what you will do in real life but in programming you will notice that whichever way you resolve the other issues your program here which starts by counting count equal to 0, reads this image data and calculates this and gives you the estimated area of the lake as area is as accurate as possible. In terms of programming problem you have solved the problem. Now we will go further. We will say that look this is the water body but I want to know the contours of the lake I want to know what is the perimeter. Suppose I start walking around the lake say today morning 7 o'clock and walk at 4 kilometers an hour robust speed. How many hours it will take me to come back to this point that is perimeter? Radhakshina, how will I determine the perimeter? Yes, estimate the perimeter of the lake. The total number of pixels on the boundary of the lake how will you estimate that? All the other assumptions that you have made stand yes. Any other suggestion? He is suggesting that count all the pixels which have a value greater than 200 but which has an adjacent pixel which are not all 200 greater than 200. Here we introduce the notion of neighbors of a pixel. Suppose this is a pixel which i comma j that you are looking at. Then how many neighbors does this pixel have? 1, 2, 3, 4, 5, 6, 7 and 8. The 8 neighbors when will be a pixel on a boundary? Some of the neighboring pixels are belonging to lake and some of the neighboring pixels are not belonging to lake. Even if one pixel does not belong to the lake then I must be on the boundary. Very simple. If I am somewhere here imagine I am me and I have these 8 neighbors. Now I have to examine all my neighbors. White, white, white, white, white, white, white. Then I must be inside the lake. If I examine my neighbor black, black, black, black, black, black, black, black, black, black then I am outside the lake. Now examine neighbors white, white, black, black, oh some blacks. Who am I? White. Then I am on the border. If I am black, am I on the border? If I am black, no. Because I am not part of the lake. Border of the lake is defined by those points which are in the lake but on the border. So I must be white to begin with. However suppose I count all pixels which have at least one non-white neighbor. Will my estimate be wrong? Without caring for who I am. If I did that what will be I counting? That is I am saying I do not care who I am but I examine all my neighbors and if any one of those neighbors is non-white or the other way round. If any one of those neighbors is white then I count myself to be on the boundary. Will that be correct? If I did that I will be counting even myself when I am just outside the lake. So two conditions. One, A I should be white and B I should have at least one non-white neighbor. At least one non-white neighbor. As long as I have one non-white neighbor I am on the boundary. Now if I count all such pixels they will amount to what? The pixels on the boundary. But how will I calculate the perimeter? Perimeter is a distance measure, length measure not area measure. How will I do that? Ok. So let us look at some of the pixels. If I have a pixel on the boundary here then the length of the pixel is equal to the vertical resolution because it happens to be on something like a straight line. If I have a boundary pixel in this region then the length of the pixel is equal to horizontal resolution. If I have a pixel in some region like this here which is on the boundary then the length covered by it is equal to the diagonal of the pixel and it is not very easy to determine who is on the diagonal, who is horizontal, who is vertical and then some chokers will be neither horizontal nor vertical nor diagonal. In short we recognize that determining the length of the perimeter accurately is a harder problem. It is not very straightforward, not very simple. But I can make reasonable approximation and I can say that every pixel represents an average of this length, an average of this length. Suppose I made assumptions that the average length is somewhere between it is larger than the height of it, but it is lesser than the diagonal. Will I be accurate? I do not know. I am speculating everything depends upon the shape of the lake. If the shape of the lake is very arbitrary, if it is elliptical then there will be more pixels which will cover only the horizontal resolution and very less which will cover the, so this is not an easy area to estimate. However, I can do the following. I can say that look I will produce an output which will give you all pixel coordinates on the boundary and I will also give you the total number of those pixels. Now based on the boundary you determine what you want to do. So that is a reasonable assumption about programming problem. I am converting a physical problem into a programming problem saying that I do not know how exactly to calculate. Given more time I will do it. In 10, 15 minutes I cannot work that out. But permit me to do the following. Whenever I determine a pixel on a boundary I will output its coordinates and at the end I will give you total number of pixels of the boundary. Is that a reasonable approximation of the problem solution? The original problem said find the parameter. This is what you will notice. In an exam you will get specifically to determine the number of points on the boundary or coordinates of the points. In real life you always have to solve problems which involve physical dimensions and therefore some additional work. Now here what is the issue when you have to do such counting? Please note that you have two outer iterations already maintained. For i equal to something to something for j equal to something to something. And inside those two iterations you are sitting at i comma j. Now you have to examine all the eight neighbors of i comma j. How will you do that? How will you examine all neighbors of i comma j? Suppose p i j is me and I first examine whether I am lake or not. So if I am lake now I have to examine whether anybody around me is non-lake. If it is not lake then I have to increase the count. If everybody is lake then there is no issue. So if the non-lake count is more than zero then I am on the boundary. But I already have one fellow called count upstairs which is counting the total number of pixels which I will still use to count the total number of pixels on the boundary now. So I need another count which is called the neighbor count. Amongst my neighbors how many neighbors are non-lake? I want to count. So how will I write my program? I imagine now here that I already have this setup. I want to examine neighbors of p i comma j. Provided p i comma j is lake not other one. So if it is not lake I do not have to do anything. I can just go to the next iteration. So one statement which I can write here is if p i j what was the threshold that we had taken? Two hundred. So greater than or equal to two hundred or greater than two hundred? Greater than two hundred. Greater than two hundred. So if I say this is less than two hundred then I can simply say continue less than equal to two hundred then I can say continue. You know understand what continue is continue will break the innermost loop it will go to the next value of j. And therefore I have nothing more to do with this picture. So if I am not why if I am not lake then I have no reason to examine my neighbors. I come here only if I am lake now I have to examine all my neighbors. But I require an additional count. Suppose I say in n count this is the neighbors count or if you want l n count is the lake neighbor count is equal to zero. Now what kind of statements I will make if just look at this. If I am i comma j my i minus one j comma minus one is my diagonal neighbor above me on this side. If that fellow is not lake then I have to count one who is p i minus one j fellow above my head. I am i j i minus one is the previous row j is the same column so the pixel above me same thing I will have to do this for each one of my eight neighbors no shortcut sorry he is suggesting introduce a variable k and l and run a loop k equal to k varies from minus one to one l varies from minus one to one. And then p of i plus k and j plus l is less than 200 then l n count plus plus so I will have one for statement another for statement and this is therefore one way of doing it. When I finished everything my l n count will determine whether I am I am that image or not let me go forward and implement what he is suggesting for example I will say in k l what will be the maximum value I will come to that. Suppose k and l is equal to 0 I am examining p i j that is myself although I have already said continue there is no point in examining it but if I introduce this then I do not have to examine whether I was right or not because I am also getting examine in the process if I am less than equal to 200 count will become one. It is unlikely that others are all white around me if I am non white then one of my neighbors is also non white otherwise the lake will have a hole ok. So therefore this is also ok if the count is l n count is non zero can I say I am on the boundary so here what is happening is if I maintain let us look back at my program here if I have already said that if this particular statement look at if p i j less than equal to 200 continue that means I will never come to this point if p i j was not lake I will never come to this point. So even if this statement is executed it will not do any harm because it will not add anything to my l n count. So my l n count will still be correct now all that I need to do is if l n count is greater than zero that means around me there is at least one fellow who is non lake that means I am on the boundary whatever statement you want to learn and of course so you will add one to the count count this time is not the count of pixels which are inside lake but the count of pixels which are on the boundary do you agree that this program will give me the total count of pixels on the boundary and therefore when I when I come out I will have the total count printed and inside if I wanted I could print the coordinates of each of the points on the boundary ok the next problem ok I will have to draw this again let's say this is my lake unfortunately in real life when you have a large water body there are also small water bodies around it so when you have a large lake like this there will be a small pond here there is a small pond here there is a pond here ok there are some people who have gone for camping let's say a group of your people have gone for camping and you have put up tents and all those tents are white tents as far as the satellite is concerned the poor fellow cannot distinguish between the roof of a white tent and the water body he is just looking at the reflection so you also get counted as lake this also gets counted as lake that is not the intention of the real life problem the real life problem says that there is a large water body which is lake now Mr. Remote Sensing Expert or Miss Remote Sensing Expert please understand that there may be small water bodies here and there please ignore them and give me the area and the contour of the largest portion can you now see the similarity between the problem of the mid-same exam which said that you have multiple white patches and you have to determine the area of the largest patch this is one of the physical problem reasons why such a requirement will arise in practice there could be many such things how will you solve this problem for any one area you know how to calculate for any one region you know how to calculate the area so I will just leave this hint and work it out maybe I will put up this solution on the web the solution is that as you scan the pixels row by row when you come to the first row where you find a pixel which is white which is on the lake then you stop there and you freeze that i, j for example now you determine all the pixels which form the boundary and the region surrounding this area which is the connected area the connected area may be only one pixel long isolated pixel the connected area may be 28 pixels some 2 pixels in the first row 3 in the next row 5 in the third row 3 in the second row but all connected no discontinue you can scan the subsequent rows and again examining the neighbors you can determine whether you have the connected area or not you are not examining anything else now there might be another water body here there might be another water body here you are not looking at you are looking only at the connected pixels by looking at the neighbors in the next row of the pixels which belong to the lake in the previous row you will determine whether they are connected or not and you can keep on doing that you have isolated this region in a separate area structure I store this region I continue my scan when I come here I have no more pixel in this region now I go back to this i, j where I was I had left and I start examining this row again is there any lake pixel no I again come here is there any lake pixel yes there is one however this is part of an area which I have already identified so I can ignore that I continue here I come to the next row I come to the next row I suddenly find out a pixel which belongs to another area now this is not part of the earlier area which I have got this is a new area I do exactly the same thing I freeze i, j at this point and I examine all neighbors till I cover this entire area please note that when I come here I may if I go forward I may find some other water body but I will not go forward because I am only looking at connected pixels the next pixel here will be black so it is it is not part of this so I will find out all the connected area like this and I would have got another area identified in another area now I go back to this i, j and I again start scanning again so do I find anything here when I go to the next row I will find some pixel here but I will know that it is part of already scanned area that means while examining every pixel I have to determine two things a whether it is lake and b whether it is part of already scanned lake if it is already scanned lake I ignore it if it is a new lake like for example here I will find this even if there are twenty such areas fifty such areas hundred such areas I can put them into different hundred matrices I can have either a three dimensional matrix or I can have a two dimensional matrix where I say start point end point or whatever now that problem is bit more tricky but that is the problem that you will have to solve for a real life scenario so I will put up that solution on the web in the context of this problem and it is exactly the same thing as the problem that was given in the mid-sem so you will know the answer thank you so much