% Create novel objects from snodgrass objects - with NO HOLES % Randomize rotation and placement of objects with respect to each other % Control for only one area of change %clear all; function create_stim_onechange(num_objects) %num_objects = 345:500; % number of novel objects to create num_bases = 4; % number of base objects to use rand('state',sum(100*clock)); % Reset random number generator each time. % Use four objects - for now, forget about jitter m = 480; n = 640; % Absolute image dimensions of base objects for o = num_objects o go = 1; while go disp(['Creating object ' num2str(o)]) obj = zeros(m,n,num_bases); for b = 1:num_bases obj(:,:,b) = imread(['base_objects/' num2str(ceil(rand*260)) '.bmp'],'bmp'); obj(:,:,b) = imrotate(obj(:,:,b),rand*360,'crop'); end obj2 = obj; obj2(:,:,b+1) = imread(['base_objects/' num2str(ceil(rand*260)) '.bmp'],'bmp'); obj2(:,:,b+1) = imrotate(obj2(:,:,b+1),rand*360,'crop'); obj = sum(obj,3); obj = obj>0; obj2 = sum(obj2,3); obj2 = obj2>0; % Put fill operation here - gets rid of holes back = imfill(obj,[1 1]); back = double(back)-obj; obj = double(back==0); back = imfill(obj2,[1 1]); back = double(back)-obj2; obj2 = double(back==0); % Ensure there is only one connected change to the object mask = ~(obj2-obj); % isolate changes [i,j] = find(mask==0); % locate changes if length(i) == 0 % there is no change go = 1; % Essentially, do nothing. else ind = ceil(rand*length(i)); % randomly select one change mask = imfill(mask,[i(ind) j(ind)],4); obj2 = double(mask).*obj2; % Recreate obj2 to have a single change % Display figure figure(2); clf; colormap('gray'); subplot(1,2,1); imagesc(obj); axis equal; subplot(1,2,2); imagesc(obj2); axis equal; % Display change figure(3); clf; imagesc(obj2-obj); axis equal; ans = input('Accept? ','s'); if ans=='y' imwrite(obj,['pair_objects/' num2str(o) '.bmp'],'bmp'); imwrite(obj2,['pair_objects/' num2str(o+1000) '.bmp'],'bmp'); go = 0; end end end end