I don't know how to start but by sharing the 'folder' structure and its elements. Here they are: Google Drive Link to the ZIP The images to group have been downloaded from PMD Sprites Collab Next, I want to share the MATLAB code I am working with to try to 'group the images'. It was devised thanks to MATLAB: Create and Explore Datastore for Image Classification:
filepath='C:\portrait'; % above the unzipped folder, better full file path
dataFolder=fullfile(filepath);
PortraitIMDS=imageDatastore(filepath,...
'IncludeSubfolders',true,...
'LabelSource','foldernames');
numObs=length(PortraitIMDS.Labels);
numObsPerClass=countEachLabel(PortraitIMDS);
%numObs
numObsPerClass
%numObsToShow=8;
classes=compose('d', 0:905);
classSID=zeros(1,length(classes));
for i=1:length(classes)
classSID(i)=str2num(char(classes(i)));
end % this small part would be used to make a loop over 'class' variable below.
class = "0001"; % between "0000" y "0905"
% obtain all the images in groups of 8.
idxClass = find(PortraitIMDS.Labels == class);
size(idxClass)
%numObsPerClass(str2num(size(idxClass,1)) 1,2)
%idx = randsample(idxClass,numObsToShow,false);
% I DO NOT want it randomised, I want everything in order
imshow(imtile(PortraitIMDS.Files(idxClass),'GridSize',[2 4],'ThumbnailSize',[144 144]));
Ok, so, as the code mentions, I do not want a randsample of the idxClass added by class. I don't know how to retrieve an ordered sample of data of idxClass, but only this randomized sample of data. I must mention that there are 906 classes in total, from 0 to 905, and the image count inside them can range from a whole lot of nearly 1500 png's in only the 0001 class to nothing in some classes, where others can have 40, 25, 16, 8, etc.
I ask this question because I don't know how to proceed in order to retrieve all the images Class by Class, group by group, in order. The groups of 8 with the ThumbnailSize I am looking for are already obtained via 'GridSize',[2 4],'ThumbnailSize',[144 144]));
, but I'd like to go over all the images grouping them in 2x4 grids whether they are from a class or not, jumping to the next image after finishing the 2x4 grid. I do not remember how many images are in total, so I am sure it won't fit perfectly in groups of 8.
I thought of a loop over 'classes' would be useful, but it won't open all the images but instead the first 8 ones of each class with the current setup... (I haven't written yet the classSID on class ="0001"
, but that would be the idea)
Maybe it is something not viable with MATLAB, so I am also open to answers in Python. Remember, the point is to group the images of the zip in 1 in ordered groups of 8. You know, ordered combinations without any single repetition of N elements taken 8 by 8.
CodePudding user response:
Ok, so it was a shuffling problem that has already been solved via this code:
filepath='C:\portrait'; % full file path (not mine)
filelist=dir(fullfile(filepath,'**\*.png'));
filelist = filelist(~[filelist.isdir]);
k=1
while k < size(filelist,1) 1
photo_1=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_2=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_3=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_4=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_5=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_6=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_7=strcat(filelist(k).folder,'\',filelist(k).name);
k=k 1;
photo_8=strcat(filelist(k).folder,'\',filelist(k).name)
fig=imtile({photo_1,photo_2,photo_3,photo_4,photo_5,photo_6,...
photo_7,photo_8},'GridSize',[2 4],'ThumbnailSize',[144 144]);
imshow(fig)
imwrite(fig,strcat('Photosfrom',num2str(k-8),'to',num2str(k-1),'.png'))
k=k 1
end
So yeah, the problem was sort of processing the data which are image, not image processing itself as it was already solved...