Login  Register

Re: Opening images from Different folders for stacking

Posted by degussa on Dec 29, 2008; 10:05pm
URL: http://imagej.273.s1.nabble.com/Opening-images-from-Different-folders-for-stacking-tp3694155p3694160.html

degussa wrote
Johannes Schindelin wrote
Hi,

On Wed, 17 Dec 2008, degussa wrote:

> Johannes Schindelin wrote:
> >
> > for (i = 0; i < list1.length; i++) {
> > if (File.exists(dir2 + list1[i]) &&
> > File.exists(dir3 + list1[i])) {
> > // do your thing
> > }
> > }
> >
> > I agree with you on the repeating steps, but its necessary here
> > because the files i need must have just the last four numbers in the
> > file names common to them. The folders i am using have equal numbers
> > of files (1-1000), but different file name prefix such as
> > MW24C2_1_S101_0020( folder 1), MW24C2_2_S101_0020( folder 2),
> > MW24C2_3_S101_0020( folder 3).

Okay, fair enough.  Still, I would decouple that test, then (and maybe use
a higher-level language that has something like hashsets):

        function inList(list, extension, last4digits) {
                for (i = 0; i < list.length; i++) {
                        extensionIndex = indexOf(list[i], extension);
                        if (extensionIndex < 4)
                                continue;
                        if (substring(list[i], extensionIndex - 4, 4)
                                         == last4digits)
                                return list[i];
                }
                return "";
        }

Then I'd call this function in the loop, and only open the images when all
three of them are found:

        for (i = 0; i < list1.length; i++) {
                extensionIndex = indexOf(list1[i], exten1);
                if (extensionIndex < 4)
                        continue;
                last4digits = substring(list1[i], extensionIndex - 4, 4);

                name2 = inList(list2, exten2, last4digits);
                name3 = inList(list3, exten3, last4digits);
                if (name2 == "" || name3 == "")
                        continue;

                // only now open dir1 + list1[i], dir2 + name2
                // and dir3 + name3

                // then do the operations you need to do
        }

It's just a hint how to structure your code better, so that you do not
miss an unadjusted number, which is a consequence of heavy copy-pasting.

Of course, you are free to let this advice go unheeded, and just fix the
number2 to number3 I pointed out in my first reply.

Ciao,
Dscho
Thanks for you help so far, i have tried working with your suggestion, but its not achieving my purpose and is not opening my image to enable me stack them. Fixing the issues of number 2 and number 3 as you pointed out in my earlier code does not improve the code and it actually does not affect the output of the code if it runs. Thanks
Fixing the number 2 and number error you pointed out doesn.t still make the code to run, i keep on having  this error message which i do not understand,

index(-5) is outside of the 0-49 range in line 208.
number3 = substring (list3 [k], index5, index6<)>;

Please can anyone let me know what this error message implies. Thanks