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

43 次查看(过去 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.

采纳的回答

Matt J
Matt J 2024-11-20,20:36
编辑:Matt J 2024-11-20,20:37
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
  4 个评论
James
James 2024-11-21,16:37
编辑:James 2024-11-21,19:05
Hi this seems unstable. As sometime the red crosses flip accordingly like your example above and other times they don't flip at all. Any thoughts on that?

请先登录,再进行评论。

更多回答(1 个)

Suraj Kumar
Suraj Kumar 2024-11-20,20:42
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 2024-11-20,22:54
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