Image sequence listing ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • majestik666@gmail.com

    Image sequence listing ...

    Am not sure if it's been asked before (did a search but didn't come up
    with anything
    related...).
    I'm trying to write some code to "collapse" image sequences into
    a single item , i.e.:
    image.1.exr
    image.2.exr
    ....
    image.100.exr

    into
    image.[1-100].exr

    This is for display only so i do not show up 100 files but only one
    as some file managers do.

    Anyone got any info on doing this quickly ?

    I use Boost already in my app, so I guess the regex boost lib could
    help
    but not really sure of the most efficient way of doing it
  • Victor Bazarov

    #2
    Re: Image sequence listing ...

    majestik666@gma il.com wrote:
    Am not sure if it's been asked before (did a search but didn't come up
    with anything
    related...).
    I'm trying to write some code to "collapse" image sequences into
    a single item , i.e.:
    image.1.exr
    image.2.exr
    ...
    image.100.exr
    >
    into
    image.[1-100].exr
    >
    This is for display only so i do not show up 100 files but only one
    as some file managers do.
    >
    Anyone got any info on doing this quickly ?
    What's your C++ language question? Are you trying to declare an array
    to help you manage the sequence? You can also do it using 'std::map'
    or 'std::vector', but I am unsure what to recommend since you didn't
    show any code, and C++ doesn't have a definition of "image", nor does
    it have a definition of "collapsing " of those.
    I use Boost already in my app, so I guess the regex boost lib could
    help
    but not really sure of the most efficient way of doing it
    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • majestik666@gmail.com

      #3
      Re: Image sequence listing ...

      On Dec 20, 12:43 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
      majestik...@gma il.com wrote:
      Am not sure if it's been asked before (did a search but didn't come up
      with anything
      related...).
      I'm trying to write some code to "collapse" image sequences into
      a single item , i.e.:
      image.1.exr
      image.2.exr
      ...
      image.100.exr
      >
      into
      image.[1-100].exr
      >
      This is for display only so i do not show up 100 files but only one
      as some file managers do.
      >
      Anyone got any info on doing this quickly ?
      >
      What's your C++ language question? Are you trying to declare an array
      to help you manage the sequence? You can also do it using 'std::map'
      or 'std::vector', but I am unsure what to recommend since you didn't
      show any code, and C++ doesn't have a definition of "image", nor does
      it have a definition of "collapsing " of those.
      >
      I use Boost already in my app, so I guess the regex boost lib could
      help
      but not really sure of the most efficient way of doing it
      >
      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask
      Well I guess my c++ question is about
      how do you list a folder, and while doing that
      collapsing the filenames that are in the form prefix.%d.suffi x
      into "groups" like prefix.[first-last].suffix
      it's not image related really, just about how to work out
      the strings to collapes into one.

      Comment

      • Victor Bazarov

        #4
        Re: Image sequence listing ...

        majestik666@gma il.com wrote:
        [..]
        Well I guess my c++ question is about
        how do you list a folder, and while doing that
        collapsing the filenames that are in the form prefix.%d.suffi x
        into "groups" like prefix.[first-last].suffix
        it's not image related really, just about how to work out
        the strings to collapes into one.
        Ah... OK. Folders aside, files aside, your question is what you
        should do to form "blah.[N-M].blah" if you have a bunch of strings
        all containing "blah.<N>.blah" , "blah.<N+1>.bla h", etc., until the
        "blah.<M>.b lah" where N and M are two numbers. Right?

        This is not a C++ language question. It's an algorithm question.
        You need an algorithm for string processing. I would probably
        suggest something like

        // find the beginning of the sequence
        int N;
        for (N = 0; N < INT_MAX; ++N) {
        std::ostringstr eam os;
        os << "prefix." << N << ".suffix";
        std::string filename(os.str ());
        if (/* exists the file with pattern 'filename' */)
        break;
        }
        // now N is your start
        int M;
        for (int M = N; M<INT_MAX; ++M) {
        std::ostringstr eam os;
        os << "prefix." << M << ".suffix";
        std::string filenam(os.str( ));
        if (/* does NOT exist file with pattern 'filename' */)
        break;
        }
        if (--M N) { // got the sequence!
        std::ostringstr eam os;
        os << "prefix.[" << N << '-' << M << "].suffix";
        return os.str(); // here you go
        }
        else { // it's a single file, maybe.
        ...
        }

        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask


        Comment

        • majestik666@gmail.com

          #5
          Re: Image sequence listing ...

          On Dec 20, 1:27 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
          majestik...@gma il.com wrote:
          [..]
          Well I guess my c++ question is about
          how do you list a folder, and while doing that
          collapsing the filenames that are in the form prefix.%d.suffi x
          into "groups" like prefix.[first-last].suffix
          it's not image related really, just about how to work out
          the strings to collapes into one.
          >
          Ah... OK. Folders aside, files aside, your question is what you
          should do to form "blah.[N-M].blah" if you have a bunch of strings
          all containing "blah.<N>.blah" , "blah.<N+1>.bla h", etc., until the
          "blah.<M>.b lah" where N and M are two numbers. Right?
          >
          This is not a C++ language question. It's an algorithm question.
          You need an algorithm for string processing. I would probably
          suggest something like
          >
          // find the beginning of the sequence
          int N;
          for (N = 0; N < INT_MAX; ++N) {
          std::ostringstr eam os;
          os << "prefix." << N << ".suffix";
          std::string filename(os.str ());
          if (/* exists the file with pattern 'filename' */)
          break;
          }
          // now N is your start
          int M;
          for (int M = N; M<INT_MAX; ++M) {
          std::ostringstr eam os;
          os << "prefix." << M << ".suffix";
          std::string filenam(os.str( ));
          if (/* does NOT exist file with pattern 'filename' */)
          break;
          }
          if (--M N) { // got the sequence!
          std::ostringstr eam os;
          os << "prefix.[" << N << '-' << M << "].suffix";
          return os.str(); // here you go
          }
          else { // it's a single file, maybe.
          ...
          }
          >
          V
          --
          Please remove capital 'A's when replying by e-mail
          I do not respond to top-posted replies, please don't ask
          well yes it's the problem, but the initial conditions are a bit
          different
          let's say i have a list of strings in the form you mentioned
          prefix.<N>.suff ix, I can have different prefixes etc.
          but I guess I cannot avoid going through the files one by one
          and looking if i can join it with other files in the same folder.

          Comment

          • Victor Bazarov

            #6
            Re: Image sequence listing ...

            majestik666@gma il.com wrote:
            On Dec 20, 1:27 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
            >majestik...@gm ail.com wrote:
            >>[..]
            >>Well I guess my c++ question is about
            >>how do you list a folder, and while doing that
            >>collapsing the filenames that are in the form prefix.%d.suffi x
            >>into "groups" like prefix.[first-last].suffix
            >>it's not image related really, just about how to work out
            >>the strings to collapes into one.
            >>
            >Ah... OK. Folders aside, files aside, your question is what you
            >should do to form "blah.[N-M].blah" if you have a bunch of strings
            >all containing "blah.<N>.blah" , "blah.<N+1>.bla h", etc., until the
            >"blah.<M>.blah " where N and M are two numbers. Right?
            >>
            >This is not a C++ language question. It's an algorithm question.
            >You need an algorithm for string processing. I would probably
            >suggest something like
            >>
            > // find the beginning of the sequence
            > int N;
            > for (N = 0; N < INT_MAX; ++N) {
            > std::ostringstr eam os;
            > os << "prefix." << N << ".suffix";
            > std::string filename(os.str ());
            > if (/* exists the file with pattern 'filename' */)
            > break;
            > }
            > // now N is your start
            > int M;
            > for (int M = N; M<INT_MAX; ++M) {
            > std::ostringstr eam os;
            > os << "prefix." << M << ".suffix";
            > std::string filenam(os.str( ));
            > if (/* does NOT exist file with pattern 'filename' */)
            > break;
            > }
            > if (--M N) { // got the sequence!
            > std::ostringstr eam os;
            > os << "prefix.[" << N << '-' << M << "].suffix";
            > return os.str(); // here you go
            > }
            > else { // it's a single file, maybe.
            > ...
            > }
            >>
            >V
            >--
            >Please remove capital 'A's when replying by e-mail
            >I do not respond to top-posted replies, please don't ask
            >
            well yes it's the problem, but the initial conditions are a bit
            different
            let's say i have a list of strings in the form you mentioned
            prefix.<N>.suff ix, I can have different prefixes etc.
            but I guess I cannot avoid going through the files one by one
            and looking if i can join it with other files in the same folder.
            It's all in how you check for the existence of the file. If your
            system allows enumerating with a pattern (like "*.1001.img "), then
            you're in luck and you need to put the asterisk instead of 'prefix'.

            The algorithm as I wrote it is also substandard from the performance
            point of view. It would be nice if you could simply get all the
            strings (names of the files) fitting the pattern "*.[0-9]+.suffix",
            and sort them while disregarding the prefix (you need a custom
            comparison functor for that). Then you simply have an array of
            strings, and the very first one contains your N, which you can
            simply extract from the string itself. And you can simply keep
            extracting the number from each string and compare it to what you
            expect (previous + 1). If it isn't, your sequence is over, and
            you may need to start another sequence...

            Anyway, this doesn't seem to be a C++ topic either. Try posting to
            comp.programmin g, the general algorithm discussion newsgroup.

            V
            --
            Please remove capital 'A's when replying by e-mail
            I do not respond to top-posted replies, please don't ask


            Comment

            Working...