matplotlib savefig在colab中作为空白图像导出
您好,我正在使用Google Colab在图像上进行一些图像处理。
在进行上述处理并进行了一些评估之后,我想用matplotlib保存数字。
这是我的代码:
def get_images():
frame_images = glob.glob("/content/images/*.jpg")
for n in sorted(frame_images):
print(n)
images = matplotlib.pyplot.imread(n)
yield (images)
def process():
frames_in_sharp = 0
sharpened_image = None
dark_frames = 0
capture = True
frame_count = 0
for (frame) in get_images():
lower = frame.max()
if lower < 120:
dark_frames += 1
if dark_frames > 18 and sharpened_image is not None:
fig1 = matplotlib.pyplot.imshow(sharpened_image, cmap = "jet")
matplotlib.pyplot.savefig(f"/pictures/{frame_count}.png", dpi=1000)
matplotlib.pyplot.show()
matplotlib.pyplot.draw()
frames_in_sharp = 0
sharpened_image = None
else:
if capture and dark_frames > 18:
sharpened_image = numpy.asarray(cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY), numpy.uint32)
frames_in_sharp = 1
dark_frames = 0
if frames_in_sharp > 0:
frames_in_sharp += 1
plus_frame = numpy.asarray(cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY), numpy.uint32)
values_k = numpy.zeros(numpy.shape(sharpened_image), numpy.uint)
numpy.copyto(values_k, plus_frame, where = plus_frame > 10)
sharpened_image += values_k
frame_count+=1
process()
当我运行此操作并尝试其他在线发现的其他不同组合时,我会继续写一个空白的白色文件。 matplotlib.pyplot.imshow
正确显示图像。
我在做什么错?
Hello I am using Google Colab to do some image processing on images.
After doing said processing and doing some evaluations I want to save figure with matplotlib.
Here is my code:
def get_images():
frame_images = glob.glob("/content/images/*.jpg")
for n in sorted(frame_images):
print(n)
images = matplotlib.pyplot.imread(n)
yield (images)
def process():
frames_in_sharp = 0
sharpened_image = None
dark_frames = 0
capture = True
frame_count = 0
for (frame) in get_images():
lower = frame.max()
if lower < 120:
dark_frames += 1
if dark_frames > 18 and sharpened_image is not None:
fig1 = matplotlib.pyplot.imshow(sharpened_image, cmap = "jet")
matplotlib.pyplot.savefig(f"/pictures/{frame_count}.png", dpi=1000)
matplotlib.pyplot.show()
matplotlib.pyplot.draw()
frames_in_sharp = 0
sharpened_image = None
else:
if capture and dark_frames > 18:
sharpened_image = numpy.asarray(cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY), numpy.uint32)
frames_in_sharp = 1
dark_frames = 0
if frames_in_sharp > 0:
frames_in_sharp += 1
plus_frame = numpy.asarray(cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY), numpy.uint32)
values_k = numpy.zeros(numpy.shape(sharpened_image), numpy.uint)
numpy.copyto(values_k, plus_frame, where = plus_frame > 10)
sharpened_image += values_k
frame_count+=1
process()
When I run this and try other different combinations I have found online, I keep getting a blank white file written. matplotlib.pyplot.imshow
shows the image correctly.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ola @devman3211 o/
我也是Google Colab用户:)
您是否检查了图块是否尊重您的状况?
如果是的,请尝试更改
not sharpened_image是无
sharpened_image不是没有。。
您必须尊重一定优先级,请考虑以下情况以下情况:
工作证明:

结果( for Fun ):

Ola @devman3211 o/
I'm a Google Colab user too :)
Have you check if the plot respect your condition?
If yes, try to change
not sharpened_image is None
forsharpened_image is not None
.You have to respect a certain order of priority, update your code considering the following:
Proof of work:

Result (for fun):
