使用Matlab的马赛克图像

时间:2014-10-20 08:32:07

标签: matlab mosaic

我有一个关于我该怎么做的问题。我有一个包含不同图像的文件夹(每个图像有3个波段)。例如。

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);

如何使用始终位于相同输出名称位置的日期编号(244,250 ...)进行自动化?

真的很感激任何建议。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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