简体   繁体   English

是否可以使用 Python 将低质量图像转换为高质量图像?

[英]Is it possible to turn a low quality image into a high quality one with Python?

I made a tif image based on a 3d model of a woodsheet.我根据木板的 3d 模型制作了 tif 图像。 (x, y, z) represents a point in a 3d space. (x, y, z) 表示 3d 空间中的一个点。 I simply map (x, y) to a pixel position in the image and (z) to the greyscale value of that pixel.我只是将 (x, y) 映射到图像中的像素位置,并将 (z) 映射到该像素的灰度值。 It worked as I have imagined.它像我想象的那样工作。 Then I ran into a low-resolution problem when I tried to print it.然后我在尝试打印时遇到了低分辨率问题。 The tif image would get pixilated badly as soon as it zooms out. tif 图像一旦缩小就会被严重像素化。 My research suggests that I need to increase the resolution of the image.我的研究表明我需要提高图像的分辨率。 So I tried a few super-resolution algos found from online sources, including this one https://learnopencv.com/super-resolution-in-opencv/ The final image did get a lot bigger in resolution (10+ times larger in either dimension) but the same problem persists - it gets pixilated as soon as it zooms out, just about the same as the original image.所以我尝试了一些从在线资源中找到的超分辨率算法,包括这个https://learnopencv.com/super-resolution-in-opencv/最终图像的分辨率确实变大了(两者都大了 10 倍以上)尺寸),但同样的问题仍然存在 - 一旦缩小,它就会被像素化,与原始图像几乎相同。

Looks like quality of an image has something to do not only with resolution of it but also something else.看起来图像的质量不仅与它的分辨率有关,还与其他一些东西有关。 When I say quality of image, I mean how clear the wood texture is in the image.当我说图像质量时,我的意思是图像中木材纹理的清晰程度。 And when I enlarge it, how sharp/clear the texture remains in the image.当我放大它时,图像中保留的纹理有多清晰/清晰。 Can anyone shed some light on this?任何人都可以对此有所了解吗? Thank you.谢谢你。

original tif原始tif

The algo generated tif is too large to be included here (32M)算法生成的 tif 太大,此处无法包含(32M)

Gigapixel enhanced tif千兆像素增强 tif

Update - Here is a recently achieved result: with a GAN-based solution It has restored/invented some of the wood grain details.更新 - 这是最近取得的结果:使用基于 GAN 的解决方案它已经恢复/发明了一些木纹细节。 But the models need to be retrained.但是模型需要重新训练。

In short, it is possible to do this via deep learning reconstruction like the Super Resolution package you referred to, but you should understand what something like this is trying to do and whether it is fit for purpose.简而言之,可以通过深度学习重建来做到这一点,比如你提到的 Super Resolution 包,但你应该了解这样的事情试图做什么以及它是否适合目的。

Generic algorithms like the Super Resolution is trained on variety of images to "guess" at details that is not present in the original image, typically using generative training methods like using the low vs high resolution version of the same image as training data.像超分辨率这样的通用算法在各种图像上进行训练,以“猜测”原始图像中不存在的细节,通常使用生成训练方法,例如使用同一图像的低分辨率和高分辨率版本作为训练数据。

Using a contrived example, let's say you are trying to up-res a picture of someone's face (CSI Zoom-and-Enhance style!).使用一个人为的示例,假设您正在尝试对某人的脸部图片进行高分辨率(CSI 缩放和增强风格!)。 From the algorithm's perspective, if a black circle is always present inside a white blob of a certain shape (ie a pupil in an eye), then next time it the algorithm sees the same shape it will guess that there should be a black circle and fill in a black pupil.从算法的角度来看,如果一个黑色圆圈总是出现在某个形状的白色斑点内(即眼睛中的瞳孔),那么下次算法看到相同的形状时,它会猜测应该有一个黑色圆圈,并且填充一个黑色的瞳孔。 However, this does not mean that there is details in the original photo that suggests a black pupil.但是,这并不意味着原始照片中有暗示黑色瞳孔的细节。

In your case, you are trying to do a very specific type of up-resing, and algorithms trained on generic data will probably not be good for this type of work.在您的情况下,您正在尝试进行一种非常特定类型的向上调整,并且在通用数据上训练的算法可能不适合这种类型的工作。 It will be trying to "guess" what detail should be entered, but based on a very generic and diverse set of source data.它将尝试“猜测”应该输入哪些细节,但基于一组非常通用和多样化的源数据。

If this is a long-term project, you should look to train your algorithm on your specific use-case, which will definitely yield much better results.如果这是一个长期项目,您应该考虑针对您的特定用例训练您的算法,这肯定会产生更好的结果。 Otherwise, simple algorithms like smoothing will help make your image less "blocky", but it will not be able to "guess" details that aren't present.否则,像平滑这样的简单算法将有助于减少图像的“块状”,但它无法“猜测”不存在的细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM