【问题标题】:What is the difference between a matrix and image in Matlab?Matlab中的矩阵和图像有什么区别?
【发布时间】:2014-06-08 05:04:22
【问题描述】:

我可以将 .png 图像保存为pic = imread(image_name),我可以将其视为包含大小的矩阵,以便检索[nrows, ncols, ~] = size(pic)。然后,我可以使用imshow(pic) 轻松显示此图像。

但是,如果我使用 test = zeros(nrows, ncols, 3) 创建自己的矩阵并尝试使用 test(:, :, :) = pic 复制图像并尝试使用 imshow(test) 它不起作用。我可以逐个元素比较testpic,它们是相同的,但我不能将两者相减,否则会出现

错误
Error using  - 
Integers can only be combined with integers of the same class, or scalar doubles.

如何创建矩阵并将图像中的像素分配给它,并且仍然将矩阵视为图像?我试图这样做的原因是我有很多图片我想组合成一张更大的图片,所以我需要事先创建一个大矩阵,然后将每个单独图像中的像素复制到更大的矩阵中,但是这个更大的矩阵当我使用 imshowimwrite 时,不再将其视为图像。

【问题讨论】:

    标签: image matlab matrix png


    【解决方案1】:

    错误告诉你你错过的东西。重要的是变量的class。图像具有某种类类型(uint8,uint16 ...),matlab 中的通用矩阵,除非另有说明,否则为double。尝试定义

     test = zeros(size(pic),class(pic));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 2011-04-20
      • 2020-07-11
      • 2013-04-11
      • 1970-01-01
      • 2013-03-26
      • 1970-01-01
      相关资源
      最近更新 更多