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

43 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Matt J
Matt J am 20 Nov. 2024 um 20:36
Bearbeitet: Matt J am 20 Nov. 2024 um 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 Kommentare
James
James vor etwa 18 Stunden
Bearbeitet: James vor etwa 15 Stunden
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 vor etwa 15 Stunden
My fault was flipping the points a second time. Thank you. Working now.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Suraj Kumar
Suraj Kumar am 20 Nov. 2024 um 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 Kommentar
James
James am 20 Nov. 2024 um 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?

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by