Commit 92895a3d by Jigyasa Watwani

added code to find area enclosed by the contour

parent d9e3725c
Showing with 17 additions and 12 deletions
......@@ -4,15 +4,15 @@ import pandas as pd
from matplotlib.widgets import Slider
from scipy.spatial import ConvexHull
def perimeter(X, Y):
def perimeter_area(X, Y):
points = np.column_stack((X, Y))
hull = ConvexHull(points)
N = len(hull.vertices)
value = 0
perimeter_value = 0
for i in range(N):
value += np.linalg.norm(points[hull.vertices[i]] - points[hull.vertices[(i+1)%N]])
perimeter_value += np.linalg.norm(points[hull.vertices[i]] - points[hull.vertices[(i+1)%N]])
# The (i+1)%N part ensures that after the last vertex, we go back to the first vertex, creating a closed loop
return value
return (perimeter_value, hull.volume)
def long_axis(x, y):
x_diff = x[:, None] - x
......@@ -21,16 +21,16 @@ def long_axis(x, y):
return np.max(distances)
# NOTE: check perimeter and long_axis functions on known shapes
# x = np.array([1, 0, -1, 0])
# y = np.array([0, 2, 0, -2])
# print(long_axis(x, y))
# x = np.array([1, -1, -1, 1])
# y = np.array([1, 1, -1, -1])
# points = np.column_stack((x, y))
# hull = ConvexHull(points)
# print(perimeter_area(x, y))
# print(long_axis(x, y))
# raise SystemExit
file = np.loadtxt('xy_coordinates_movie15.txt')
file = np.loadtxt('xy_coordinates_movie1.txt')
number_of_pixels = file.shape[0]
time_points = file.shape[1]
time_array = np.arange(0, 5*int(time_points/2), 5)
......@@ -84,14 +84,19 @@ plt.xlabel('Time')
plt.ylabel('Length of the long axis')
plt.show()
# find the perimeter
# find the perimeter and area
perimeter_array = np.zeros(int(time_points/2))
area_array = np.zeros(int(time_points/2))
for k in range(0, int(time_points/2)):
perimeter_array[k] = perimeter(x[k], y[k])
perimeter_array[k], area_array[k] = perimeter_area(x[k], y[k])
plt.plot(time_array, perimeter_array, marker='o', linestyle='None')
plt.xlabel('Time')
plt.ylabel('Perimeter')
plt.xlabel('Time (min)')
plt.ylabel('Perimeter ($\mu m$)')
plt.show()
plt.plot(time_array, area_array, marker='o', linestyle='None')
plt.xlabel('Time (min)')
plt.ylabel('Area ($\mu m^2$)')
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment