Example API¶
This is an example of what your API will look like.
Python code¶
-
class
qgisplugin.core.my_code.
MyCode
(image: numpy.ndarray, normalize: bool = False, quotient: int = 255)[source]¶ Bases:
object
todo: Give a short summary of what this code does here.
e.g.: This script is a super simple example of a set of functions: one to multiply an image with a factor, one to add a constant to an entire image and one to set all values below a threshold to 0.
This script only contains the mathematical part of your code and should be completely independent of i/o. You start from matrices, integers and other variables, and not from files or widgets!
-
add_to_image
(constant: float) → numpy.ndarray[source]¶ Add a constant to an image.
Parameters: constant – The constant to add to each pixel of the image. Returns: The new image.
-
execute
(constant: float, threshold: float, set_progress: callable = None, log: callable = <built-in function print>) → numpy.ndarray[source]¶ This part is usually the core of your plugin: this function is called when the user clicks “run”.
Here we don’t do anything special: we add a number to an image and then set all values in an image to 0 where they are below a given threshold.
Parameters: - constant – The constant to add to each pixel of the image.
- threshold – all values below this threshold are set to 0
- set_progress – communicate progress (refer to the progress bar in case of GUI; otherwise print to console)
- log – communicate messages (refer to the print_log tab in the GUI; otherwise print to the console)
Returns: the new image
-
Command Line Interface¶
todo: Give a short summary of what this code does here.
e.g.: This script is a super simple example of a set of functions: one to multiply an image with a factor, one to add a constant to an entire image and one to set all values below a threshold to 0.
This script only contains the mathematical part of your code and should be completely independent of i/o. You start from matrices, integers and other variables, and not from files or widgets!
usage: mycli [-h] [-n N] [-c C] [-t T] [-o O] image
Positional Arguments¶
image | Path to the input image. |
Named Arguments¶
-n | To normalize your image, set the quotient here. (default: not set) |
-c | Add this constant to the image (default: 0.01). Default: 0.01 |
-t | Threshold for setting cells to 0 (default: 0.2). Default: 0.2 |
-o | Output file (default: in same folder with name ‘output.tif’ |