0

您好,有此代码,我不知道如何将输出结果与每个像素一起放置。我认为输出代码定义不明确。

编辑:

我将尝试解释代码:

% I have an image

    imagen1=imread('recor.tif');
    imagen2= double(imagen1);
    band1= imagen2(:,:,1);

% I preallocate the result (the image size is 64*89*6)
    yvan2= zeros(61,89,1);

% For every pixel of the image, I want to get one result (each one is different).
    for i = 1 : nfiles
        for j = 1 : nrows
            for i = 1:numel(band1)

% I'm doing this because I've to multiply the results of this interpolation with that result a2ldb1y= ldcm_1(:,1). This vector has a length of 2151x1 and I need to muliply the result of the interpolation for (101:267) position on the vector, this is the reason because I'm doing the interpolation since 101 to 267 (also because I don't have that values).

            interplan= interp1(van1,man2,t2,'spline');
             ma(96) = banda1a(i); % I said 96, because I want to do an interpollation 
            end                
            van1= [101 96 266]';
            mos1= ma(134);
            van2= [0 pos1 0];

            t= 101:267;
            t2= t';
            xi= 101:1:267;
            xi2=xi';
            interplan= interp1(van1,van2,t2,'spline');

% After this, I 'prepare' the vector.

            out=zeros(2151,1)
            out(101:267) = interplan;

% And then, I do all this operation (are important for the result) 

            a2ldb1y= ldcm_1(:,1); 
            a2ldsum_pesos1= sum(a2ldb1y);
            a2l7dout1_a= a2ldb1y.*out;
            a2l7dout1_b=  a2l7dout1_a./a2ldsum_pesos1;
            a2l7dout1_c= sum(a2l7dout1_b);

% And the result a2l7dout1_c I want it for every pixel (the results are different because every pixel has a different value...)
           **yvan2(:,:,1)= [a2l7dout1_c];**

        end 
    end

提前致谢,

4

1 回答 1

0

我在这里在黑暗中拍摄,但我认为您正在寻找:

yvan2(i, j, 1)= a2l7dout1_c;

代替:

yvan2(:,:,1)= [a2l7dout1_c];

因此,您的输出应该在yvan2循环完成后存储在变量中。

附言

您的代码中的一些问题:

  1. 为什么你有两个循环使用相同的迭代变量i?您的计算可能不正确,因为i正在被两个for循环修改。

  2. 为什么你甚至需要第二个循环?每次迭代都会超出ma(134)前一次迭代设置的值。您可以将整个循环替换为:

    ma(134) = banda1a(numel(band1))
    
  3. 您不应该使用名称ijfor 循环变量。它们已经为虚数单位(即sqrt(-1))保留,因此 MATLAB 需要额外的处理时间来解析名称。您宁愿使用其他循环变量名称,甚至iijj.

于 2013-01-28T12:23:01.323 回答