Overlaying data on image
28 次查看(过去 30 天)
显示 更早的评论
I have a set of points that have been extracted from users clicking on an image, which I now need to show overlapping the original
figure1 = xlsread("AllAMDataCollated.xlsx","Sheet2");
x = figure1(:,1);
y = figure1(:,2);
hold on
for k=0
ind = ((k*40)+1):40*(k+1); % indices of data to plot. When k=0 ind equals 1 to 40. When k=1 ind equals 41 to 80
plot(x(ind),y(ind),'.')
title(["AM Data Points"])
xlabel("Xpixels")
ylabel("Ypixels")
grid
saveas(gcf,'inputs.png')
P1 = imread('inputs.png');
I = imread('AM\cropped\09_58_00.jpg');
figure
imshowpair(P1,I,'blend','Scaling','joint')
end
This is the figure I'm intrested with, the points in the plot were determined by clicking on the faint ellipse in the image I'm trying to overlay however the scale is all off. any help would be great!
0 个评论
采纳的回答
Image Analyst
2021-5-1
Call plot() AFTER you display the image, not before.
6 个评论
Image Analyst
2021-5-2
Oliver, you can see from my attached analysis that your respondents don't agree very well, and the one you picked out if one of the two worst outliers. The dots accurately represent the coordinates in the workbook. It's just that for some reason they didn't accurately identify the centroid of the ellipse.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
rgbImage = imread('10_00_00.jpg');
figure
h1 = subplot(2, 2, 1);
image(rgbImage)
axis('on', 'image');
% Read in data.
data = xlsread("AllAMDataCollated.xlsx", "Sheet2");
[rows, columns] = size(data);
fprintf('The data has %d rows and %d columns.\n', rows, columns);
% Plot all the data for each respondent. x in column 1 and the y column 2.
x = data(:,1); % Get x
idNumbers = unique(data(:, 5)) % Get respndent ID numbers.
h2 = subplot(2, 2, [2, 4]);
% legendStrings = cell(1, columns - 2);
y = data(:, 2);
for id = 1 : length(idNumbers)
thisID = idNumbers(id);
logicalIndexes = data(:, 5) == thisID;
linearIndexes = find(logicalIndexes);
xforThisID = x(linearIndexes);
yforThisID = y(linearIndexes);
plot(xforThisID, yforThisID, '.', 'LineWidth', 2, 'MarkerSize', 17);
% legendStrings{id-1} = sprintf('Column %d', id);
hold on;
end
axis ij;
grid on;
% legend(legendStrings, 'Location', 'west');
caption = sprintf('Data from columns 2-4.');
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
title(caption, 'FontSize', fontSize);
% Get y data from rspondent #100000.
logicalIndexes = data(:, 5) == 100000; % indices of data to plot. When k=0 ind equals 1 to 40. When k=1 ind equals 41 to 80
linearIndexes = find(logicalIndexes);
fprintf('Extracting indexes in column 2 from row %d to row %d.\n', linearIndexes(1), linearIndexes(2));
x2 = x(logicalIndexes);
y2 = y(logicalIndexes);
% Draw red lines at the max and min x and y on the graph without the image.
xline(min(x2), 'Color', 'r', 'LineWidth', 2);
xline(max(x2), 'Color', 'r', 'LineWidth', 2);
yline(min(y2), 'Color', 'r', 'LineWidth', 2);
yline(max(y2), 'Color', 'r', 'LineWidth', 2);
h3 = subplot(2, 2, 3);
imshow(rgbImage);
axis('on', 'image');
hold on
% Draw red lines at the max and min x and y on the graph with the image.
xline(min(x2), 'Color', 'r', 'LineWidth', 2);
xline(max(x2), 'Color', 'r', 'LineWidth', 2);
yline(min(y2), 'Color', 'r', 'LineWidth', 2);
yline(max(y2), 'Color', 'r', 'LineWidth', 2);
% Plot all the data in green.
% plot(x, y, 'g.', 'MarkerSize', 30)
% Plot the data for the bad respondent in yellow.
plot(x2, y2, 'y.', 'MarkerSize', 30)
grid on;
caption = sprintf('Data from column 2 from row %d to row %d.', min(logicalIndexes), max(logicalIndexes));
title(caption, 'FontSize', fontSize);
% Find the average of all the data and put a big black circle there.
xMean = mean(x);
yMean = mean(y);
plot(h2, xMean, yMean, 'ko', 'LineWidth', 2, 'MarkerSize', 50);
plot(h3, xMean, yMean, 'ko', 'LineWidth', 2, 'MarkerSize', 50);
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m ...\n', mfilename);
Each respondent is a different color in the scatterplot.
Even the average of all the data (the black circle) is not that accurate. If you want, you can determine how far on average each respondent is from the average of the other respondents and admonish those who are obviously terrible and careless.
更多回答(1 个)
Oliver Hancock
2021-5-2
编辑:Oliver Hancock
2021-5-2
2 个评论
Image Analyst
2021-5-2
To fix existing bad data
yFixed = size(rgbImage, 1) - yBad;
If you need help with using ginput(), drawpoint(), or impoint(), so that you get the accurate values, let me know.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!