Skip to content

Commit 15eb3c6

Browse files
adding paper figure files
1 parent e08b376 commit 15eb3c6

File tree

2 files changed

+1043
-0
lines changed

2 files changed

+1043
-0
lines changed

paper/cpsam/fig_utils.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
3+
"""
4+
import string
5+
import matplotlib
6+
import matplotlib.pyplot as plt
7+
import matplotlib.transforms as mtransforms
8+
import numpy as np
9+
from matplotlib import rcParams
10+
from matplotlib.colors import ListedColormap
11+
from cellpose import utils
12+
13+
default_font = 12
14+
rcParams["font.family"] = "Arial"
15+
rcParams["savefig.dpi"] = 300
16+
rcParams["axes.spines.top"] = False
17+
rcParams["axes.spines.right"] = False
18+
rcParams["axes.titlelocation"] = "left"
19+
rcParams["axes.titleweight"] = "normal"
20+
rcParams["font.size"] = default_font
21+
22+
ltr = string.ascii_lowercase
23+
fs_title = 16
24+
weight_title = "normal"
25+
26+
def plot_label(ltr, il, ax, trans, fs_title=20):
27+
ax.text(
28+
0.0,
29+
1.0,
30+
ltr[il],
31+
transform=ax.transAxes + trans,
32+
va="bottom",
33+
fontsize=fs_title,
34+
fontweight="bold",
35+
)
36+
il += 1
37+
return il
38+
39+
40+
def outlines_img(imgi, maski, color=[1, 0, 0], weight=2):
41+
img = np.tile(np.clip(imgi.copy(), 0, 1)[:, :, np.newaxis], (1, 1, 3))
42+
out = np.nonzero(utils.masks_to_outlines(maski[1:-1, 1:-1]))
43+
img[out[0], out[1]] = np.array(color)
44+
if weight > 1:
45+
if weight == 2:
46+
ix, iy = np.meshgrid(np.arange(0, 3), np.arange(0, 3))
47+
else:
48+
ix = np.array([-1, 1, 0, 0])
49+
iy = np.array([0, 0, 1, 1])
50+
ix, iy = ix.flatten(), iy.flatten()
51+
for i in range(len(ix)):
52+
img[out[0] + ix[i], out[1] + iy[i]] = np.array(color)
53+
return img

0 commit comments

Comments
 (0)