-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_centroids.py
executable file
·64 lines (46 loc) · 1.51 KB
/
view_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
# -*- 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
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("image_file")
parser.add_argument("centroid_file")
parser.add_argument("-pn", "--particlenumber", type=int, help="highlights the particle entered")
args = parser.parse_args()
# Handle IO
if not os.path.exists("outputs"):
os.mkdir("outputs")
output_name="outputs/"+"centroids_display.pdf"
# 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']
# Create and display overlay
fig, ax = plt.subplots()
plt.imshow(image,cmap='gray')
if len(x) != 0:
plt.plot(x, y, 'r.')
if args.particlenumber:
print "Highlighting particle {} in blue.".format(args.particlenumber)
if args.particlenumber > len(x):
print "ERROR: There aren't that many particles!"
else:
plt.plot(x[args.particlenumber],y[args.particlenumber],'b.')
plt.show()
fig.canvas.draw()