Skip to content

Commit

Permalink
Merge pull request #2 from StrokaLab/feature/axis-angle
Browse files Browse the repository at this point in the history
Feature/axis angle
  • Loading branch information
thomaskcr authored Jun 24, 2021
2 parents cad4259 + 5d1da3f commit 7624b49
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ $ pip install -r bin/requirements.txt
```
$ jupyter nbextension enable --py widgetsnbextension
```

### Checking for Errors

In order to check for errors after running jobs, navigate to your main repository, then go to: data / projects / 'your project name' / system / job errors
56 changes: 56 additions & 0 deletions code/cells/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,59 @@ def get_hull_aspect_ratios(self):
ls = min([float(a), float(b)]) / max([float(a), float(b)])

return ab, ls

def get_angle(self):
sorted_hull_points = self.get_convex_hull()
hull_point_array = numpy.asarray(sorted_hull_points)

ellipse_hull = skimage.measure.EllipseModel()
success = ellipse_hull.estimate(hull_point_array)

if not success:
add_points = 10

while not success and add_points < 100:
add_points_skip = int(math.floor(len(self.path) / add_points))

path = numpy.asarray(self.path)
add_points_arr = path[::add_points_skip]

new_arr = numpy.append(hull_point_array, add_points_arr, 0)
hull_point_array = new_arr.copy()


ellipse_hull = skimage.measure.EllipseModel()
success = ellipse_hull.estimate(hull_point_array)

add_points += 10

xc, yc, a, b, phi = ellipse_hull.params
# need to calculate the slope of the line relative to the image, not the x,y axis.
a_p1 = xc + a*math.cos(phi), yc + a*math.sin(phi)
a_p2 = xc - a*math.cos(phi), yc - a*math.sin(phi)
b_p1 = xc - b*math.sin(phi), yc + b*math.cos(phi)
b_p2 = xc + b*math.sin(phi), yc - b*math.cos(phi)

# we need to invert only the apparent y-axis
x_max, y_max = self.image.shape
m = ((y_max - a_p1[0]) - (y_max - a_p2[0])) / (a_p1[1] - a_p2[1])
image_angle = math.atan(m)
image_angle_deg = math.degrees(image_angle)
if image_angle_deg < 0:
image_angle_deg += 180

#import matplotlib.pyplot

#matplotlib.pyplot.figure(15)
#matplotlib.pyplot.imshow(self.image)
#for hp in hull_point_array:
# r, c = hp
# matplotlib.pyplot.plot(r, c, 'o')
# matplotlib.pyplot.scatter([c], [r], color='#AA3C39', marker=',')

#matplotlib.pyplot.plot([a_p1[1], a_p2[1]], [a_p1[0], a_p2[0]], 'y') #Change y to change color
#matplotlib.pyplot.plot([b_p1[1], b_p2[1]], [b_p1[0], b_p2[0]], 'c') #Change c to change color
#matplotlib.pyplot.savefig('/Users/adamlanda/Documents/JAnaP/data/testfig.png')
#matplotlib.pyplot.close()

return image_angle_deg
3 changes: 3 additions & 0 deletions code/cli/jobs/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,8 @@ def __calculate_shape_data(self, image_path, perimeter_path, job_entity_row):

shape_data["hull_aspect_ratio_ab"], shape_data["hull_aspect_ratio"] = \
shape_calculator.get_hull_aspect_ratios()

#adding angle
shape_data["angle"] = shape_calculator.get_angle()

return shape_data
4 changes: 3 additions & 1 deletion code/cli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def generate_cell_data_file(project):
# "Hull Aspect Ratio (< 1)"])

output_row.extend(["Hull Aspect Ratio (< 1)"])
output_row.extend(["Angle of Major Axis wrt X-Axis (degrees)"])



Expand Down Expand Up @@ -167,7 +168,8 @@ def generate_cell_data_file(project):
output_row.extend([shape_data.get("solidity", ""),
shape_data.get("circularity", ""),
shape_data.get("convex_area", ""),
shape_data.get("hull_aspect_ratio", "")])
shape_data.get("hull_aspect_ratio", ""),
shape_data.get("angle", "")])
#shape_data.get("aspect_ratio", "")])
else:
# Perimeter
Expand Down
4 changes: 4 additions & 0 deletions web/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import inspect
import sys

# TODO: Determine why this change was made
import matplotlib
matplotlib.use('TkAgg')

import werkzeug.serving
import thread

Expand Down

0 comments on commit 7624b49

Please sign in to comment.