필터 지우기
필터 지우기

Array dimensions must match for binary array op." How you solve that one? How to check the images have exactly the same row and column sizes, and the same number of dimensions (2 or 3).?

조회 수: 1 (최근 30일)
How to check the images have exactly the same row and column sizes, and the same number of dimensions (2 or 3).?

답변 (1개)

Sudhakar Shinde
Sudhakar Shinde 2020년 10월 9일
To check dimensions you can use:
if ndims(Image1) == ndims(Image2)
disp('dimensions are same');
else
disp('Dimensions are different')
end
To check size i.e. number of rows and colums equality, you can use
[Row1 Column1] = size(Image1);
[Row2 Column2] = size(Image2);
if (Row1==Row2) &(Column1==Column2)
disp('Both images have same size');
else
disp('Image size is different');
end
%Alternatively to check size also can be used:
if size(Image1) == size(Image2)
disp('same size')
else
disp('different size')
end
  댓글 수: 9
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 9일
Can you please elaborate meaning of download? If you re downloading from website or google this may be actual rgb image and hence it shows 128x128x3.
Stephen23
Stephen23 2020년 10월 12일
This answer is incorrect:
[Row1 Column1] = size(Image1);
[Row2 Column2] = size(Image2);
The size documentation explains that for multiple outputs "When dim is not specified and fewer than ndims(A) output arguments are listed, then all remaining dimension lengths are collapsed into the last argument in the list." This means for a 3D array (very likely with image data) the second of two outputs does NOT give the number of columns. This is very easy to demonstrate:
>> A = rand(4,3,2); % four rows, three columns, two pages
>> [X,Y] = size(A)
X = 4
Y = 6
Is Y the number of columns in A? (hint: no)
The simple solution for images (i.e. known to be either 2D or 3D) is to specify the third output:
>> [R,C,~] = size(A)
R = 4
C = 3

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by