【问题标题】:Given an image in Lua Torch, how can I find its dimensions?给定 Lua Torch 中的图像,我如何找到它的尺寸?
【发布时间】:2015-03-23 22:27:39
【问题描述】:

假设我想知道image.lena() 的高度和宽度。我应该调用什么方法?指向图像方法资源的链接会很好,因为 Torch help 命令在这种情况下不起作用。

【问题讨论】:

    标签: lua torch


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      相关资源
      最近更新 更多