How to add two binay images and add the result to a third image?

1 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2014-8-18
Try this:
R1 = int32(I1) + int32(I2);
R2 = R1 + int32(I3);
R3 = R2 + int32(I4);
R4 = R3 + int32(I5);
output_R = [R1, R2, R3, R4];
imshow(output_R, []); % The [] are important.
  8 个评论
Meshooo
Meshooo 2014-8-19
编辑:Meshooo 2014-8-19
Thank you very much. Your program will add all the binary images, but actually I want the flow of the program to be in the same way I explained before, because I am doing other operations (adding the binary was just an example).
So how to make a new array R[ ] that contains four binary images R1, R2, R3, R4.
R1 = I1 + I2
R2 = R1 + I3 % do something
R3 = R2 + I4
R4 = R3 + I5

请先登录,再进行评论。

更多回答(1 个)

Ahmet Cecen
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 个评论
Meshooo
Meshooo 2014-8-18
Thank you all for your comments. Is there some way to do it directly without any reshaping?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by