2013-02-13 77 views
1

我有一個6波段的多光譜圖像。多光譜圖像的Píxel循環

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 

我得到與結果相同的值,而不是每個像素。

由於提前,

回答

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 
+0

你又幫了我很多謝,非常感謝你! :) – user1578688 2013-02-13 09:20:57

1

看到夏嘉曦已經回答了你的問題,但是如果你不變量y5很感興趣,y12等有辦法讓代碼比較容易維護:

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

爲了提高效率,儘量避免在Matlab中出現循環,可以嘗試一下l IKE在此:

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)) 

我不能檢查代碼,所以有可能是錯誤的;但只是給出其他類型實現的想法。