Area of a polygon given xml file Documentation

Naggita Keziah

Makerere University

1        Introduction

    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

  1. 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.
  2. 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.
  3. Consider the polygon below

polygon

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.

im

Determine the sum of all the “\” products

= (2*2)+(5*7)+(3*5)+(-4*-2)+(-6*-4)

= 4+35+15+8+24

= 86

Determine the sum of all the “/” products

= (5*-4)+(3*2)+(-4*7)+(-6*5)+(2*-2)

= -20+6-28-30-4

= -76

Determine the absolute value of the difference of the “\” products and “/” products:

Absolute ((86) – (–76))

= Absolute (162)

= 162

Take  1/2   of the absolute value

=  (1/2) * (162)

= 81 area of pentagon

3        Methods used

[8] .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.

[19] .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.

[93] .def writetofile (self):

Writes the image name, area of the whole image and the necrosis part. It does                               not return anything.

 

4        Citations

xml.dom.minidom

os.listdir ()

Advertisements