3

I have questions regarding dealing with multiple images of a series:

  1. When we are coding, we can get the front image by image front:=GetFrontImage(). Can I also get the image that is not in front? For example, if there are total 20 images, can I directly get the 7th image (-Counted from front to back-) by something similar to this pseudo-command:image img7:=GetFrontThe7thImage() ?

  2. I have a series of images, the format of names of images are consistent, such as the name of front image is xxx001, the second is xxx002, the third one is xxx003,..., the Nth image is xxxN, Could I use a coding define like image N:=imagexxxN, and then I directly use image N for math process? Or should I use a loop and get the images one-by-one?

BmyGuest
  • 6,331
  • 1
  • 21
  • 35
together
  • 413
  • 2
  • 11

2 Answers2

2

1)

As you can have multiple images within one window/saved data set ( - just copy & paste one image onto the other - ) it is generally saver to use ImageDocuments for the iteration. An ImageDocument is the object which gets stored to and loaded from the hard drive. When you create an image, but don't display it, this image does not yet have an ImageDocument, but all (once) displayed images do.

To select the last image (the back-most) you can do the following:

number nDocs = CountImageDocuments()
imageDocument docLast = GetImageDocument( nDocs-1 )
image imgLast := ImageDocumentGetImage( docLast, 0 )
SelectImage( imgLast )

Note that you can get things in a single line as well, using OOP coding style where the first parameter of a method is put in front of the command to allow pipe-lines. So you can select the 2nd-front-most image (provided there are at least 2) by the line

GetImageDocument(1).ImageDocumentGetImage(0).SelectImage()

2)

You need a loop to access multiple images, but for parallel processing you might consider putting the data into a 3D data-stack. (Also note, that you can load multiple image into a 3D stack using File/Open Series...). Depending on what you want to do, you can then operate on this stack "slice by slice" iterating over z-dimension with the Slice2 command, or you might be able to act on the 3D data as a whole.

Community
  • 1
  • 1
BmyGuest
  • 6,331
  • 1
  • 21
  • 35
  • For my DM 2.0, I can open all the images one time, and also load all of them as slices by slice player, but I am not sure what is the meaning slice2 command? Is it a command and I can find it from the DM scripting help files? Thanks – together Jul 23 '15 at 04:18
  • @together The slice-player does something different, I believe. (It streams only part of the data into memory at any time.) The slice1, slice2, slice3 and sliceN commands are regular commands but I'm not sure they are documented properly in DM 2.0. You can get some examples [here](http://stackoverflow.com/questions/27178748/creating-an-image-of-difference-of-adjacent-pixels-with-digitalmicrograph-dm-s/27250596?s=2|2.7618#27250596) and [here](http://digitalmicrograph-scripting.tavernmaker.de/HowToScript_index.htm). In case of questions, best ask them as separate question here on StackOverlow. – BmyGuest Jul 23 '15 at 07:16
  • @together BTW, it is good courtesy on StackOverflow to "accept" an answer to a question you've asked (if it answers your question.) This is done by clicking the grey "checked" icon under the voting arrows. – BmyGuest Jul 23 '15 at 07:17
1
  1. For this part, you need the two functions CountImages() and FindImageByIndex(). Here is an example to show how they work:

    Result("\nAvailable images:\n");
    
    Number imageCount = CountImages();
    if (imageCount > 0)
    {
        for (Number imageIndex = 0; imageIndex < imageCount; imageIndex++)
        {
            Image nextImage := FindImageByIndex(imageIndex);
            String imageName = nextImage.ImageGetName();
            Result("Image " + imageIndex + ": " + imageName + "\n");
        }
    }
    else
        Result("None\n");
    
    Result("\n");
    
  2. If your images are all open and systematically named as you indicate, then you can locate a specific one using the GetNamedImage() function, as follows:

    String baseName = "xxx";
    Number desiredImageNumber = 3;
    String imageName = baseName + Format(desiredImageNumber, "%03.0f");
    Image desiredImage := GetNamedImage(imageName);
    
Mike Kundmann
  • 705
  • 5
  • 12