Overlay data points on image plot and only rotate image points not the image using imref2d
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (2)
Matt J
il y a environ 13 heures
Modifié(e) : Matt J
il y a environ 13 heures
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 commentaires
Matt J
il y a environ 11 heures
Modifié(e) : Matt J
il y a environ 9 heures
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
il y a environ 13 heures
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!
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!