How to compare two 3D matrices element-wise?

조회 수: 10 (최근 30일)
Hadi Ghahremannezhad
Hadi Ghahremannezhad 2021년 2월 10일
댓글: Hadi Ghahremannezhad 2021년 2월 10일
I have two RGB images (3D matrix: x, y, z) of the same size, and I wanted to compare the corresponding values.
Suppose there are two matrices A and B, both have size (4,5,3).
I want a 2D mask (logical image) that represents the (x,y) points where matrix A is less than matrix B in all 3 values of the third (z) dimension.
So for example the mask(4,4) = 1 if:
  • A(4,4,1) < B(4,4,1)
  • A(4,4,2) < B(4,4,2)
  • A(4,4,3) < B(4,4,3)
I tried this but it doesn't work, because the resulting matrix (ALessThanB) is 3D logical:
ALessThanB = A < B;
How can I make this comparison only along the third dimension?

채택된 답변

Steven Lord
Steven Lord 2021년 2월 10일
Use the all function. You'll want to specify the optional dim input argument as well as the required A input argument (the data.)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by