필터 지우기
필터 지우기

Loop in a array

조회 수: 1 (최근 30일)
Emmanuelle
Emmanuelle 2012년 11월 26일
Hi,
I have a question. I have an image with three bands. How can I apply a loop for do an operation to all the pixels?
image1=imread('image_1.tif'); %I've load the image. Has a length of 4x4x3
band1a= image_1(:,:,1);
band2a= image_1( :,:,2);
band3b= image_1(:,:,3);
for i = 1:numel(band1b)
(...) this is the part of the operation
output= ?
Thanks a lot in advance,
  댓글 수: 5
Emmanuelle
Emmanuelle 2012년 11월 26일
편집: Emmanuelle 2012년 11월 27일
I know it would be a bit confusing...
image1=imread('image_1.tif');
band1a= image1(:,:,1);
band2a= image1(:,:,2);
band3b= image1(:,:,3);
for i = 1:numel(band1b)
ma = zeros(100,1);
ma(10) = banda1b(i);
end
for i = 1:numel(band2b)
ma(25) = banda2b(i);
end
for i = 1:numel(band3b)
ma(50) = band3b(i);
end
vec1= [10, 25, 50]';
pos1= ma(10);
pos2= ma(25);
pos3= ma(50);
vec2= [pos1 pos2 pos3];
t= 0:100;
xi= 0:1:100;
interplan= interp1(vec1,vec2,t,'spline');
sp1_a= spb1y.*interplan; %I've defined sp1by before
sp1_b= sp1_a./spsum1;
sp2_a= spb2y.*interplan;
sp2_b= sp2_a./spsum2;
sp3_a= spb3y.*interplan;
sp3_b= spout3_a./spsum3;
spout1_c= sum(spout1_b);
spout2_c= sum(spout1_b);
spout3_c= sum(spout1_b);
I know it could be something confusing but what I want is to get this last three values (spout1_c, spout2_c and spout3_c) for every pixel, in every band.
Hope I've explain this well!
Emmanuelle
Emmanuelle 2012년 11월 27일
The main problem is the following part because in an assignment A(I) = B, the number of elements in B must be the same but, I need to do it because it's important the 'position' in the interpolation.
for i = 1:numel(band1b)
ma = zeros(100,1);
ma(10) = banda1b(i);
end
for i = 1:numel(band2b)
ma(25) = banda2b(i);
end
for i = 1:numel(band3b)
ma(50) = band3b(i);
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2012년 11월 26일
What is image_1? All you have shown up until that point is image1, which is a different variable.
  댓글 수: 3
Image Analyst
Image Analyst 2012년 11월 27일
Regarding "I know it could be something confusing but what I want is to get this last three values (spout1_c, spout2_c and spout3_c) for every pixel, in every band." How about this:
image1(:, :, 1) = spout1_a;
image1(:, :, 2) = spout1_b;
image1(:, :, 3) = spout1_c;
Emmanuelle
Emmanuelle 2012년 11월 27일
Thanks Image analyst! :) I've solved the problem starting the code like this:
for row= 1: nrows
for col= 1: ncols
for band= 1: nband
But now I don't know how it's possible to copy correctly the output. I've created my output matrix like this:
output= zeros(1200, 1202, 3);
And I want to copy the spout1_a to the first band (band1a), spout1_b to the second.... I'm trying with that but I get the following error: " Conversion to double from cell is not possible."
output(:,:,1)= {spout1_c}
Thanks!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by