Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:54:23+00:00 2026-05-15T09:54:23+00:00

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

  • 0

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

An image is saved as name_typeX.tif, so there are X different type of images for a given name.

The image processing algorithm takes an input image and outputs an image result.

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

Now..

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

How to save the result as name_typeX_number.tif?

The results have to be saved in the same directory where the input images are present. How do I tell MATLAB NOT to treat the results that have been saved as an input images?

I have to run this as background code on a server… so no user inputs allowed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:54:24+00:00Added an answer on May 15, 2026 at 9:54 am

    It sounds like you are wanting to get all files in a directory whose names match a certain format, then process them all automatically. You can do this using the function DIR to get a list of file names in the current directory, then using the function REGEXP to find file names that match a certain pattern. Here’s an example:

    fileData = dir();             %# Get a structure of data for the files in the
                                  %#   current directory
    fileNames = {fileData.name};  %# Put the file names in a cell array
    index = regexp(fileNames,...                 %# Match a file name if it begins
                   '^[A-Za-z]+_type\d+\.tif$');  %#   with at least one letter,
                                                 %#   followed by `_type`, followed
                                                 %#   by at least one number, and
                                                 %#   ending with '.tif'
    inFiles = fileNames(~cellfun(@isempty,index));  %# Get the names of the matching
                                                    %#   files in a cell array
    

    Once you have a cell array of files in inFiles that matches the naming pattern you want, you can simply loop over the files and perform your processing. For example, your code might look like this:

    nFiles = numel(inFiles);    %# Get the number of input files
    for iFile = 1:nFiles        %# Loop over the input files
      inFile = inFiles{iFile};  %# Get the current input file
      inImg = imread(inFile);   %# Load the image data
      [outImg,someNumber] = process_your_image(inImg);  %# Process the image data
      outFile = [strtok(inFile,'.') ...   %# Remove the '.tif' from the input file,
                 '_' ...                  %#   append an underscore,
                 num2str(someNumber) ...  %#   append the number as a string, and
                 '.tif'];                 %#   add the `.tif` again
      imwrite(outImg,outFile);  %# Write the new image data to a file
    end
    

    The above example uses the functions NUMEL, STRTOK, NUM2STR, IMREAD, and IMWRITE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nothing looks out of place in your code. You are… May 15, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer Bill Karwin's code is almost correct. I made the needed… May 15, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer Some of the answers given here are either overcomplicated or… May 15, 2026 at 11:31 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.