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

1 Ansicht (letzte 30 Tage)
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');

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 13 Sep. 2019
Bearbeitet: KALYAN ACHARJYA am 13 Sep. 2019
  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?

Weitere Antworten (0)

Kategorien

Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by