I searched the site but I could not find any solution to this problem. It is a pretty simple thing I am trying to accomplish, but I really cannot figure out how to do it.
I have a directory of images. I am running an experiment where, on a slider, people will rate how well two images relate to each other. Programming the slider part is easy in MATLAB. However, I am having a problem figuring out how to get the images to work. I want two pictures from the directory to appear randomly on the screen, such that by the end of the experiment every possible image pair will have been rated.
So if the images are:
dog
cat
mouse
hat
I want:
dog cat
dog mouse
dog hat
cat mouse
cat hat
mouse hat
How do I get MATLAB to do this?
First, I am having trouble getting it to display a random image in the first place. My script is something like this, but it doesn’t work:
dfiles = d(~[d.isdir]);
genRandNum = randperm(length(dfiles));
filename = dfiles(genRandNum(i)).name;
imageName = fullfile('Desktop', 'SEMREL', 'Pictures', filename);
imshow(imageName, 'Parent');
But once I get that working, how do I get it to display two images next to each other on the screen? And how do I weight the random generation so that I only get each image pair once? If I just tell it not to repeat an image that won’t work, because each individual image will have to be paired with several other images.
Help? I literally cannot find a way to do this.
Starting with your variable
dfiles, you can generate a set of every possible two-image pairing using the functions NCHOOSEK and RANDPERM like so:And each row of
comboswill have a unique pair of indices into your set of image files stored indfiles. Keep in mind that this could be a lot of unique pairings. For just 80 images, you will have 3,160 total pairwise combinations. That’s a very long experiment!With regard to displaying both images side-by-side, you can use SUBPLOT in conjunction with your calls to IMSHOW: