MATLAB Answers

Michael
1

Does logical indexing have a direct inverse?

Michael
さんによって質問されました 2012 年 12 月 10 日
Say I have some region-of-interest filter X, and I use B = A(X~=0) to only extract the values of A where X~=0, is it then possible to retrieve A from B and X?
I'm trying to think of a clever way to do it but coming up a little short!
Thanks for any suggestions,
Mike

  0 件のコメント

サインイン to comment.

4 件の回答

Sean de Wolski
回答者: Sean de Wolski
2012 年 12 月 10 日

I.e:
A(X~=0) = B
?

  2 件のコメント

Michael
2012 年 12 月 10 日
That looks the same as my forward problem, I'm looking for A = [matlab operation](B).
Sean de Wolski
2012 年 12 月 10 日
No, the location data is required and it comes from X.
Also, you will never know about the values in A that were not extracted from X or the size of A. Thus you need the index to go in reverse.

サインイン to comment.


Walter Roberson
回答者: Walter Roberson
2012 年 12 月 10 日

No, it is not possible.
Suppose for example X was a matrix the same size as A, and is 1 for the top-left quadrant and 0 elsewhere. B = A(X~=0) would then retrieve values from the top left quadrant and would have no information about anything elsewhere in A. X also has no information about anything in A. Therefore, if you have only X and B, you cannot reconstruct the information that was in the other three quadrants of A.
My guess about what you actually want to do is:
A(X ~= 0) = B;

  0 件のコメント

サインイン to comment.


Login_Name
回答者: Login_Name
2012 年 12 月 10 日
編集済み: Login_Name
2012 年 12 月 10 日

Simple example:
A = randperm(4);
X = [0 1 0 1]
B = A(X~=0)
clear A
Now just look at X and B. By looking at just those two arrays, it is not even in principle possible to tell exactly what A was! This despite the fact that we know all of the elments of A! In a more general case, the problem is only worse. If you, as a human being, cannot tell what the original A was with such a simple example, how in the world could MATLAB tell?

  0 件のコメント

サインイン to comment.


Image Analyst
回答者: Image Analyst
2012 年 12 月 10 日

Michael: As the others have said, you can't get back ALL of a from only the part you extracted - you'd need the complete a to do that. However you extracted a chunk of "a" into a 1D column vector, and it is possible to put that back into a 2D reconstructed "a" where the extracted part is the same, but the unextracted part is zero (or any other number you want). Here's some demo code. See if it's what you were thinking.
% Generate sample data.
a = magic(8)
% Make x a mask in the upper left quadrant.
x = false(size(a)); % Initialize.
x(1:4, 1:4) = true % Mask of upper left quadrant
% Extract masked a into b.
b = a(x~=0) % This will be a 16 by 1 column vector.
% We can't get back ALL of a, without using a, but we CAN get back the a that we extracted
% back into the original 2D shape with zeros (or any constant) elsewhere.
a_reconstructed = zeros(size(x)); % Initialize a new "a" with 2D matrix of 0's.
% Find the linear indices that we used to extract elements of a.
linearIndexes = find(x~=0)
% Use them to assign those elements of a reconstructed a
% from the elements in b.
a_reconstructed(linearIndexes) = b(:)

  0 件のコメント

サインイン to comment.



Translated by