Overlaying data on image

28 views (last 30 days)
Oliver Hancock
Oliver Hancock on 30 Apr 2021
Commented: Oliver Hancock on 3 May 2021
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!

Accepted Answer

Image Analyst
Image Analyst on 1 May 2021
Call plot() AFTER you display the image, not before.
  6 Comments
Oliver Hancock
Oliver Hancock on 1 May 2021
The data was collected from users clicking on an image of the ellipse (ie 10_00_00) at where they thought the centre was using a pre written matlab program. The points should be somewhere in the centre and look more like the plot in my original post. Sorry Im not entirely sure what Im doing as I'm a complete begginer with matlab
Image Analyst
Image Analyst on 2 May 2021
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.

Sign in to comment.

More Answers (1)

Oliver Hancock
Oliver Hancock on 2 May 2021
Edited: Oliver Hancock on 2 May 2021
thank you so much for all your help with this, I think I see the probelem now. I ran a test clicking the 10_00_00 image in the lower right corner and as you can see the point appears in the top right corner when plotted. It looks as though the original matlab programme that diplays the image and then records the coordinates of the results uses a different axis to that of the image itself (I think?) which would explain why the points seem mirrored. I'm assuming I could just subtract the y coords of the points from the maximum y value the image holds (The images are not all the same size, not sure if this complicates things)
  2 Comments
Image Analyst
Image Analyst on 2 May 2021
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.
Oliver Hancock
Oliver Hancock on 3 May 2021
Yep thats done the trick, thanks very much

Sign in to comment.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!