How to add two binay images and add the result to a third image?
Mostra commenti meno recenti
Dear all,
I have one array that includes 5 binary images [I1, I2, I3, I4, I5].
I want to have a new array [R1, R2, R3, R4] where:
R1 = I1 + I2
R2 = R1 + I3
R3 = R2 + I4
R4 = R3 + I5
How to make a for loop for that?
Any help will be very appreciated.
Thank you very much.
Meshoo
Risposta accettata
Più risposte (1)
Ahmet Cecen
il 18 Ago 2014
Here is how to make a loop for that:
R(:,1)=I(:,1)+I(:,2); %Initialization
for i=2:4
R(:,i)=R(:,i-1)+I(:,i+1); %This is the loop that you asked for.
end
5 Commenti
Image Analyst
il 18 Ago 2014
His I1, I2, etc. are arrays (2D images), not 1D column vectors like your code requires.
Ahmet Cecen
il 18 Ago 2014
In that case, I can't repair the loop until I know exactly how each image is stored. Are they literally a concatenated array like [I1 I2 ...] or ar they stored individually as variables I1 and I2 or are they cell arrays or a struct. The same indexing logic should work regardless though.
One fool-proof way to do it would be to flatten the images to 1D, and form the 2D array I=[I1,I2...] and use the above code, then unflatten them using "reshape".
Image Analyst
il 18 Ago 2014
My question exactly. The situation is not defined clearly enough to answer. But I think it can be done without reshaping, just so long as you know the size and number of the I1, I2, etc. that make up the "one array".
Meshooo
il 18 Ago 2014
Image Analyst
il 18 Ago 2014
Yes. Did you read our comments about what information is required?
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!