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

1 visualización (últimos 30 días)
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');

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 13 de Sept. de 2019
Editada: KALYAN ACHARJYA el 13 de Sept. de 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?

Más respuestas (0)

Categorías

Más información sobre Modify Image Colors en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by