How to add two binay images and add the result to a third image?
古いコメントを表示
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
採用された回答
その他の回答 (1 件)
Ahmet Cecen
2014 年 8 月 18 日
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 件のコメント
Image Analyst
2014 年 8 月 18 日
His I1, I2, etc. are arrays (2D images), not 1D column vectors like your code requires.
Ahmet Cecen
2014 年 8 月 18 日
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
2014 年 8 月 18 日
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
2014 年 8 月 18 日
Image Analyst
2014 年 8 月 18 日
Yes. Did you read our comments about what information is required?
カテゴリ
ヘルプ センター および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!