Presenting simultaneously 40 images, non overlapping.
Afficher commentaires plus anciens
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, 100x100 pixels each, 20 on the right side of the screen, 20 on the left, simultaneously. The screen has a 1600x1200 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
1 commentaire
utkarsh kumar singh
le 27 Juin 2017
sir can you please how to write a code for generatin 6 block module in same plane for vlsi floorplanning. its urgent
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 20 Juin 2017
2 votes
Try the montage() function.
4 commentaires
Dritan Nikolla
le 20 Juin 2017
Image Analyst
le 20 Juin 2017
So just use the colon operator, like
x = 1 : 150 : (3000-100)
Dritan Nikolla
le 20 Juin 2017
Image Analyst
le 21 Juin 2017
Modifié(e) : Image Analyst
le 21 Juin 2017
I have a demo that gives random locations with no point closer to any other point than a specified distance. Here it is:
% Creates a random pattern of points with no point closer to another than some specified distance.
clc;
x = rand(1, 10000);
y = rand(1, 10000);
minAllowableDistance = 0.05;
numberOfPoints = 300;
% Initialize first point.
keeperX = x(1);
keeperY = y(1);
% Try dropping down more points.
counter = 2;
for k = 2 : numberOfPoints
% Get a trial point.
thisX = x(k);
thisY = y(k);
% See how far is is away from existing keeper points.
distances = sqrt((thisX-keeperX).^2 + (thisY - keeperY).^2);
minDistance = min(distances);
if minDistance >= minAllowableDistance
keeperX(counter) = thisX;
keeperY(counter) = thisY;
counter = counter + 1;
end
end
plot(keeperX, keeperY, 'b*');
grid on;

As usual a rejection method to determine random areas without overlap:
function Pos = GetPositions
count = 0;
success = false;
while ~success
count = count + 1;
if count > 100 % Try it 100 times
error('Cannot find enough positions.');
end
Pos = GetPositionsCore;
success = ~any(isnan(Pos));
end
% Draw a test to show success (remove this from productive code):
figure;
axes('XLim', [1, 800], 'YLim', [1, 1200], 'NextPlot', 'add');
for k = 1:size(Pos, 1)
line([Pos(k,1), Pos(k,1), Pos(k,1)+100, Pos(k,1)+100, Pos(k,1)], ...
[Pos(k,2), Pos(k,2)+100, Pos(k,2)+100, Pos(k,2), Pos(k,2)]);
end
end
function Pos = GetPositionsCore
PicSize = 100;
n = 20; % Number of pictures
Area = [800, 1200]; % Available area (half of the screen)
Space = 50; % Empty pixels in X and Y direction separately
Pos = nan(n, 2); % Pre-allocate
for k = 1:n
found = false;
count = 0;
while ~found
X = randi([1, Area(1) - PicSize]);
Y = randi([1, Area(2) - PicSize]);
if all(abs(X - Pos(1:k-1, 1)) > Space + PicSize | ...
abs(Y - Pos(1:k-1, 2)) > Space + PicSize)
% Distance to all former found points is accepted:
found = true;
Pos(k, 1) = X;
Pos(k, 2) = Y;
end
count = count + 1; % Security limit
if count > 1e5
return;
end
end
end
end
20 images with 100x100 and 50 pixels distance is rather dense. Therefore about every 100th trial to run GetPositionCore fails. Therefore it is tried multiple times. If you want to find much more than 20 positions, this approach is not sufficient.
This is called for the right and the left side separately. Add 800 to the X-position of the images for the right side.
The code needs about 0.1 seconds.
Catégories
En savoir plus sur Blocked Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





