How to add two binary images in order?

4 次查看(过去 30 天)
Meshooo
Meshooo 2013-10-16
编辑: Meshooo 2014-1-23
Dear all, I have a folder that includes a serial images, let's say 5 images X_1, X_2, X_3, X_4, X_5. I want to use the imadd matlab function to perform the following steps:
Step1: apply imadd to the first two images X_1 and X_2.
Add_1 = imadd(X_2, X_1);
Step2: apply imadd to X_3 and Add_1 that we obtained image from step1
Add_2 = imadd(X_3, Add_1);
Step3: apply imadd to X_4 and Add_2
Step4: again apply imadd to X_5 and Add_3 and so on.
Can we do that using a for loop?
I would appreciate any help and suggestions.
Thank you very much.
Meshoo

回答(2 个)

Jan
Jan 2013-10-16
编辑:Jan 2013-10-16
"X_1" might be a simplification, but it matters, what this exactly mean. Is this a name of an image in a folder, the complete path or the imported image data? Do you really use "X_1" as name? If so, please read http://www.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a10-in-a-loop and avoid hiding an index in the name of a variable, but prefer a cell array: X{1}, X{2} .... Then adding gets easy:
Add = X{1};
for k = 2:5
Add = imadd(X{k}, Add);
end

Image Analyst
Image Analyst 2013-10-16
Why do you want to add binary images, and what exactly do you mean by add? So do you really want to add them like integers? So that with 5 images you could have a max value of 5?
integerImage = int32(binary1) + int32(binary2);
or do you want to make sure that the output image is white wherever any of the input images are white, so in essence you want to OR the images:
binaryCombined = binary1 | binary2;
To determine which method you should use I really need to know what you plan on doing with this image once you've created it.
  4 个评论
Jan
Jan 2013-10-17
@Mustafa: I have posted a suggestion already. Instead of repeating the question, you could explain if it helps already or which detail is not solved by it.
Image Analyst
Image Analyst 2013-10-17
And explain why you said these are binary images (logical true/false) when it appears that they're probably actually color images or gray scale images since they came from a microscope.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by