Skip to content

Commit 7624b49

Browse files
authored
Merge pull request #2 from StrokaLab/feature/axis-angle
Feature/axis angle
2 parents cad4259 + 5d1da3f commit 7624b49

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ $ pip install -r bin/requirements.txt
4747
```
4848
$ jupyter nbextension enable --py widgetsnbextension
4949
```
50+
51+
### Checking for Errors
52+
53+
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

code/cells/shapes.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,59 @@ def get_hull_aspect_ratios(self):
165165
ls = min([float(a), float(b)]) / max([float(a), float(b)])
166166

167167
return ab, ls
168+
169+
def get_angle(self):
170+
sorted_hull_points = self.get_convex_hull()
171+
hull_point_array = numpy.asarray(sorted_hull_points)
172+
173+
ellipse_hull = skimage.measure.EllipseModel()
174+
success = ellipse_hull.estimate(hull_point_array)
175+
176+
if not success:
177+
add_points = 10
178+
179+
while not success and add_points < 100:
180+
add_points_skip = int(math.floor(len(self.path) / add_points))
181+
182+
path = numpy.asarray(self.path)
183+
add_points_arr = path[::add_points_skip]
184+
185+
new_arr = numpy.append(hull_point_array, add_points_arr, 0)
186+
hull_point_array = new_arr.copy()
187+
188+
189+
ellipse_hull = skimage.measure.EllipseModel()
190+
success = ellipse_hull.estimate(hull_point_array)
191+
192+
add_points += 10
193+
194+
xc, yc, a, b, phi = ellipse_hull.params
195+
# need to calculate the slope of the line relative to the image, not the x,y axis.
196+
a_p1 = xc + a*math.cos(phi), yc + a*math.sin(phi)
197+
a_p2 = xc - a*math.cos(phi), yc - a*math.sin(phi)
198+
b_p1 = xc - b*math.sin(phi), yc + b*math.cos(phi)
199+
b_p2 = xc + b*math.sin(phi), yc - b*math.cos(phi)
200+
201+
# we need to invert only the apparent y-axis
202+
x_max, y_max = self.image.shape
203+
m = ((y_max - a_p1[0]) - (y_max - a_p2[0])) / (a_p1[1] - a_p2[1])
204+
image_angle = math.atan(m)
205+
image_angle_deg = math.degrees(image_angle)
206+
if image_angle_deg < 0:
207+
image_angle_deg += 180
208+
209+
#import matplotlib.pyplot
210+
211+
#matplotlib.pyplot.figure(15)
212+
#matplotlib.pyplot.imshow(self.image)
213+
#for hp in hull_point_array:
214+
# r, c = hp
215+
# matplotlib.pyplot.plot(r, c, 'o')
216+
# matplotlib.pyplot.scatter([c], [r], color='#AA3C39', marker=',')
217+
218+
#matplotlib.pyplot.plot([a_p1[1], a_p2[1]], [a_p1[0], a_p2[0]], 'y') #Change y to change color
219+
#matplotlib.pyplot.plot([b_p1[1], b_p2[1]], [b_p1[0], b_p2[0]], 'c') #Change c to change color
220+
#matplotlib.pyplot.savefig('/Users/adamlanda/Documents/JAnaP/data/testfig.png')
221+
#matplotlib.pyplot.close()
222+
223+
return image_angle_deg

code/cli/jobs/shapes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,8 @@ def __calculate_shape_data(self, image_path, perimeter_path, job_entity_row):
130130

131131
shape_data["hull_aspect_ratio_ab"], shape_data["hull_aspect_ratio"] = \
132132
shape_calculator.get_hull_aspect_ratios()
133+
134+
#adding angle
135+
shape_data["angle"] = shape_calculator.get_angle()
133136

134137
return shape_data

code/cli/output.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def generate_cell_data_file(project):
9191
# "Hull Aspect Ratio (< 1)"])
9292

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

9596

9697

@@ -167,7 +168,8 @@ def generate_cell_data_file(project):
167168
output_row.extend([shape_data.get("solidity", ""),
168169
shape_data.get("circularity", ""),
169170
shape_data.get("convex_area", ""),
170-
shape_data.get("hull_aspect_ratio", "")])
171+
shape_data.get("hull_aspect_ratio", ""),
172+
shape_data.get("angle", "")])
171173
#shape_data.get("aspect_ratio", "")])
172174
else:
173175
# Perimeter

web/application.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import inspect
33
import sys
44

5+
# TODO: Determine why this change was made
6+
import matplotlib
7+
matplotlib.use('TkAgg')
8+
59
import werkzeug.serving
610
import thread
711

0 commit comments

Comments
 (0)