Loop in a array

1 view (last 30 days)
Emmanuelle
Emmanuelle on 26 Nov 2012
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 Comments
Emmanuelle
Emmanuelle on 26 Nov 2012
Edited: Emmanuelle on 27 Nov 2012
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 on 27 Nov 2012
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

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 26 Nov 2012
What is image_1? All you have shown up until that point is image1, which is a different variable.
  3 Comments
Image Analyst
Image Analyst on 27 Nov 2012
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 on 27 Nov 2012
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!!

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!