subset of pictures into one picture

1 view (last 30 days)
Itzik
Itzik on 22 Sep 2014
Commented: Itzik on 23 Sep 2014
Hi,
I'm new to matlab and I need to program an experiment in our lab. I have 4 sets of 8 pictures. I need to create 30 pictures, such that each picture containing 4 subsets of 4 (with no replacement) from each set (matrix of 4*4 pictures). the pictures shall be chosen randomly and the number of appearances of each picture must be same. How do i do it? I found the function "randperm" to get the subsets, but I still need to figure out the other parts.
Thanks,
Itzik

Answers (1)

Image Analyst
Image Analyst on 22 Sep 2014
Here's a good start:
folder = pwd; % Wherever...
filePattern = fullfile(folder, '*.*'); % Or *.PNG or whatever extension you want.
baseFileNames = dir(filePattern)
numberOfFiles = length(baseFileNames)
numberOfOutputImages = 30;
if numberOfOutputImages > floor((numberOfFiles-3)/4)
numberOfOutputImages = floor((numberOfFiles-3)/4)
end
theOrder = randperm(numberOfFiles, numberOfOutputImages*4)
for k = 1 : numberOfOutputImages
index = (k-1)*4+1
filename1 = fullfile(folder, baseFileNames(theOrder(index)).name)
filename2 = fullfile(folder, baseFileNames(theOrder(index + 1)).name)
filename3 = fullfile(folder, baseFileNames(theOrder(index + 2)).name)
filename4 = fullfile(folder, baseFileNames(theOrder(index + 3)).name)
allFilenames = {filename1, filename2, filename3, filename4}
% Display a montage of the 4 images.
montage(allFilenames);
% Use export_fig() if you want to save the 4 image montage.
end
  1 Comment
Itzik
Itzik on 23 Sep 2014
thanks, it looks like really good starting point for me.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!