Can we get an image that is not in front of the DM script?

I have questions regarding working with multiple series images:

  • When we code, we can get the image in front image front:=GetFrontImage()

    . Can I get an image that is not in front? For example, if there are only 20 images, can I get the 7th shot (-According to front-to-back), something similar to this pseudo command image img7:=GetFrontThe7thImage()

    :?

  • I have a series of images, the image naming format is consistent, for example, the front image name is xxx001, the second is xxx002, the third is xxx003, ..., the Nth image is xxxN, Can I use encoding, for example image N:=imagexxxN

    , and then I directly using image N for math process? Or should I use a loop and get images one by one?

+3


source to share


2 answers


1)

As you can have multiple images in one window / saved datasets (- just copy and paste one image onto another) it is generally recommended to use ImageDocuments

for iteration. ImageDocument is an object that is stored and loaded from the hard drive. When you create an image, but don't display it, that image doesn't have an ImageDocument yet, but all (once) displayed images do.

To select the last image (the very opposite), 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 on the same line as well, using the OOP coding style where the first parameter of the method is given before the first parameter to resolve the pipelines. So you can select an image from the 2nd front (assuming at least 2) along the line

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

2)

You need a loop to access multiple images, but for parallel processing, you might consider putting data into a 3D data stack. (Also note that you can load multiple images into the 3D stack using File/Open Series...

). Depending on what you want to do, you can then work with this "slice by slice" of this stack, iterating over the z-dimension with a command Slice2

, or you can act on the 3D data in general.

+2


source


  • For this part, you need two functions CountImages () and FindImageByIndex (). Here's 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");
    
          

  • If your images are open and systematically named as you specify, you can find a specific object using the GetNamedImage () function, as shown below:

    String baseName = "xxx";
    Number desiredImageNumber = 3;
    String imageName = baseName + Format(desiredImageNumber, "%03.0f");
    Image desiredImage := GetNamedImage(imageName);
    
          



+1


source







All Articles