-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_centroids.py
executable file
·79 lines (58 loc) · 1.74 KB
/
edit_centroids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Loads an image and a .npz file, and displays an overlay.
Used to determine the success of centroids.py or centroids_SP.py
inputs: image file, as a tiff (other formats compatible with skimage.io.load should work, i.e. png, etc)
centers file, as .npz
output: none
@author: BHS
"""
# Import Libraries
import numpy as np
import matplotlib.pyplot as plt
import os
import argparse
import skimage.io
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection
from matplotlib import ion
# Handle I/O
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("image_file")
parser.add_argument("centroid_file")
args = parser.parse_args()
# Output path
if not os.path.exists("outputs"):
os.mkdir("outputs")
output_name="outputs/"+"centroids_edited"
# Get image and centroids
print "Loading image and centers and generating overlay."
image = skimage.io.imread(args.image_file)
centroids = np.load(args.centroid_file)
x = centroids['x']
y = centroids['y']
spacing = float(centroids['spacing'])
# Turn on mpl interactive mode
#ion()
# Define callback event
def onclick(event):
print ("Button={}\nx={}\ny={}\nxdata={}\nydata={}".format(event.button,
event.x, event.y, event.xdata, event.ydata))
return None
# Create and display overlay
fig, ax = plt.subplots()
plt.imshow(image,cmap='gray')
if len(x) != 0:
plt.plot(x, y, 'r.')
fig.canvas.draw()
### Add code here ###
cid = fig.canvas.mpl_connect('button_press_event',onclick)
fig.canvas.mpl_disconnect(cid)
plt.show()
#raw_input("Click on a spot!")
x_edited=x
y_edited=y
# Save as .npz
print "Saving as {}.npz".format(output_name)
np.savez(output_name, x=x_edited, y=y_edited, spacing=np.array(spacing))