Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Need Help: Load Multiple Images

2007-09-18
2013-05-02
  • hello there. i need help. im using Devil to enhance frames of images. so i need to load and process about hundred or thousand of images at same time. im using devil to adjust the contrast of images. can any one help me on how how it could be done. does devil support this. thanks.

     
    • Nicolas Weber
      Nicolas Weber
      2007-09-18

      This should be possible. Call ilInit(); iluInit();, then load each image with ilLoadImage("bla.png");, adjust the contrast of the current image with iluContrast(float); (play with the parameter) and store it back to disk with ilSaveImage("bla_contrast.png"). Repeat for all images.

       
      • okay. but how about if i want to process about 100 of image. do i have to repeat the coding for hundred times. this will result for lengthy coding. is there any simple way. the images is name in sequent. i like to use the program in parallel computing. 

         
        • Nicolas Weber
          Nicolas Weber
          2007-09-24

          Have you heard of the "for loop"? Stuff all image names in an array/vector/whatever, then iterate over that array. This way, you have to write the image handling code only once, but it'll be executed for every image. Sounds like magic, I know. But it works.

           
          • i still have prob on how to input multiple file. below is my sample prog.
            // Required include files.
            #include <il.h>
            #include <ilu.h>
            #include <stdio.h>

            int main(int argc, char **argv)
            {
                ILuint    ImgId;
                ILenum    Error;

                // We use the filename specified in the first argument of the command-line.
                if (argc < 2) {
                    fprintf(stderr, "DevIL_test : DevIL simple command line application.\n");
                    fprintf(stderr, "Usage : demo1.exe <file> [output]\n");
                    fprintf(stderr, "Default output is test.png\n");
                   
                    return 1;
                }

                // Check if the shared lib's version matches the executable's version.
                {
                if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
                    iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
                    printf("DevIL version is different...exiting!\n");
                    return 2;
                    }

                // Initialize DevIL.
                ilInit();

                // Generate the main image name to use.
                ilGenImages(1, &ImgId);

                // Bind this image name.
                ilBindImage(ImgId);

                // Loads the image specified by File into the image named by ImgId.
                {
                    if (!ilLoadImage(argv[1]))
                    printf("Could not open file...exiting.\n");
                    return 3;
               

                // Display the image's dimensions to the end user.
                printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n",
                       ilGetInteger(IL_IMAGE_WIDTH),
                       ilGetInteger(IL_IMAGE_HEIGHT),
                       ilGetInteger(IL_IMAGE_DEPTH),
                       ilGetInteger(IL_IMAGE_BITS_PER_PIXEL));
                       iluContrast(0.5);

                // Enable this to let us overwrite the destination file if it already exists.
                ilEnable(IL_FILE_OVERWRITE);
               
                // If argv[2] is present, we save to this filename, else we save to test.png.
                if (argc > 2)
                    ilSaveImage(argv[2]);
                else
                    ilSaveImage("test.png");
               
                }
                // Simple Error detection loop that displays the Error to the user in a human-readable form.
                while ((Error = ilGetError())) {
                    printf("Error: %s\n", iluErrorString(Error));
                }

                return 0;
                }
            }

            it same with the simple prog. i only add the contrast function. my question is where i have to add the loop function to input multiple file. thanks.

             
            • Nicolas Weber
              Nicolas Weber
              2007-09-30

              If you want to use this program, you have to put the loop in a shell script. Are you using windows or unix? In windows, you can do something like

                  for %i in (*.bmp) do my_convert_program %i %i_converted.png

              in cmd.

              my_convert_program is your compiled program (needs to be in the same folder as your images are in (you have to cd to this directory in cmd).

              You can do something similar in C, but this is probably the easiest way. You're welcome.

              Before asking another question, use Google and read a few books on programming. I won't answer further questions on this basic level anymore -- it takes me more time to write an answer than it you seem to take to do some research.

               
              • thanks a lot for your help. your really help.