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