Area of a polygon given xml file Documentation
- This document explains imagesarea.py code. It gives the general description of all the methods used, how they work and the citations used.
2 General Overview
- I first looped through the folder containing xml files representing the images. The os.listdir (path) method returns a list containing the names of the files which end with .xml in the directory given by path. The names of the xml files were then put in a list.
- Then I parsed each xml file and got the objects within the file. Each xml file contained one or more necrosis objects and one area object. After getting the objects, I got all the points and their respective x, y coordinates which I used to find the area of each object. Shoelace formula was used to calculate the area of the object that formed a polygon shape.
- Consider the polygon below
The procedure for finding the area of the polygon is as explained below:
Select a vertex and travel around the pentagon ending with the starting point. Write a matrix of the coordinates of the path including both the starting and ending coordinates.
Determine the sum of all the “\” products
Determine the sum of all the “/” products
Determine the absolute value of the difference of the “\” products and “/” products:
Absolute ((86) – (–76))
= Absolute (162)
Take 1/2 of the absolute value
= (1/2) * (162)
= 81 area of pentagon
3 Methods used
 .def loopThroughFolder (self):
This method loops through a folder with a specified path, it collects all files with a .xml extension and puts them in a list .It returns names of all the xml files in the folder.
 .def areas (self):
Here I parse the xml document, get the x, y coordinates of the necrosis part and the whole image. The method returns an image details list which includes the following; image name, area of the necrosis, and area of the whole image.
 .def writetofile (self):
Writes the image name, area of the whole image and the necrosis part. It does not return anything.