Skip to content

Commit

Permalink
feat: stubs for safe-ds library (#950)
Browse files Browse the repository at this point in the history
Closes #926

### Summary of Changes

Add a first version of stubs for the `safe-ds` library.
  • Loading branch information
lars-reimann authored Mar 29, 2024
1 parent 21fc485 commit 155b1c0
Show file tree
Hide file tree
Showing 37 changed files with 3,462 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
package safeds.data.image.containers

/**
* A container for image data.
*/
class Image {
/**
* Get the width of the image in pixels.
*/
attr width: Int
/**
* Get the height of the image in pixels.
*/
attr height: Int
/**
* Get the number of channels of the image.
*/
attr channel: Int

/**
* Create an image from a file.
*
* @param path The path to the image file.
* @param device The device where the tensor will be saved on. Defaults to the default device
*
* @result result1 The image.
*/
@Impure([ImpurityReason.FileReadFromParameterizedPath("path")])
@PythonName("from_file")
static fun fromFile(
path: String
) -> result1: Image

/**
* Save the image as a JPEG file.
*
* @param path The path to the JPEG file.
*/
@Impure([ImpurityReason.FileWriteToParameterizedPath("path")])
@PythonName("to_jpeg_file")
fun toJpegFile(
path: String
)

/**
* Save the image as a PNG file.
*
* @param path The path to the PNG file.
*/
@Impure([ImpurityReason.FileWriteToParameterizedPath("path")])
@PythonName("to_png_file")
fun toPngFile(
path: String
)

/**
* Return a new `Image` that has been resized to a given size.
*
* The original image is not modified.
*
* @result result1 The image with the given width and height.
*/
@Pure
fun resize(
@PythonName("new_width") newWidth: Int,
@PythonName("new_height") newHeight: Int
) -> result1: Image

/**
* Return a new `Image` that is converted to grayscale.
*
* The original image is not modified.
*
* @result result1 The grayscale image.
*/
@Pure
@PythonName("convert_to_grayscale")
fun convertToGrayscale() -> result1: Image

/**
* Return a new `Image` that has been cropped to a given bounding rectangle.
*
* The original image is not modified.
*
* @result result1 The cropped image.
*/
@Pure
fun crop(
x: Int,
y: Int,
width: Int,
height: Int
) -> result1: Image

/**
* Return a new `Image` that is flipped vertically (horizontal axis, flips up-down and vice versa).
*
* The original image is not modified.
*
* @result result1 The flipped image.
*/
@Pure
@PythonName("flip_vertically")
fun flipVertically() -> result1: Image

/**
* Return a new `Image` that is flipped horizontally (vertical axis, flips left-right and vice versa).
*
* The original image is not modified.
*
* @result result1 The flipped image.
*/
@Pure
@PythonName("flip_horizontally")
fun flipHorizontally() -> result1: Image

/**
* Return a new `Image` with an adjusted brightness.
*
* The original image is not modified.
*
* @param factor The brightness factor.
* 1.0 will not change the brightness.
* Below 1.0 will result in a darker image.
* Above 1.0 will resolut in a brighter image.
* Has to be bigger than or equal to 0 (black).
*
* @result result1 The Image with adjusted brightness.
*/
@Pure
@PythonName("adjust_brightness")
fun adjustBrightness(
factor: Float
) -> result1: Image

/**
* Return a new `Image` with noise added to the image.
*
* The original image is not modified.
*
* @param standardDeviation The standard deviation of the normal distribution. Has to be bigger than or equal to 0.
*
* @result result1 The image with added noise.
*/
@Pure
@PythonName("add_noise")
fun addNoise(
@PythonName("standard_deviation") standardDeviation: Float
) -> result1: Image

/**
* Return a new `Image` with adjusted contrast.
*
* The original image is not modified.
*
* @param factor If factor > 1, increase contrast of image.
* If factor = 1, no changes will be made.
* If factor < 1, make image greyer.
* Has to be bigger than or equal to 0 (gray).
*
* @result result1 New image with adjusted contrast.
*/
@Pure
@PythonName("adjust_contrast")
fun adjustContrast(
factor: Float
) -> result1: Image

/**
* Return a new `Image` with adjusted color balance.
*
* The original image is not modified.
*
* @param factor Has to be bigger than or equal to 0.
* If 0 <= factor < 1, make image greyer.
* If factor = 1, no changes will be made.
* If factor > 1, increase color balance of image.
*
* @result result1 The new, adjusted image.
*/
@Pure
@PythonName("adjust_color_balance")
fun adjustColorBalance(
factor: Float
) -> result1: Image

/**
* Return a blurred version of the image.
*
* The original image is not modified.
*
* @param radius Radius is directly proportional to the blur value. The radius is equal to the amount of pixels united in
* each direction. A radius of 1 will result in a united box of 9 pixels.
*
* @result result1 The blurred image.
*/
@Pure
fun blur(
radius: Int
) -> result1: Image

/**
* Return a sharpened version of the image.
*
* The original image is not modified.
*
* @param factor If factor > 1, increase the sharpness of the image.
* If factor = 1, no changes will be made.
* If factor < 1, blur the image.
* Has to be bigger than or equal to 0 (blurred).
*
* @result result1 The image sharpened by the given factor.
*/
@Pure
fun sharpen(
factor: Float
) -> result1: Image

/**
* Return a new `Image` with colors inverted.
*
* The original image is not modified.
*
* @result result1 The image with inverted colors.
*/
@Pure
@PythonName("invert_colors")
fun invertColors() -> result1: Image

/**
* Return a new `Image` that is rotated 90 degrees clockwise.
*
* The original image is not modified.
*
* @result result1 The image rotated 90 degrees clockwise.
*/
@Pure
@PythonName("rotate_right")
fun rotateRight() -> result1: Image

/**
* Return a new `Image` that is rotated 90 degrees counter-clockwise.
*
* The original image is not modified.
*
* @result result1 The image rotated 90 degrees counter-clockwise.
*/
@Pure
@PythonName("rotate_left")
fun rotateLeft() -> result1: Image

/**
* Return a grayscale version of the image with the edges highlighted.
*
* The original image is not modified.
*
* @result result1 The image with edges found.
*/
@Pure
@PythonName("find_edges")
fun findEdges() -> result1: Image
}
Loading

0 comments on commit 155b1c0

Please sign in to comment.