2

Has anyone had success getting line (or any other) annotations to show using Python in DM? My code is:

img = DM.CreateImage(...)
img_disp = img.CreateImageDisplay(1)
img_disp.AddNewComponent(2, 512, 0, 512, 1000)
img.ShowImage()
del imgk

Theoretically, this should draw a horizontal line annotation, but I'm not seeing anything in my images even though I can find a child component of type 'line annotation' in the image display component. There is also the function NewLineAnnotation() in Python but I can't find a function like ComponentAddChildAtEnd() that exists in the DM scripting language.

1 Answer 1

0

The problem you have is, thatShowImage() creates a new display which is not the same as your img_disp.

You have two ways of resolving this:

  • Either You create an imageDocument and then add the created imageDisplay to it.

  • Or you use the ShowImage first and then get the imageDisplay.

I would recommend the 2nd solution unless for some reason you do not want to display the image in a first place. So the code would be:

# This is a PYTHON script to be run in DigitalMicrograph
import numpy as np
img = DM.CreateImage( np.arange(120000).reshape(300, 400).copy() )
img.ShowImage()
img.GetImageDisplay(0).AddNewComponent(2, 150, 100, 150, 300)
del img

The equivalent DM-script would be:

// This is a DM-script to be run in DigitalMicrograph
image img := IntegerImage("Test",4,0,400,300) = irow
img.ShowImage()
img.ImageGetImageDisplay(0).ComponentAddNewComponent(2,150,100,150,300)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I used the 2nd solution and it now works! Do you know a directer way to change the properties of the new annotation than using GetNthChildOfType by any chance since defining a new line annotation and then adding it to the image display doesn't seem to work in python.
@Luke, no I don't. It seems the missing ComponentAddChild... commands in Python seem to be an oversight and should possibly just be added in one of the next releases, provided somebody files a feature-request/issue-report with the Gatan issue reporting site. Personally, I use the scripting differently. I prefer doing DM-scripts and only calling out to Python for the extended functionality where needed instead of doing all in a Python script. When really needed, I rather do a short "hybrid" script. But that's personal preference.

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.