Presenting simultaneously 40 images, non overlapping.
이전 댓글 표시
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
utkarsh kumar singh
2017년 6월 27일
sir can you please how to write a code for generatin 6 block module in same plane for vlsi floorplanning. its urgent
채택된 답변
추가 답변 (2개)
Image Analyst
2017년 6월 20일
2 개 추천
Try the montage() function.
댓글 수: 4
Dritan Nikolla
2017년 6월 20일
Image Analyst
2017년 6월 20일
So just use the colon operator, like
x = 1 : 150 : (3000-100)
Dritan Nikolla
2017년 6월 20일
Image Analyst
2017년 6월 21일
편집: Image Analyst
2017년 6월 21일
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.
카테고리
도움말 센터 및 File Exchange에서 Blocked Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





