【问题标题】:ERROR RESHAPE the number of elements must not changeERROR RESHAPE 元素的数量不能改变
【发布时间】:2017-01-14 19:20:07
【问题描述】:

下面的代码有错误消息“要重塑元素的数量不能改变”

for i=1:11
s=num2str(i);
filename=['D:\test matlab\',s,'.tif'];
Image=imread(filename);
r=size(Image,1);
c=size(Image,2);
numberarray=r*c;
data=reshape(Image,1,numberarray);

最后一行产生错误%Error using reshape . produced_data(i,1:numberarray)=data;

图像=333x300x11 单幅

numberarray=99900

谁能帮帮我?

【问题讨论】:

  • 假设您的循环的意图是沿Image 的第三维进行切片,您需要在sizereshape 调用中实际索引到Image

标签: matlab reshape


【解决方案1】:

您的图片可能是彩色的;因此第三维可能> 1。 colorinformation=size(Image,3); % Red, Green, Blue

解决办法是:

  • 将图像转换为灰度

Image = rgb2gray(Image)

  • 在 reshape 中也使用 3 个颜色维度。

data=reshape(Image,1,numberarray,size(Image,3));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-15
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    相关资源
    最近更新 更多