1

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.

user2355306
  • 367
  • 1
  • 6
  • 14
  • Related questions might be [this](http://stackoverflow.com/questions/14213442/matlab-file-name-with-zero-padded-numbers/14214042#14214042) and [this](http://stackoverflow.com/questions/15366374/how-can-i-load-100-files-with-similar-names-and-or-string-in-just-one-step-in-ma/15366423#15366423). – Shai Jun 17 '13 at 12:41
  • Next time, it would be nicer if you could provide a more concise code example that demonstrated the error you are having + a better localization/description of the error message and the exact location that invoked it. – Shai Jun 17 '13 at 12:43

1 Answers1

1

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) );
Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • thank you very much for your quick reply. sorry I had problem with my internet and it made this delay. What I want to say with **. format(fname)** is to get the format of the input file which is .tif. – user2355306 Jun 17 '13 at 14:22
  • @ Shi: Thank you for the edition. well, I have faced a problem now concerning the new files name. what I expected was to have outputs as (outimage1,outimage2,...,outimage10,outimage11) but what I have received is (outimage1,outimage15,...,outimage127,outimage141). do you think by introducing another loop I can solve this problem? or maybe introducing another indexing for the output file? – user2355306 Jun 17 '13 at 15:40
  • @user2355306 i think the most simple way would be to introduce another index. – Shai Jun 17 '13 at 15:41
  • Thank you for your advice. I did this new change but unfortunately it does not work. the output images are empty :( what do you think would be the problem? . you can find the new edited one in the above code. – user2355306 Jun 18 '13 at 09:09