Skip to content

Commit

Permalink
compute stats in cm instead of px
Browse files Browse the repository at this point in the history
Former-commit-id: 329b50873c414e729209198a5673a5884ff18b52
  • Loading branch information
Javi Ribera committed May 8, 2018
1 parent 84e70db commit 85d94d8
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions scripts_dataset_and_results/spacing_stats_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
parser.add_argument('--hist',
metavar='DIR',
help='Directory with histograms.')
parser.add_argument('--res',
metavar='DIR',
type=float,
default=1,
help='Resolution in centimeters.')
args = parser.parse_args()

# Import GT from CSV
Expand All @@ -39,26 +44,29 @@
# 2. Compute distances (chain-like) between plants
dists = list(map(distance, locs[:-1], locs[1:]))

# 3. Statistics!
# 3. pixels -> centimeters
dists = [d*args.res for d in dists]

# 4. Statistics!
mean = statistics.mean(dists)
median = statistics.median(dists)
std = statistics.stdev(dists)
means.append(mean)
medians.append(median)
stds.append(std)

# 4. Put in CSV
df.loc[idx, 'mean_intrarow_spacing'] = mean
df.loc[idx, 'median_intrarow_spacing'] = median
df.loc[idx, 'stdev_intrarow_spacing'] = std
# 5. Put in CSV
df.loc[idx, 'mean_intrarow_spacing_in_cm'] = mean
df.loc[idx, 'median_intrarow_spacing_in_cm'] = median
df.loc[idx, 'stdev_intrarow_spacing_in_cm'] = std

# Save to disk as CSV
df.to_csv(args.out_csv)

if args.hist is not None:
os.makedirs(args.hist, exist_ok=True)

# 5. Generate nice graphs for presentation
# 6. Generate nice graphs for presentation
# Means
fig = plt.figure()
n, bins, patches = plt.hist(
Expand All @@ -69,7 +77,7 @@
plt.xlabel('Average intra-row spacing [cm]')
plt.ylabel('Probability')
plt.title('Histogram of average intra-row spacing')
plt.axis([10, 30, 0, 0.3])
plt.axis([5, 30, 0, 0.3])
plt.grid(True)
plt.legend()
fig.savefig(os.path.join(
Expand All @@ -86,7 +94,7 @@
plt.xlabel('Median of intra-row spacing [cm]')
plt.ylabel('Probability')
plt.title('Histogram of medians intra-row spacing')
plt.axis([10, 30, 0, 0.3])
plt.axis([5, 30, 0, 0.3])
plt.grid(True)
plt.legend()
fig.savefig(os.path.join(
Expand Down

0 comments on commit 85d94d8

Please sign in to comment.