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

1 次查看(过去 30 天)
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