【发布时间】:2015-03-23 22:27:39
【问题描述】:
假设我想知道image.lena() 的高度和宽度。我应该调用什么方法?指向图像方法资源的链接会很好,因为 Torch help 命令在这种情况下不起作用。
【问题讨论】:
假设我想知道image.lena() 的高度和宽度。我应该调用什么方法?指向图像方法资源的链接会很好,因为 Torch help 命令在这种情况下不起作用。
【问题讨论】:
image.lena() 返回一个 Torch 3 维张量,其中第一个维度是通道数(RGB 图像为 3 个),最后一个是通道数。图片的高度(nb. of rows)和宽度(nb. of columns)。
所以你需要做的就是使用size(dim)方法如下:
require 'image'
local img = image.lena()
print(torch.typename(img)) -- torch.DoubleTensor
local nchan, height, width = img:size(1), img:size(2), img:size(3)
print('nb. channels: ' .. nchan) -- 3
print('width: ' .. width .. ', height: ' .. height) -- 512, 512
【讨论】: