Gatan | AMETEKSkip to Main Content
No options found

Count negative pixels

Python Script

Count the number of negative pixels in the front image.

Preview

'''
Count number of negative pixels in the front image
'''
import DigitalMicrograph as DM
import numpy as np

#Get front image and image data as numpy array
img_data = DM.GetFrontImage().GetNumArray()

#Count number of negative and total pixels 
num_negative = np.sum(np.where(img_data < 0, 1, 0))
num_total = np.prod(img_data.shape)

#Print result to output window after clearing its content
DM.ClearResults()
print( 'Number of Negative Pixels: %s out of %s total' %(num_negative, num_total))