# Function Reference

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

Example:

<mark style="color:orange;">p = ai.getPixel(100,100)</mark>

<mark style="color:orange;">print(p)</mark>

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

<mark style="color:orange;">(0.30588236451148987, 0.5372549295425415, 0.843137264251709)</mark>

**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:

<mark style="color:orange;">ai.setPixel(100, 100, 1.0, 0.0, 0.0)</mark> \ <mark style="color:orange;">ai.updateImage()</mark>

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:

<mark style="color:orange;">ai.newImage(256,256)</mark>

<mark style="color:orange;">for y in range(0, 256):</mark>\
&#x20;  <mark style="color:orange;">for x in range(0, 256):</mark>\
&#x20;    <mark style="color:orange;">ai.setPixel(x, y, 1.0, 0, 0)</mark>

<mark style="color:orange;">ai.updateImage()</mark>

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:

<mark style="color:orange;">ai.openImage('c:/users/public/pictures/image.jpg')</mark> \ <mark style="color:orange;">ai.openImage(r'c:\users\public\pictures\image.jpg')</mark> <br>

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

<mark style="color:orange;">ai.openImage('c:\users\public\pictures\image.jpg')</mark>

Result:

<mark style="color:orange;">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</mark>

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

Example:

<mark style="color:orange;">data = np.frombuffer(ai.getImageDataFloat(), dtype=np.float32)</mark>

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:

<mark style="color:orange;">data.shape = (ai.getWidth(), ai.getHeight(), 3)</mark>

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

Example:

<mark style="color:orange;">ai.setImageDataFloat(data.tobytes(), ai.getWidth(), ai.getHeight())</mark>

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:

<mark style="color:orange;">roi = ai.getROI()</mark>

<mark style="color:orange;">print(roi)</mark>

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

<mark style="color:orange;">(962, 622, 1624, 1362)</mark>

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

<mark style="color:orange;">(-1, -1, -1, -1)</mark>

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

Example:

<mark style="color:orange;">fn = ai.getCurrentFilename()</mark>

<mark style="color:orange;">print(fn)</mark>

Result:

<mark style="color:orange;">c:\users\public\pictures\image.jpg</mark>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://astra-image.gitbook.io/astra-image-6.0/python-scripts/function-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
