Astra Image 6.0
Home
  • Welcome
  • Getting Started
    • Overview
    • System Requirements
    • Post Installation
  • Getting Started
    • Opening Images
    • Viewing Images
    • Saving and Exporting
    • Printing Images
    • Preferences and Settings
  • Adjustment Tools
    • Introduction to Adjustment Tools
    • Applying Changes and Color Space
    • Levels
    • Light
    • Color
    • Contrast
    • Curves
  • Processing Tools
    • Auto Enhancement
    • Deconvolution
    • Remove Camera Shake
    • Remove Focus Blur
    • Multiscale Contrast
    • Wavelet Sharpen
    • Unsharp Mask
    • Texture and Edge Sharpen
    • Histogram Equalization
    • Smart Gamma Correction
    • Shadows and Highlights
    • Color Balance
    • Channel Mixer
    • Color Temperature
    • Hyperbolic Arcsine Curve
    • Exponential Scale
    • Invert
    • Denoise
    • Convert to Gray
    • Arithmetic Filter
    • Convolution Filters
    • Edge Aware Filter
    • Pixel Math
    • Threshold
  • Image Geometry
    • Resize
    • Flip / Crop / Rotate
  • Statistics and Measurement
    • Statistics
    • Metadata
    • Measurement and Analysis
    • Pixel Information
  • Python Scripts
    • Installing Python
    • Writing Scripts
    • Function Reference
  • Activation
    • Activate Astra Image
  • Information and Credits
    • Contact Information
    • Credits
Powered by GitBook
On this page
  1. Python Scripts

Function Reference

Your guide to Python in Astra Image.

getPixel(x, y) Gets the value of the pixel and the x,y coordinate and returns an RGB value as a tuple.

Example:

p = ai.getPixel(100,100)

print(p)

The result will display the RGB values of the pixel at 100, 100, with values between 0.0 and 1.0:

(0.30588236451148987, 0.5372549295425415, 0.843137264251709)

setPixel(x, y, r, g, b) Sets the pixel at the x,y coordinate to the RGB value. The RGB values must be between 0.0 and 1.0. The setPixel function can be slow, so for processing a large image, it is recommended to use numpy where possible.

Example:

ai.setPixel(100, 100, 1.0, 0.0, 0.0) ai.updateImage()

This will set the pixel at 100,100 to pure red.

updateImage() When modifying the pixel values, use updateImage to see the changes.

getWidth() Returns the width of the image in pixels.

getHeight() Returns the height of the image in pixels.

newImage(width, height) Creates a new, empty image with the dimensions of width and height.

Example:

ai.newImage(256,256)

for y in range(0, 256): for x in range(0, 256): ai.setPixel(x, y, 1.0, 0, 0)

ai.updateImage()

This will create a new 256 by 256 pixel image and set all the pixels to red.

openImage(filename) Opens a file from disk. At the moment, this function does not support Unicode characters. Please note that on Windows you cannot directly pass the path as a string.

Examples the successfully open an image:

ai.openImage('c:/users/public/pictures/image.jpg') ai.openImage(r'c:\users\public\pictures\image.jpg')

Example that will not work on Windows (will result in a Python error):

ai.openImage('c:\users\public\pictures\image.jpg')

Result:

File "", line 3 ai.openImage('c:\users\public\pictures\image.jpg') ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape

getImageDataFloat() Gets the image data from Astra Image for use in numpy.

Example:

data = np.frombuffer(ai.getImageDataFloat(), dtype=np.float32)

The variable data is now a 1-dimensional numpy array that contains the image data.

If you want to have an array with the width, height, channels format, you can do this:

data.shape = (ai.getWidth(), ai.getHeight(), 3)

setImageDataFloat() Updates the image data in Astra Image from a numpy array.

Example:

ai.setImageDataFloat(data.tobytes(), ai.getWidth(), ai.getHeight())

In this case, the information in the variable 'data' will be loaded into Astra Image. The image data should be in 32-bit floating point with a range of 0.0 to 1.0.

getROI() Gets the current region of interest as a tuple. If no region is defined, the result will be -1.

The result format for a rectangular region is: (left, top, right, bottom). When the line tool is being used the format will be(x, y, x1, y1), where x,y are the starting coordinates and x1,y1 are the ending coordinates of the line.

Example:

roi = ai.getROI()

print(roi)

If there is a valid region or line, the result will look like:

(962, 622, 1624, 1362)

If there is no region or line, the result will look like this:

(-1, -1, -1, -1)

getCurrentFilename() Gets the fully qualified filename of the current image.

Example:

fn = ai.getCurrentFilename()

print(fn)

Result:

c:\users\public\pictures\image.jpg

PreviousWriting ScriptsNextActivate Astra Image

Last updated 10 months ago