首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多光谱图像的Píxel环

多光谱图像的Píxel环
EN

Stack Overflow用户
提问于 2013-02-13 16:31:39
回答 3查看 600关注 0票数 1

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

代码语言:javascript
复制
imagen1=imread('re_2008.tif')
size2=size(imagen1);
nrow= size2(1);
ncol= size2(2);
nband= size2(3);

我想做的是得到每个波段的每个像素(在相同的位置)和它们的值,做一个插值,然后用一个位于其他波长的新值来替换它。如果我给你看代码,你可能会更了解我。

代码语言:javascript
复制
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

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

提前谢谢你,

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-02-13 16:55:34

怎么样

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2013-02-13 17:34:48

我看到Shai已经回答了你的问题,但是如果你对变量y5y12等不太感兴趣,有一种方法可以让代码更紧凑,更容易维护:

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2013-02-13 18:11:45

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

代码语言:javascript
复制
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

或者甚至像这样:

代码语言:javascript
复制
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))

我不能检查代码,所以可能会有错误;但这只是为了给出其他类型的实现的想法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14849355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档