cv_2013
cv_2013

Reputation: 3

Join 2 different points in different images in MATLAB

I have 2 different images of same dimensions. There is 1 point of interest in each image. I want to join the 2 images by joining those 2 points in a plot with a line. How can I do that? This is the rough idea of the image: http://i.imgbox.com/abhqL3XT.png

Upvotes: 0

Views: 784

Answers (2)

Marcin
Marcin

Reputation: 238967

If I understand correctly, this should do what you want:

% example random images (assumed gray-scale)
Img1 = rand(256)*.1;
Img2 = rand(256)*.3;

% widh of the images
imgWidth = size(Img1, 2);

%joined image
Img12 = [Img1, Img2];


% example points
[point1x, point1y] = deal(201, 100);
% point twos horizontal coordinate
% is shifted by the image width
[point2x, point2y] = deal(imgWidth + 101, 40);


% show images and plot the line
figure;
imshow(Img12);
hold on;
plot([point1x, point2x],[point1y, point2y], '+-b');

Upvotes: 1

Chris Taylor
Chris Taylor

Reputation: 47402

Let's create two images

>> [X,Y] = meshgrid(-200:200, -200:200);
>> im1 = exp(-sqrt(X.^2+Y.^2)/100);
>> im2 = exp(-sqrt(X.^2+Y.^2)/200);

You can display them side by side with the imagesc command:

>> imagesc([im1 im2]);

enter image description here

Now say you want to connect two points in the images, with coordinates (100, 300) and (300, 50). Because the images are side by side, you need to add the width of the first image to the x coordinate in the second image:

>> width = size(im1, 2);
>> x1 = 100; y1 = 300;
>> x2 = 300 + width; y2 = 50;

Now you can put a hold on the image (so you can plot on top of it) and plot your line connecting the two points:

>> hold on;
>> plot([x1 x2], [y1 y2], 'r', 'LineWidth', 2)

enter image description here

Upvotes: 1

Related Questions