There are times when we need measurements for things we do not have at the moment and we only have an image of it. What do we do if we can’t measure it ? Of course we won’t cry! Let’s measure it anyway … with a laptop (or desktop PC) and SciLab!

Let’s start with an easy one, regular shapes (polygons with equal lengths). I chose to use a diamond in this one.

Breaking down the steps, we need to

- Get the edge coordinates
- Use math.

Easy, right? We’ll be using Green’s theorem (GT) to compute for the area of the white space.

Before we go further, let’s talk about GT and why it is useful in measuring the areas.

GT is an identity that is relates the curl of a function to a double integral. In short, we get an area if we take a closed curve and process it using Green’s theorem. The form of GT is shown below.

If this seems difficult, then let’s break it down a bit by choosing and . We now have

If we recall our integral calculus, the left side of the equations is the area. So if we add the two equations, we’ll get

or

Now taking consecutive pixel coordinates and adding seems to be easy enough.

Getting back to the main steps,

### Step 1: Get the edge coordinates

Importing image in SciLab is easy. In this case, make sure the image is in gray scale so we can work in a single channel environment only. This means dealing with only one matrix and one matrix is enough of a burden!

input into SciLab. To get the edges, the syntax is . This line of code returns Boolean values for each pixel: T for white and F for black pixels. To extract the coordinates of the edges, we use and viola! Edges.

**Step 2:** Arrange the edge coordinates

Since we need the curve to be continuous and we also need to sweep the values in a counter-clockwise direction, we should arrange the coordinates properly.

**2.1 Arrange!**

to arrange it in a counter-clockwise direction, let’s get the angle of each points relative to the polygonal center.

**2.1.1 get the center**

since the polygon is a regular one, it’s center can be easily located if we get the average value of both x and y coordinates. Note that we can also do this to irregularly shaped shapes however it should be convex or without any concavities. Then,

**2.1.2 get the angle**

offset the coordinates from the image coordinates with (0,0) located at the upper-leftmost corner to (0,0) located in the polygonal center.

Then take the arctangent of each points. The corresponding angle obtained should be unique for each points

**2.1.3 arrange the points with respect to the angle**

sort the points in increasing order of the angle (theta), this will sort each of the Xs and Ys to be sorted in a counter-clockwise manner

**Step 3: Apply Green’s theorem**

The value that we’ll get is the area in square pixels. To convert it to actual measurement, refer to Digitize hand-drawn figures with Excel – An AP187 Activity.

Now that’s we know how to do it, let’s apply what we’ve learned here to get the area of an actual location via Google Maps! Since GMaps measures distance too, we can check our work later on.

Let’s choose for example the main library of UP Diliman.

I darkened other parts of the image to make it look like the one we prepared a while back. I also measured the area of the library from GMaps. It is 3486.37 m².

Following the steps we talked about, it yielded 10560 sqare pixels or 3487.9112 m². Very close to the GMaps measurement! YAY!

One software application that also can also measure image distances/lengths is ImageJ. However, there should be at least one known length within the image to correctly calibrate the program.

Let’s try this scanned ace of spades from a PAGCOR deck of playing cards for example.

Since it’s known dimension is 2.5 x 3.5 inches or 6.35 x 8.89 cm, we can calibrate ImageJ to measure for us.

To calibrate, start ImageJ and open an image (File > Open) you want to measure. Then using the Straight function, trace the side of the image that you know the measurement.

After dropping the straight line, go to Analyze and choose to Set Scale.

We can now input the known distance of that side and get a scale of the image dimension to the real world measurements.

After all this, we can freely choose any side or area we want to measure. For example, i measured the area of the card and also the area the lone spade occupies in the center. In the image below, the 1st measurement was the clipped card, the 2nd measurement is the approximate area of the clipped part, and the 3rd is the measurement of the spade in the middle.

If we try to measure how accurate this is, the supposed area of the whole card is supposed to be 6.35 x 8.89 cm or 56.4515 cm². Subtracting the clipped area, then we’re looking at 55.8795 cm²! That’s just a mere 1.46% deviation from what we computed and that’s accurate enough for our purposes.

After all of this, I think I can rate myself 10/10 for the activity. Although it became difficult for me despite the topic being easy, I always put a lot of effort in making the write up as easy to read as possible. Thank goodness I still end up completing the activity. It wouldn’t be possible with the help of Louie and Patrick for unending patience teaching and answering my simple questions.

References:

- Activity Handout
- Paul’s Online Math Notes – Green’s Theorem

## Leave a Reply