1

How can I pass an array of filenames into the following method:

public static double getFitness(int x, int y, int r, BufferedImage image);

I currently have a method which creates an array of filenames from a given directory:

//Default image directory (to convert to greyscale).
static File dir = new File("images");
//Array of original image filenames.
static File imgList[] = dir.listFiles();

public static void processGreyscale(){
    if(dir.isDirectory()){
        for(File img : imgList){
            if(img.isFile()){
                //functions are carried out here.
            }
            else{
                                    //functions are carried out here.
            }
        }
    }
}

The getFitness method scores the fitness of an image (...BufferedImage image);) based on the main region of interest (ROI).

What I am looking for is a way to run the getFitness method on the array of filenames; something like this:

public static double getFitness(int x, int y, int r, fileArray)

Can this be done?

UPDATE:

Thank you all for your great suggestions; however, I should mention that I wish to leave the method parameters the same/unchanged as the fitness function is affected (negatively) if I change the passed parameters.

Is there any way that I can run the fitness function on all files/filenames within imgList[]?

What I'm hoping for is this:

public static double getFitness(int x, int y, int r, BufferedImage image){
    use filenames stored in imgList[] to take place of 'image'
    getFitness of `image`
    next image name
}

Is this possible?

1

4 Answers 4

3

Yes, it is possible.

This is the method signature:

public static double getFitness(int x, int y, int r, File[] fileArray)

And this is the calling code:

getFitness(1, 1, 1, imgList);
Sign up to request clarification or add additional context in comments.

Comments

1

Just pass the array?

public static double getFitness(int x, int y, int r, File[] files);

Comments

0

You can specify parameter type as File[] fileArray

Comments

0

You can do File fileArray[] = new File[numberOfFiles]; then specify a counter to store in the array such as counter = 0 and increment the value of counter each time fileName is added to the array fileArray[counter] = img.getName(); counter++;

then send the array in your desired method public static double getFitness(x, y, r, fileArray);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.