How to tell MATLAB to open and save specific files in the same directory -


I have to run an image processing algorithm on a number of images in a directory.

Code> name_typeX.tif , so there are different types of images for the given name.

Image processing algorithm takes an input image and output an image result.

I have to save this result as name_typeX_number.tif , where number is also an output from the algorithm given image

< P> Now ..

How do I tell MATLAB to open a specific typeX file? Also keep in mind that there are other non-TIF files in the same directory.

How to save the result as name_typeX_number.tif ?

The result can be saved in a single directory where input images are present. How do I tell MATLAB to treat the results that are saved as input images?

I have to run it as a background code on the server ... so no user input is allowed.

It seems that you want to get all the files in a directory, whose name is a certain format , Then process them automatically You can do this by using the function to get a list of file names in the existing directory, then using the function to find the file name, you can match a certain pattern. Here's an example:

  fileData = dir (); % #% # Get the structure of data for the files in the existing directory fileName = {fileData.name}; Match the file names in a cell array index = regexp (filename, ...% # with a file name if it is '^ [A-Za-z] + _ Type \ d + \. Tif $') ; % # Was executed with at least one letter, # _type`, at least one number,% #, and #% with '.tif' inFiles = fileNames (~ SELFAN (@IsMPTY, index) ; % # Get the names of the matching% # files in a cell array  

Once you create a cell array of files in the inFiles that you want the naming pattern you want , You can simply loop on the files and you can do your processing. For example, your code might look like this:

  nFiles = numel (inFiles); Get the number of input files for% # IFile = 1: nFiles% # In the input files loop; File = files {iFile}; % # Get the input = file in the input file; Load% # image data [outImg, someNumber] = process_your_image (inImg); Execute image # file data = [strtok (inFile, '.') ... Remove the '.tif' from the% # input file, '_' ...% # attach an underscore, num2str (someNumber). Attach the% # number as a string, and '.tif']; Adding #% `.tif` to rewrite (outImg, outFile); % # Write a new image data at the end of a file  

The example function above,


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -