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

43 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Matt J
Matt J el 20 de Nov. de 2024 a las 20:36
Editada: Matt J el 20 de Nov. de 2024 a las 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 comentarios
James
James hace alrededor de 16 horas
Editada: James hace alrededor de 14 horas
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?
James
James hace alrededor de 13 horas
My fault was flipping the points a second time. Thank you. Working now.

Iniciar sesión para comentar.

Más respuestas (1)

Suraj Kumar
Suraj Kumar el 20 de Nov. de 2024 a las 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 comentario
James
James el 20 de Nov. de 2024 a las 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?

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by