MATLAB: Presenting simultaneously 40 images, non overlapping.

digital image processingdisplayeye trackereye trackingImage Processing ToolboxMATLAB and Simulink Student Suiterandomrandom locationscreen

Hi everyone,
I have a specific problem I hope you will help me with. I am running an experiment using eyetracking. In each trial (84 trials in total) I have to present 40 images, 100×100 pixels each, 20 on the right side of the screen, 20 on the left, simultaneously. The screen has a 1600×1200 pixels resolution.
I am trying to generate a random vector of coordinates of x and y which adheres the following conditions:
Each randomly generated x and y location coordinate pair must ensure the image presented is equidistant by 50 pixels from the next. This means that all the images displayed on screen, all 40 of them, must have at least 50 pixels distance from each other. So if on of the image location pairs is x = 1 and y = 1, the other x and y pairs must not have a value within x + 100(image pixel number) + 50 (distance between images) = 151, and y + 100(image pixel number) + 50 (distance between images) = 151. Each trial must have coordinate/location x and y numbers for all 40 images that adhere to these rules.
I am sorry this is so wordy. Can anyone please help?
All the best and thanks, Dritan

Best Answer

Hi Dritan Nikolla
zipped attachment split_coordinates.zip contains the following files: example1.m scatter_points_saturate.m sactter_points7.m and 2 free license files.
example1.m contains the following steps to get the relative coordinates of the split images, using scattered points meeting the minimum distance requirement.
1. simulating scattered points with minimum distance
W0=2000;H0=2000;R0=150;
[X,Y,Nmax,Dmatrix]=scatter_points_saturate(W0,H0,R0)
.
the attached functions scatter_points7.m and scatter_points_saturate.m generate random points within a given rectangle meeting constraint of minimum distance.
scatter_points7.m asks how many random points and minimum distance. scatter_points_saturate.m generates as many random points as possible meeting the minimum distance you choose.
please note that R0 is the minimum distance between any adjacent points.
2.
With some minor coordinate corrections we can easily obtain the coordinates as follows
X=X+W0/2+1;Y=Y+H0/2+1; % centring
X(1)=[];Y(1)=[]; % correction
A=zeros(W0,H0);
for k=1:1:numel(X)
A(X(k),Y(k))=1;
end
figure(2);plot(X,Y,'sr');axis([0 W0+1 0 H0+1]);
ax=gca
ax.DataAspectRatio=[W0/2 H0/2 1];
.
The coordinates within the original image are already in variables X and Y.
But these coordinates have the reference right in the centre of the square, I assume you want the coordinates reference on the bottom left corner.
3.
Now let's generate the tiles 100x100. Since the distance you require between any adjacent points has to be at least 151 (I am using 150) there may be some empty blocks
% generating tiles
L=100
N=W0/L
B=zeros(L,L,N);
for k=1:1:N
for s=1:1:N
B(:,:,k+s-1)=A((s-1)*L+[1:1:L],(k-1)*L+[1:1:L]);
end
end
bxn=0;byn=0; % relative coordinates
the 20x20 images with the same scattered points are contained in B.
B(:,:,1) is the bottom left corner image. B(:,:,20) is the top left corner image. B(:,:,380) is the bottom right corner image. B(:,:,400) is the top right corner image.
4.
Result
the absolute coordinates are contained in X and Y.
As mentioned above the 100x100 images are contained in B.
The relative coordinates of the scattered points in each 100x100 are also available in variables bxn and byn. If empty then there's no point.
5.
Please not that since I simulate the points with random generations each time the obtained coordinates are different.
6.
For this example note that the very 1st point in the 1st 100x100 image has coordinates [22 4] x=22 y=4.
Since it's the 1st image, such coordinates exactly match the coordinates of the 1st 100x100 image, let's check plotting the 1st 5 100x100 images
for d=1:1:5
[bx,by,vx]=find(B(:,:,d));
bxn=[bxn bx]; byn=[byn by];
fn=figure(2+d);
bx=bx(:);by=by(:);
for s=1:1:numel(bx)
plot(bx(s),by(s),'sr');
axis([-2 L+2 -2 L+2]);hold('all');
end
axn=gca;
axn.DataAspectRatio=[L L 1];
end
bxn(1)=[];byn(1)=[];
the 1st image
has 1 point, checking coordinates with the marker
for the 2nd image, 2nd block from bottom left and 1 block up, only the x coordinate coincides with the original image coordinates:
the marker on 2nd point in original big image
and the 2nd 100x100 image with marker
So, Dritan Nikolla
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG