Skip to content

Commit

Permalink
new get_length, new get_horizontal_slices
Browse files Browse the repository at this point in the history
  • Loading branch information
thoklei committed Jul 16, 2019
1 parent 776a811 commit fd31ce1
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 2,820 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
# git rm -r .ipynb_checkpoints/
#


### non-auto-generated shit ###
*.jpg
*.bmp
*.png

### LaTeX ###
## Core latex/pdflatex auxiliary files:
*.aux
Expand All @@ -24,7 +30,7 @@
*.cb
*.cb2
.*.lb
*.jpg

## Intermediate documents:
*.dvi
*.xdv
Expand Down
Empty file removed code/augmentation.py
Empty file.
61 changes: 38 additions & 23 deletions code/feature_extraction.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
# last changes from RR and SSW at 2019/09/12
"""
This file contains functions for manually extracting certain properties from pre-processed asparagus
pieces and the utility functions that are needed.
"""

# import area
import matplotlib
import numpy as np
import scipy.stats as stats
import skimage.measure as measure
from scipy.ndimage import label, find_objects
# import from own scripts (have to be in the same folder!)
from preprocessor import binarize_asparagus_img, filter_mask_img, verticalize_img
from utils import *

def get_horizontal_slices(img, k, min_row):
"""Get the start and end values of a asparagus piece in a certain row.
def get_length(img):
'''Simple length extraction
The length is measured from the highest white pixel to the lowest in the binarized image after rotation
Args:
img: the image
Returns:
length: the length in millimeters from highest to lowest point, under the assumption that one pixel
corresponds to 4 pixels
'''
img = rotate_to_base(img)
upper, lower = find_bounds(img)
length = lower - upper

This is helper function for the curvature_score.
return length/4.5

Args:
img : image
k (int): Number of slices
min_row (int): First row of the asparagus piece
def get_horizontal_slices(img, k):
"""
Calculates the x-coordinates of the outline of the asparagus pieces, measured at k evenly
spaced horizontal slicing points.
Returns:
horizontal_slices: Pairs of values for each of the k rows
img = the preprocessed image
k = the number of slices
returns: an np array([a1, a2],[b1,b2] ... ) where a1,a2 = x-coordinates of asparagus outline
"""

# binarize and filter the image with functions from preprocessor.py
img_mask = filter_mask_img(binarize_asparagus_img(img))
# get the slices
slices = get_slices(img, k, min_row)
horizontal_slices = np.zeros((k,2))
# find the first and the last 1-value in the row and save it in horizontal_slices
for i in range(k):
start = np.argwhere(img_mask[slices[i]]==True)[0]
horizontal_slices[i][0] = start[0]
end = np.argwhere(img_mask[slices[i]]==True)[-1]
horizontal_slices[i][1] = end[0]
upper, lower = find_bounds(img)
slice_points = np.floor(np.linspace(upper+50, lower-20, k))

def slice_img(img, sp):
sp = int(sp)
bin_img = binarize(img, 20)
line = np.nonzero(bin_img[sp,:])
left = line[0][0]
right = line[0][-1]
return left, right

return horizontal_slices
return np.array([[left, right] for left, right in [slice_img(img, sp) for sp in slice_points]])

### legacy from here on ###

def curvature_score(slices, horizontal_slices):
""" Returns a score for the curvature of the aparagus piece.
Expand Down
40 changes: 0 additions & 40 deletions code/good_style.py

This file was deleted.

86 changes: 0 additions & 86 deletions code/manual_feature_extractor.py

This file was deleted.

551 changes: 0 additions & 551 deletions code/notebooks/check_violet-Copy1.ipynb

This file was deleted.

89 changes: 0 additions & 89 deletions code/notebooks/extractor.ipynb

This file was deleted.

Loading

0 comments on commit fd31ce1

Please sign in to comment.