Overlay data points on image plot and only rotate image points not the image using imref2d

조회 수: 30 (최근 30일)
Hello,
I have the following data that I would like to overlay onto an image, and only flip the data points on the image and not the image itself.
load B.mat; %load reverse imcomplement of image
load x_world
load y_world
figure(1);
theta = -90; %rotate image counterclockwise
distorted = imrotate(B, theta);
ref = imref2d(size(distorted),[300 700], [100 550]); %set world coordinates
imshow(distorted,ref); %show image
set(gca, 'XTickLabel', flipud(get(gca,'XTickLabel') )); %change x-axis direction on image
hold on
plot(x_world,y_world,'r+','MarkerSize',12,'LineWidth',2); %overlay data points onto image
some code; %need to "flip/reflect" vertically only the data points. Not the image or x-axis.
I'm needing help on being able to flip/reflect vertically only the data points not the x-axis or the image.

답변 (2개)

Matt J
Matt J 대략 16시간 전
편집: Matt J 대략 16시간 전
load B.mat; %load reverse imcomplement of image
load x_world
load y_world
figure(1);
theta = -90; %rotate image counterclockwise
distorted = imrotate(B, theta);
ref = imref2d(size(distorted),[300 700], [100 550]); %set world coordinates
imshow(distorted,ref); %show image
set(gca, 'XTickLabel', flipud(get(gca,'XTickLabel') )); %change x-axis direction on image
hold on
y_world=sum(ref.YWorldLimits)-y_world;
plot(x_world,y_world,'r+','MarkerSize',12,'LineWidth',2);
hold off
  댓글 수: 2
James
James 대략 11시간 전
Thank you for the response, this flips the points horizontally, but I changed the code to flip the points vertically.
x_world=sum(ref.XWorldLimits)-x_world;
The issue now is that when you hover over the crosses, the values for the x coordinates do not match the placement on the x-axis.
Any ideas on how to flip the actual X coordinate values to match the position on the x-axis?
Thank you
Matt J
Matt J 대략 14시간 전
편집: Matt J 대략 9시간 전
Thank you for the response, this flips the points horizontally, but I changed the code to flip the points vertically.
I'm not sure why you think so. Doesn't flipping vertically mean to reflect the data across a horizontal axis? The output of my code above demonstrates that the points do flip in this manner, compared to the output in your post.
Regardless, this might be what you ultimately want:
load B.mat; %load reverse imcomplement of image
load x_world
load y_world
figure(1);
theta = -90; %rotate image counterclockwise
distorted = imrotate(B, theta);
ref = imref2d(size(distorted),[300 700], [100 550]); %set world coordinates
imshow(fliplr(distorted),ref); %show image
set(gca, 'XDir','reverse'); %change x-axis direction on image
hold on
plot(x_world,y_world,'r+','MarkerSize',12,'LineWidth',2);
hold off

댓글을 달려면 로그인하십시오.


Suraj Kumar
Suraj Kumar 대략 16시간 전
Hi James,
To overlay the data points on an image and flip them vertically (i.e. along Y-axis), you can refer to the following steps and the attached code snippets:
1. After plotting the image, you can determine the midpoint of the x-axis using the limits provided by the 'imref2d' object. This midpoint is used as the line of reflection.
% Calculate the midpoint of the x-axis range
x_min = ref.XWorldLimits(1);
x_max = ref.XWorldLimits(2);
x_mid = (x_min + x_max) / 2;
2. Compute the flipped x-coordinates by reflecting the original x-coordinates across the x-axis midpoint.
x_world_flipped = x_mid - (x_world - x_mid);
3. Plot the original data points in one color (e.g., red) and the flipped data points in another color (e.g., blue) on the same image.
% Plot the original data points
plot(x_world, y_world, 'r+', 'MarkerSize', 12, 'LineWidth', 2, 'DisplayName', 'Original Points');
% Plot the flipped data points
plot(x_world_flipped, y_world, 'b+', 'MarkerSize', 12, 'LineWidth', 2, 'DisplayName', 'Flipped Points');
You can go through the output below for a better understanding:
To learn more about the 'imref2d' function in MATLAB, please go through the following documentation:
Hope this helps!
  댓글 수: 1
James
James 대략 11시간 전
The issue now is that when you hover over the crosses, the values for the x coordinates do not match the placement on the x-axis.
Any ideas on how to flip the actual X coordinate values to match the position on the x-axis?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by