3

Given a 2D array that has been converted to binary, for some index values of the binary array how do you find the corresponding values in the original?

Maybe something using ind2sub?

2 Answers 2

5

No, you can index directly.

%# create some test data
m = magic(4);
%# make binary image
bw = m>10;

%# read values from m
values = m(bw);

%# alternatively, if you have linear indices (as found via find)...
linIdx = find(bw);
%# ...you can use that instead
values = m(linIdx);
Sign up to request clarification or add additional context in comments.

Comments

1

You can keep the 2D structure using an element-wise multiplication.

m = magic(4);
bw = m>10;
m .* bw

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.