如何在 Torch 中倾斜图像

How to skew an image in Torch

我正在尝试扭曲图像以将其输入到神经网络中,但我似乎不知道该怎么做。似乎提供我正在寻找的东西的库不多。

它最好适用于 torch.FloatTensor

类型

编辑:实际上,函数 image.warp 看起来很有前途,但 warp_test.lua 并不是特别有用。我只是想将 x 中的图像倾斜不同的量

这是一个简单的版本:

require 'torch'
require 'image'

local function skew(input, factor)
  local w, h  = input:size(3), input:size(2)
  local y     = torch.range(0, h - 1):view(h, 1):expand(h, w)
  local x     = torch.range(0, w - 1):view(1, w):expand(h, w)
  local field = torch.Tensor(2, h, w)
  field[1]    = y
  field[2]    = torch.add(x, factor or 0, y)
  return image.warp(input, field, "bilinear", false, "pad", 0)
end

local output = skew(image.lena(), 0.25)