简体   繁体   English

使用cv2.imresize为神经网络输入调整数据大小

[英]Resizing data using cv2.imresize for neural network input

I have to scale down data to feed into a neural network . 我必须按比例缩小数据以馈入神经网络

I wanted to use cv2.imresize , but there are multiple options with regard to how it interpolates the data to scale it down: 我想使用cv2.imresize ,但是关于如何插值数据以按比例缩小它有多个选择:

  • INTER_NEAREST - a nearest-neighbor interpolation INTER_NEAREST-最近邻插值
  • INTER_LINEAR - a bilinear interpolation (used by default) INTER_LINEAR-双线性插值(默认使用)
  • INTER_AREA - resampling using pixel area relation. INTER_AREA-使用像素面积关系进行重采样。 It may be a preferred method for image decimation, as it gives moire'-free results. 这可能是首选的图像抽取方法,因为它可提供无波纹的结果。 But when the image is zoomed, it is similar to the 但是,当图像放大时,它类似于
  • INTER_NEAREST method. INTER_NEAREST方法。
  • INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood INTER_CUBIC-在4x4像素邻域上的双三次插值
  • INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood INTER_LANCZOS4-在8x8像素邻域上的Lanczos插值

Has anyone experimented with these, and if so what have you found? 有没有人尝试过这些,如果发现的话,您发现了什么? Note: I don't have enough time to try out learning with all varieties of interpolation. 注意:我没有足够的时间尝试学习各种插值方法。

For down sampling image data (I presume the data is an image since you're using OpenCV), you can just use area averaging to get good performance in terms of speed and quality (unless the downscaling factor is quite small, where blurring may happen). 对于向下采样的图像数据(由于您使用的是OpenCV,我认为数据是图像),您可以使用面积平均来获得速度和质量方面的良好性能(除非缩小比例很小,否则可能会发生模糊) )。

Nearest neighbor will drop some cells at regular intervals but will be quite fast since no interpolation is actually performed. 最近的邻居将以规则的时间间隔丢弃某些像元,但是由于实际上没有执行插值,因此会非常快。 However some aliasing is to be expected with most images. 但是,大多数图像都可能会有一些混叠

If quality is your main concern, use Lanczos (slower than bicubic, but higher quality images, generally speaking). 如果您最关心的是质量,请使用Lanczos (通常比双三次慢,但图像质量更高)。

Bicubic and bilinear are known to perform quite badly for downscaling images for factors less than 0.5. 已知双三次和双线性在缩小图像比例小于0.5时表现不佳。

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

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