Reading Multiple Images from Folder
4 次查看(过去 30 天)
显示 更早的评论
I have a folder named 'ImageSet1',it consist of 20 images named as a 1.jpg,2.jpg...20.jpg.
Here i want to read images from 1 to 10 and then from 11 to 20 separately. it means, when i read image 1,immediately i have to read 11th image and when i read image 2,immediately i have to read 12th image in a loop and so on.. Here is the my code
sdirectory = 'ImageSet1';
jpegfiles = dir([sdirectory '/*.jpg']);
for k = 1:length(jpegfiles)/2
filename = [sdirectory '/' jpegfiles(k).name];
I = imread(filename);
figure;imshow(I)
filename1=[sdirectory '/' jpegfiles(10+k).name];
I1=imread(filename1);
figure;imshow(I1)
end
This code is not reading in order,like 1 and 11th image,2 and 12th image...
Does any one know please correct this code or any other method..?
2 个评论
Stephen23
2015-5-27
编辑:Stephen23
2015-5-27
It sorts according to any numeric values in the strings, and also sorts the file extensions separately:
B = {'test2.m'; 'test10-old.m'; 'test.m'; 'test10.m'; 'test1.m'};
sort(B) % wrong numeric order!
ans = {
'test.m'
'test1.m'
'test10-old.m'
'test10.m'
'test2.m'}
natsortfiles(B) % correct numeric order and shortest first:
ans = {
'test.m'
'test1.m'
'test2.m'
'test10.m'
'test10-old.m'}
回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!