Beg*_*ner 5 image-processing python-3.x deep-learning tensorflow pytorch
我正在尝试通过在规则间隔的 100*100 网格上采样控制点来实现弹性变形,其中 \xcf\x83 = 20 以及图像的双线性变体和掩模的最近邻。\n我找到了DeepMind 的 TensorFlow 实现。 \n到目前为止,我使用下面的实现作为 lambda 转换 -
\ndef elastic_transform(image, alpha=1000, sigma=20, spline_order=1, mode=\'nearest\', random_state=np.random):\n"""Elastic deformation of image as described in [Simard2003]_.\n.. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for\n Convolutional Neural Networks applied to Visual Document Analysis", in\n Proc. of the International Conference on Document Analysis and\n Recognition, 2003.\n"""\n#assert image.ndim == 3\nimage = np.array(image)\nassert image.ndim == 3\nshape = image.shape[:2]\n\ndx = gaussian_filter((random_state.rand(*shape) * 2 - 1),\n sigma, mode="constant", cval=0) * alpha\ndy = gaussian_filter((random_state.rand(*shape) * 2 - 1),\n sigma, mode="constant", cval=0) * alpha\n\nx, y = np.meshgrid(np.arange(shape[0]), np.arange(shape[1]), indexing=\'ij\')\nindices = [np.reshape(x + dx, (-1, 1)), np.reshape(y + dy, (-1, 1))]\nresult = np.empty_like(image)\nfor i in range(image.shape[2]):\n result[:, :, i] = map_coordinates(\n image[:, :, i], indices, order=spline_order, mode=mode).reshape(shape)\nresult = Image.fromarray(result)\nreturn result\n
Run Code Online (Sandbox Code Playgroud)\n但上述实现的问题是它使用样条插值。\nPyTorch 是否有任何 TensorFlow 等效项(我上面指定的那种),或者是否有任何其他方法可以实现我的要求而无需切换到 Tensorflow?
\n 归档时间: |
|
查看次数: |
803 次 |
最近记录: |