Python:TensorFlow PNG编码

发布于 2025-02-04 14:49:55 字数 324 浏览 1 评论 0原文

我试图找出原因,为什么此代码段返回false:

decodedBase64 = tf.io.decode_base64(imgBase64)
decodedBase64==tf.io.encode_png(tf.io.decode_png(decodedBase64))

可以压缩PNG图像并decode_png检测到它,因此我在encode_png中使用了不同的'compression ='值。我仍然在-1到9之间的所有值都被错误。

可以采取什么措施来检索正确的解码器64特性以使Encode_png< - > DECODE_PNG可逆?

I'm trying to figure out the reason, why this code snippet returns False:

decodedBase64 = tf.io.decode_base64(imgBase64)
decodedBase64==tf.io.encode_png(tf.io.decode_png(decodedBase64))

A png image can be compressed and decode_png detects it, so I used different 'compression=' values in encode_png. I still got False with all values between -1 to 9.

What can be done to retrieve correct decodedBase64 characteristics to make encode_png <-> decode_png reversible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2025-02-11 14:49:55

我对TensorFlow并不熟悉,您的代码无法尝试使用,因此我可能错了,如果是这样,我会删除答案。我还认为Base64编码和解码是一种红鲱鱼。我认为您实际上是在问为什么与TensorFlow进行编码时,您已经从已有的PNG中获得了不同的PNG。如果是这样,有几个可能的原因:

  • 日期和时间可以在PNG中编码,因此,如果您编写PNG,然后再用相同的压缩1秒再编写,如果
  • 原始PNG可能 是这种情况,它将有所不同已经使用不同的库,不同的版本或不同的参数创建,尽管您会因为编码是无损而获得相同的像素,但磁盘上的编码数据可能会有所不同。例如,一个库可能会为某些行选择一个不同的过滤器 - 当然没有过滤器

,如果您想要确定的而不是投机答案,则需要共享2个PNG-未修改。

I am not very familiar with tensorflow and your code is not runnable to be able to try it, so I may well be wrong and will delete my answer if so. I also think that the base64 encoding and decoding is something of a red herring. I think you are actually asking why you get a different PNG from one you already have when you encode with tensorflow. If so, there are several possible reasons:

  • the date and time may be encoded in the PNG so if you write a PNG and then write it again with the same compression 1 second later, it will differ if that is the case
  • the original PNG might have been created with a different library, a different version or different parameters, and although you will get the same pixels back because the encoding is lossless, the encoded data on disk could differ. For example, one library might choose a different filter for some rows - or no filter at all

Of course, if you want a definitive rather than speculative answer, you'd need to share the 2 PNGs - unmodified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文