2014-10-20 239 views
0

我有一个关于如何执行某些操作的问题。我有一个具有不同图像的文件夹(每个图像有3个乐队)。例如。使用Matlab进行马赛克图像

Img_244_234_1_1.tif 
Img_244_234_1_2.tif 

Img_250_234_1_1.tif 
Img_250_234_1_2.tif 

我需要做的是按名称拼接图像(例如,所有数字244,250 ...)。现在,我做手工那样:

image1 = imread('C:\Prueba\Img_244_234_1_1.tif','tif'); 
image2 = imread('C:\Prueba\Img_244_234_1_2.tif','tif'); 
image3 = imread('C:\Prueba\Img_250_234_1_1.tif','tif'); 
image4 = imread('C:\Prueba\Img_250_234_1_2.tif','tif'); 

image_result1 = cat(2,image1,image2); 
image_result1 = cat(2,image1,image2); 

我怎样才能使自动化使用日期数量(244250 ...)总是它在相同的输出名称的位置?

真的很感谢任何建议。

回答

0

您可以使用循环(如for x=[244,255])和字符串的串联:['C:\Prueba\Img_' x '_234_1_1.tif']将评估为'“C:\ Prueba \ Img_244_234_1_1.tif”如果x是244

0

如果你的文件名是良好的组织,那么下面的代码应该可以工作。

cd('C:\Prueba\'); 
files = dir('*.tif'); 
for i=1:2:numel(files) 
    image1 = imread(files(i).name); 
    image2 = imread(files(i+1).name); 
    image_result = cat(2,image1,image2); 
end