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

1 vue (au cours des 30 derniers jours)
Gayatri B
Gayatri B le 13 Sep 2019
Commenté : KALYAN ACHARJYA le 13 Sep 2019
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');

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 13 Sep 2019
Modifié(e) : KALYAN ACHARJYA le 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?
  2 commentaires
Gayatri B
Gayatri B le 13 Sep 2019
This worked. Thank You so much!
KALYAN ACHARJYA
KALYAN ACHARJYA le 13 Sep 2019
Welcome Always

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Modify Image Colors dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by