【问题标题】:please help me Assignment has more non-singleton rhs dimensions than non-singleton请帮助我分配比非单件具有更多的非单件 rhs 维度
【发布时间】:2010-05-14 20:26:08
【问题描述】:

我的代码中有以下错误

分配有更多的非单例 rhs 尺寸比非单件

这是代码:

 string =['d:\face\face\ffw' int2str(r) '_' int2str(Sel(nSelRow,t)) '.bmp'];
 A = imread(string);
 B = im2double(A);
 Train_Dat(:,:,s)=B;

更新 1:

当我更新代码时,下一行出现了新错误

我的代码

for r=1:Class_Num
    for t=1:Class_Train_Num
        %string=['e:\face_lib\feret_80\ff' int2str(r) '_' int2str(t) '.tif'];
        string =['d:\face\face\ffw' int2str(r) '_' int2str(Sel(nSelRow,t)) '.bmp'];
        A=imread(string);
        B=im2double(A);
        Train_Dat(:,:,:,s)=B;
        Train_Dat_Vector(:,s)=B(:); %here new error Subscripted assignment dimension mismatch.
        s=s+1;
    end

更新 2:

my define for 
nImgW = 40;
nImgH = 40;
nImgSize = nImgW*nImgH;
Train_Dat_Vector = zeros( nImgSize, Train_Num );
            A=imread(string);
            B=im2double(A);
            Train_Dat(:,:,:,s)=B;
            Train_Dat_Vector(:,s)=B(:);%here i want convert matrix to 40x40,Train_Num
            s=s+1;

【问题讨论】:

  • @Mike:他的代码返回了一个错误。他不知道为什么。但我认为在他提供语言、环境等方面的一些细节之前,他不会得到太多帮助……
  • 说真的。这是什么语言。 Train_Dat(:,:,s)=B; 是....奇特的
  • 好的,我将它标记为 matlab,因为 matlab 具有所有这些函数名称,如果我错了,请重新/取消标记
  • 什么是变量rnSelRowtSel?或者Sel是一个函数?
  • @Earlz - 是的,它是 Matlab,是的,它很奇特 :)

标签: matlab variable-assignment


【解决方案1】:

我认为问题在于 B 很可能是 3-D RGB image,而您正试图将其分配给 3-D 矩阵 Train_Dat 的单个 2-D 平面。如果您尝试收集一组 3-D 图像用作训练数据,则必须将 Train_Dat 设为 4-D 矩阵(如果您的所有图像具有完全相同的尺寸)或元胞数组(每个单元格一张图片):

示例 #1:4-D 矩阵...

nRows = 100;  %# The number of rows in the images
nCols = 100;  %# The number of columns in the images
nDepth = 3;   %# The depth of the images (3 color planes for RGB images)
nImages = 5;  %# The number of images you will use
Train_Dat = zeros(nRows,nCols,nDepth,nImages);  %# Initialize to zeros
Train_Dat(:,:,:,1) = B;                         %# Assign B as the first image

如果您想使用此选项,但您的所有图像不是相同大小,则必须将它们全部调整为给定大小。如果你有Image Processing Toolbox,一种方法是使用函数IMRESIZE

newSize = [40 40];        %# The new size the image will be
C = imresize(B,newSize);  %# Resize image B

如果您无权访问图像处理工具箱,另一种方法是使用函数INTERP2 调整图像大小。这是调整UINT8 类型的3-D RGB image 大小的一个示例:

B = double(B);                   %# Convert B to double (needed to use INTERP2)
[nRows,nCols,nDepth] = size(B);  %# Get the old image size
C = zeros(40,40,3,'uint8');      %# Initialize the new 3-D 40-by-40 uint8 image
xi = linspace(1,nCols,40);       %# Create a down-sampled set of x points
yi = linspace(1,nRows,40);       %# Create a down-sampled set of y points
[X,Y] = meshgrid(xi,yi);         %# Create 40-by-40 grids of x and y points
C(:,:,1) = interp2(B(:,:,1),X,Y,'spline');  %# Interpolate the red color plane
C(:,:,2) = interp2(B(:,:,2),X,Y,'spline');  %# Interpolate the green color plane
C(:,:,3) = interp2(B(:,:,3),X,Y,'spline');  %# Interpolate the blue color plane

图像C 现在将是B 的下采样40×40 版本。

示例 #2:元胞数组...

nImages = 5;  %# The number of images you will use
Train_Dat = cell(1,nImages);  %# Initialize the cell array
Train_Dat{1} = B;             %# Assign B as the first image

在这种情况下,您添加到每个单元格的图像可以是不同的大小和类型,因此不需要调整大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 2017-05-06
    相关资源
    最近更新 更多