Overlaying data on image

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!

 Risposta accettata

Image Analyst
Image Analyst il 1 Mag 2021

0 voti

Call plot() AFTER you display the image, not before.

6 Commenti

This seems to be working although the data has been mirrored due to the coordinates (used a different image and range to illustrate this better, the poitns should be spead along the major axis of the ellipse)
I = imread('AM\cropped\10_00_00.jpg');
figure
image(I)
figure1 = xlsread("AllAMDataCollated.xlsx","Sheet2");
x = figure1(:,1);
y = figure1(:,2);
hold on
for k=2
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),'.')
end
Oliver, note that normally when using plot, the origin is at the lower left of the graph. But the origin of matrices and images is at the upper left, which is where (1,1) element is.
Make sure that your x and y refer to rows and columns when plotting over an image.
You can specify the origin for either plots or images to be in the upper left by using axis:
axis ij;
You can specify the origin for either plots or images to be in the lower left by using axis:
axis xy;
Normally plot() uses axis xy with origin in the lower left. However when you put hold on to plot the points over an image (without blowing away the image), it will use the axis ij like the image is already using. That's why the points seemed flipped vertically when plotting over an image.
Ah right I see, how would I impliment this into the code as it still seems to be mirrored regardless of where I put axis ij; ?
Image Analyst
Image Analyst il 1 Mag 2021
Modificato: Image Analyst il 1 Mag 2021
What would you expect to see? And can you attach "AllAMDataCollated.xlsx" and 'AM\cropped\10_00_00.jpg' with the paperclip icon? How did you get the x and y in the first place? Are you sure the workbook is not (row, column) instead of (x, y)?
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
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.

Accedi per commentare.

Più risposte (1)

Oliver Hancock
Oliver Hancock il 2 Mag 2021
Modificato: Oliver Hancock il 2 Mag 2021

0 voti

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 Commenti

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.
Yep thats done the trick, thanks very much

Accedi per commentare.

Prodotti

Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by