Reputation:
I need to join two images in Matlab. The two binary images are left and right images with some overlapping in between and I need to merge them in Matlab to make a single image (like a panorama except the images are just 2D line drawings and there is no noise, e.g. the overlapped regions are perfectly identical).
Therefore if I would like to find the common columns from both images and then create a new image such as
new_image = [left_image(excluding-the-common-columns) right_image]
and then just plot it.
I tried to use the 'intersect' method, but all I have achieved so far is finding the common elements and not common columns.
How can I find the common columns in such images?
Upvotes: 3
Views: 819
Reputation: 1981
You can use ismember()
to find rows common to two arrays. Just transpose your matrix to get the same functionality for columns. Like so:
im = imread('forest.tif');
left = im(:, 1:300);
right = im(:, 200:end);
a = ismember(left', right', 'rows');
first_common_index = find(a, 1);
joined = [left(:, 1:first_common_index), right];
Then doing
figure
subplot(2,2,1);
imshow(left, []);
title('Left')
subplot(2,2,2);
imshow(right, []);
title('Right')
subplot(2,2,[3,4]);
imshow(joined, []);
title('Joined')
gives
Upvotes: 1