Grouping images from multiple folders

조회 수: 1 (최근 30일)
shivasakthi
shivasakthi 2017년 1월 13일
댓글: Walter Roberson 2017년 1월 14일
I have 120 folders each containing 46 images belonging to 46 categories. I have to take these individual images and make 46 folders (each for a separate category). Kindly help me with the code for this. Thanks in advance.
  댓글 수: 3
shivasakthi
shivasakthi 2017년 1월 14일
편집: shivasakthi 2017년 1월 14일
A small correction to the question. There are 119 folders, each containing 46 images. Yes the image categories are already known. The images are arranged in perfect order so that every two consecutive images belong to a different class. It means in every 119 folders, there are 23 classes (out of the 46 images). Now I need to create 23 different folders so that the first two images from every 119 folder should go to the first of 23 folders. The third and fourth image from every 119 folders should go to the 2nd of the 23 folders and so on. Kindly help me with the matlab code for this.
Walter Roberson
Walter Roberson 2017년 1월 14일
I suspect that you are using MS Windows,and in particular an NTFS file system. NTFS does not document the order that it stores files, and I gather that it is permitted for disk optimization utilities to change the order of files within a directory. There is no real meaning to "consecutive images" in the system, or rather the order can change at any time.
I would suggest to you that you have been thinking that the files are arranged in alphabetical order. I speculate that the information about which class any given file belongs to is somehow represented as part of the file name. If that is correct then it would help if you could describe the structure of the file names and which part includes the needed information.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2017년 1월 14일
"The first two images" is ambiguous.
But to create 23 folders, use sprintf() and mkdir()
for k = 1 : 23
folder = sprintf('Folder %d', k);
if ~exist(folder, 'dir')
mkdir(folder);
end
end
  댓글 수: 2
shivasakthi
shivasakthi 2017년 1월 14일
Many thanks image analyst, for helping with creating the 23 folders. The issue is to copy every two consecutive images from each of the 119 folders to these 23 different folders as I explained before. Kindly help me with matlab code for this.
Image Analyst
Image Analyst 2017년 1월 14일
You should use one of the two code samples in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F Have the loop step in steps of 2 instead of 1.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by