How to remove error 'matrix dimensions must agree' in XOR code ?

조회 수: 1 (최근 30일)
Gayatri B
Gayatri B 2019년 9월 13일
댓글: KALYAN ACHARJYA 2019년 9월 13일
How to remove the error of 'matrix dimensions must agree' in the following code,
a = imread('a.jpg');
b = imread('b.jpg');
binary1 = im2bw(a);
binary2 = im2bw(b);
output = xor(binary1, binary2);
subplot(3,2,1), imshow(a); title('First Image');
subplot(3,2,2), imshow(b); title('Second Image');
subplot(3,2,3), imshow(binary1); title('First Binary Image');
subplot(3,2,4), imshow(binary2); title('Second Binary Image');
subplot(3,2,5), imshow(output); title('Output');

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 9월 13일
편집: KALYAN ACHARJYA 2019년 9월 13일
  1. Before apply the XOR logic operation, please make sure that both and b images have same dimension.
Or
  1. If the a and b images are RGB image, convert them to gray images, then only apply xor on binary images.
a =imread('a.jpg');
[r c]=size(a);
b = imread('b.jpg');
% New Line
% Try to make the size of b, as same size of a
b=imresize(b,[r c]);
binary1 = im2bw(a);
binary2 = im2bw(b);
output = xor(binary1, binary2);
subplot(3,2,1), imshow(a); title('First Image');
subplot(3,2,2), imshow(b); title('Second Image');
subplot(3,2,3), imshow(binary1); title('First Binary Image');
subplot(3,2,4), imshow(binary2); title('Second Binary Image');
subplot(3,2,5), imshow(output); title('Output');
Or
a=rgb2gray(imread('a.jpg'));
[r c]=size(a);
b=rgb2gray(imread('b.jpg'));
% New Line
% Try to make the size of b, as same size of a
b=imresize(b,[r c]);
binary1=im2bw(a);
binary2=im2bw(b);
output=xor(binary1, binary2);
subplot(3,2,1), imshow(a); title('First Image');
subplot(3,2,2), imshow(b); title('Second Image');
subplot(3,2,3), imshow(binary1); title('First Binary Image');
subplot(3,2,4), imshow(binary2); title('Second Binary Image');
subplot(3,2,5), imshow(output); title('Output');
Any issue let me know?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by