I have some geotif files and I am trying to create a mosaic out of them. I have tried to put the images beside each other first in a row and then tried to join the in columns and have the final mosaic. I would like to have the output file with the save number of the loop (outimage1,outimage2,..). I would like to know how should I introduce the output file with the sequence of the loop number.
I would be happy if someone help me find my mistake in the following code.
close all;
clear all;
clc;
path = 'E:\MATLAB\...\tifs\';
path2 = 'E:\MATLAB\...\tifs\out\';
matfiles = dir(fullfile('E:', 'MATLAB',...,'tifs','*.tif'));
files = {matfiles.name};
lf=length(files);
image_row = [];
for L=1:11
for k=1:14:lf
fname = matfiles(k).name;
fullname = horzcat (path,fname);
infile = imread (fullname);
image_row= [image_row,infile];
[~, ~, ext] = fileparts(fname);
outimage = fullfile( path2, sprintf('outimage%d%s', L, ext) );
imwrite(image_row,outimage);
end
end
Yours assistant is highly appreciated.
I am not familiar with a matlab syntax k. format(fname)
.
If you want to do string formatting in Matlab - read this first.
A solution for your problem might be
outimage = fullfile( path2, sprintf('outimage_%03d_%s', k, fname ) );
EDIT:
following comment by OP, get the file format (tif):
[~, ~, ext] = fileparts(fname);
outimage = fullfile( path2, sprintf('outimage%d.%s',ext) );