Closed jacopoabramo closed 1 year ago
After some more tweeks I found a way to do it as follows:
range = range(int(len(video)))
max = int(len(video))
with plt.ioff(), warnings.catch_warnings(), tqdm(range, desc="video drawing") as pbar, tif.TiffWriter("test_video_drawn.tif") as outfile:
warnings.simplefilter("ignore")
for idx, frame in enumerate(video): # show every 50th frame to keep file size low
fig_kw = dict(frameon=False, figsize=(frame.shape[0]/20, frame.shape[1]/20), dpi=20)
fig, ax = plt.subplots(**fig_kw)
tp.annotate(dataframe.query(f'frame=={idx}'), frame, ax=ax, plot_style=plot_style)
ax.set(yticks=[], xticks=[])
plt.axis('off') # this rows the rectangular frame
ax.get_xaxis().set_visible(False) # this removes the ticks and numbers for x axis
ax.get_yaxis().set_visible(False) # this removes the ticks and numbers for y axis
fig.tight_layout(pad=0)
fig.canvas.draw()
data = np.array(fig.canvas.buffer_rgba())
data = np.rint(data[...,:3] @ [0.2126, 0.7152, 0.0722]).astype(np.uint16)
plt.close("all")
pbar.update(1)
outfile.write(data, contiguous=True)
This is great! Thanks. I'm closing this for now but I agree that it would be a welcome pull request as an option to annotate
.
Greetings,
I'm trying to call
trackpy.annotate
after detecting the particles on my video recording. What I want to achieve is to annotate the centroids on each image, completely remove thematplotlib
background and axis and store the annotated image on a contigous TIFF file. I've come up with a working snippet which is an hack from issue #167:This script works, but what I get is the following output:
As you can see the actual video is still surrounded by the white background of the generated figure. I want to get rid of it but don't know exactly how to approach this. It would also be great if
trackpy.annotate
had an option to return the annotate image without thematplotlib
figure axes and background.