1

我有一张有 6 个波段的多光谱图像。

imagen1=imread('re_2008.tif')
size2=size(imagen1);
nrow= size2(1);
ncol= size2(2);
nband= size2(3);

我想要做的是让每个波段的每个像素(在同一位置)都有它们的值,进行插值并使用位于其他波长的新值,替换它。如果我向您展示代码,也许您会更了解我。

imagen3_2 = zeros(nrow, ncol, nband);
var1= [1 2 3 4 5 6]'; %'

for row=1:nrow;
    for column=1:ncol;
        for band=1:nband;              
            v = imagen1(nrow(1),nband(2),:); v = v(:); 
            t= 0:100;

            interplan= interp1(var1, v, t,'cubic');
            y5 = interplan(5); % I get the value of the interpolation on this position
            y12 = interplan(12);
            y20 = interplan(20);
            y50 = interplan(50);
            y80 = interplan(80);
            y90 = interplan(90);

            imagen3_2(:,:,1)= (y5); % and I replace it
            imagen3_2(:,:,2)= (y12);
            imagen3_2(:,:,3)= (y20);
            imagen3_2(:,:,4)= (y50);
            imagen3_2(:,:,5)= (y80);
            imagen3_2(:,:,6)= (y90);
        end 
    end
end

结果,我得到了相同的值,而不是每个像素。

提前致谢,

4

3 回答 3

1

怎么样

imagen3_2 = zeros(nrow, ncol, nband);
var1= [1 2 3 4 5 6]'; %'

for row=1:nrow;
    for column=1:ncol;
            v = imagen1(row, column, :); v = v(:); 
            t= 0:100;

            interplan= interp1(var1, v, t,'cubic');
            y5 = interplan(5); % I get the value of the interpolation on this position
            y12 = interplan(12);
            y20 = interplan(20);
            y50 = interplan(50);
            y80 = interplan(80);
            y90 = interplan(90);

            imagen3_2(row,column,1)= (y5); % and I replace it
            imagen3_2(row,column,2)= (y12);
            imagen3_2(row,column,3)= (y20);
            imagen3_2(row,column,4)= (y50);
            imagen3_2(row,column,5)= (y80);
            imagen3_2(row,column,6)= (y90);
    end
end
于 2013-02-13T08:55:34.247 回答
1

我看到 Shai 已经回答了您的问题,但是如果您对 variables 等不感兴趣y5y12有一种方法可以使代码更紧凑且更易于维护:

imagen3_2 = zeros(nrow, ncol, nband);
var1= [1 2 3 4 5 6]'; %'

for row=1:nrow;
    for column=1:ncol;
            v = imagen1(row, column, :); v = v(:); 
            t= 0:100;

            interplan= interp1(var1, v, t,'cubic');

            y = [5 12 20 50 80 90];
            for i = 1:length(y)         
               imagen3_2(row,column, i)= interplan(y(i));% repace interpolation value
            end
    end
end
于 2013-02-13T09:34:47.910 回答
1

为了提高效率,请尽量避免在 Matlab 中出现循环,您可以尝试以下操作:

x = [1 2 3 4 5 6];
y = imread('re_2008.tif');
y_size = size((y(:,:,1)));

xi = 0:100;
yi = zeros([y_size,numel(xi)]);

for i_pix=1:prod(y_size)
    [aux_x,aux_y] = ind2sub(y_size,i_pix);
    yi(aux_x,aux_y,:) = interp1(x,squeeze(y(aux_x,aux_y,:)),xi,'cubic');
end

甚至像这样:

x = [1 2 3 4 5 6];
y = imread('re_2008.tif');
xi = 0:100;

yi = arrayfun(@(y1,y2,y3,y4,y5,y6) interp1(x,[y1,y2,y3,y4,y5,y6],xi,'cubic'), ...
y(:,:,1), y(:,:,2), y(:,:,3), y(:,:,4), y(:,:,5), y(:,:,6))

我无法检查代码,因此可能存在错误;但这只是提供有关其他类型实施的想法。

于 2013-02-13T10:11:44.977 回答