将文本添加到使用`image.mimread()```'imigio.mimread()`
我正在使用此数据分析管道,该数据线将视频录制的gif进行gif,用于此的函数是:
def make_gif(self, datafile, save_file, frame_limit:int=20, fps:int=10, verbose=True):
h5 = h5py.File(datafile, "r")
frames = h5['frames'][::2][:frame_limit]
imageio.mimwrite(save_file, frames, fps=fps)
if verbose:
print(f"Saved gif version: fps={fps}, nframes={frame_limit}", flush=True)
唯一必要的导入是h5py
image> imageio 。
我需要将一些文本附加到这些GIF。我们需要显示一些元数据以快速阅读。例如,我有一堆看起来像此图像的帧:
但是我需要的是这样的东西:
我将如何做 那是python和imageio?我应该注意,我无法将单个图像保存为jpgs以稍后重新上载,我需要创建GIF作为管道的一部分。
I am working with this data analysis pipeline that makes gifs of video recordings, the function used for this is:
def make_gif(self, datafile, save_file, frame_limit:int=20, fps:int=10, verbose=True):
h5 = h5py.File(datafile, "r")
frames = h5['frames'][::2][:frame_limit]
imageio.mimwrite(save_file, frames, fps=fps)
if verbose:
print(f"Saved gif version: fps={fps}, nframes={frame_limit}", flush=True)
The only necessary imports for this are h5py
and imageio
.
I'm needing to append some text to these gifs. There's some metadata we need displayed for quick reading. For example, I have a stack of frames that look like this image:
But what I need is something like this:
How would I go about doing that with Python and imageio? I should note that I cannot save the individual images as jpgs for reuploading later, I need to create the gifs as part of the pipeline.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们使用Imageio的重点是图像的IO侧。如果要将文本添加到图像或执行图像的任何其他处理,则需要引入图像处理库。这里的常见选择是
scikit-image
或opencv
。这是如何使用
cv2
进行此操作的示例。请注意,我正在使用a 标准图像相同的逻辑可与HDF5和其他视频/图像格式一起使用。输出:
奇怪,
scikit-image
不允许在图像上渲染文本,但是有一个古老的问题可以跟踪该功能在这里。另外,如果可视化是您所追求的,则可以使用
matplotlib
。这具有为您提供MPL的所有力量的优势,但由于失去对单个像素的控制权的缺点。这对于科学处理(像素值很重要)并不理想,但非常适合快速注释,人类消费和定性数据。这是一个示例,您可以如何重新创建上述
内容:
Our focus with ImageIO is on the IO side of images. If you want to add text to an image or perform any other processing of the image, you will want to bring in an image processing library. Common choices here are
scikit-image
oropencv
.Here is an example of how you can do this using
cv2
. Note that I am using a standard image here for better reproducibility, but the same logic works with HDF5 and other video/image formats.Output:
Weirdly,
scikit-image
doesn't allow rendering text onto an image, but there is an age-old issue to track that feature here.Alternatively, if visualization is what you are after, you could use
matplotlib
. This comes with the advantage of giving you all the power of the MPL but comes with the drawback of losing control over individual pixels. This is not ideal for scientific processing (where pixel values matter), but great for quick annotations, human consumption, and qualitative data.Here is an example how you could recreate the above:
Output: