Image
The image
module provides a flexible and powerful way to work with images using a composition-based design. This allows you to dynamically build image objects with the exact functionality you need.
Core Components
The image
module is built around the following core components:
- Image: The main class that represents an image. It is composed of other components to provide its functionality.
- Reader: Responsible for loading image data from various sources.
- Drawer: Provides methods for drawing shapes and text on the image.
- Transformer: Allows you to apply various transformations to the image, such as resizing, cropping, and color adjustments.
Available Modules
Below is a list of available modules and their functionalities:
Base Image module for basic image processing. It only contains very low-level, basic and generic image methods.
BaseImage
Base Image class
Source code in otary/image/base.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
area
property
Area of the image
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
image area |
asarray
property
writable
Array representation of the image
asarray_binary
property
Returns the representation of the image as a array with value not in [0, 255] but in [0, 1].
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
an array with value in [0, 1] |
bottom_left
property
Get the bottom right point coordinate of the image
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
2D point |
bottom_right
property
Get the bottom right point coordinate of the image
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
2D point |
center
property
Center point of the image.
Please note that it is returned as type int because the center is represented as a X-Y coords of a pixel.
Returns:
Type | Description |
---|---|
NDArray[int16]
|
np.ndarray: center point of the image |
channels
property
Number of channels in the image
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
number of channels |
corners
property
Returns the corners in clockwise order:
- top left corner
- top right corner
- bottom right corner
- bottom left corner
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array containing the corners |
height
property
Height of the image.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
image height |
is_gray
property
Whether the image is a grayscale image or not
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if image is in grayscale, 0 otherwise |
norm_side_length
property
Returns the normalized side length of the image. This is the side length if the image had the same area but the shape of a square (four sides of the same length).
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
normalized side length |
shape_array
property
Returns the array shape value (height, width, channel)
Returns:
Type | Description |
---|---|
tuple
|
tuple[int]: image shape |
shape_xy
property
Returns the array shape value (width, height, channel). Use this if you consider the image as pixels in a X-Y 2D coordinate system.
Returns:
Type | Description |
---|---|
tuple
|
tuple[int]: image shape |
top_left
property
Get the bottom right point coordinate of the image
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
2D point |
top_right
property
Get the bottom right point coordinate of the image
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
2D point |
width
property
Width of the image.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
image width |
as_api_file_input(fmt='png', filename='image')
Return the image as a file input for API requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fmt
|
str
|
format of the image. Defaults to "png". |
'png'
|
filename
|
str
|
name of the file. Defaults to "image". |
'image'
|
Returns:
Type | Description |
---|---|
dict[str, tuple[str, bytes, str]]
|
dict[str, tuple[str, bytes, str]]: dictionary with file input for API requests, where the key is "file" and the value is a tuple containing the filename, image bytes, and content type. |
Source code in otary/image/base.py
as_black()
Returns an entirely black image with the same dimension as the original.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
new black image |
as_bytes(fmt='PNG')
Return the image as bytes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fmt
|
str
|
format of the image. Defaults to "PNG". |
'PNG'
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
image in bytes |
Source code in otary/image/base.py
as_colorscale()
Generate the image in colorscale (height, width, 3). This property can be useful when we wish to draw objects in a given color on a grayscale image.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
original image in color |
Source code in otary/image/base.py
as_filled(fill_value=255)
Returns an entirely white image of the same size as the original. Can be useful to get an empty representation of the same image to paint and draw things on an image of the same dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fill_value
|
int | ndarray
|
color to fill the new empty image. Defaults to 255 which means that is returns a entirely white image. |
255
|
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
new image with a single color of the same size as original. |
Source code in otary/image/base.py
as_grayscale()
Generate the image in grayscale of shape (height, width)
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
original image in grayscale |
Source code in otary/image/base.py
as_pil()
as_white()
Returns an entirely white image with the same dimension as the original.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
new white image |
dist_pct(pct)
Distance percentage that can be used an acceptable distance error margin. It is calculated based on the normalized side length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pct
|
float
|
percentage of distance error. Defaults to 0.01, which means 1% of the normalized side length as the default margin distance error. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
margin distance error |
Source code in otary/image/base.py
is_equal_shape(other, consider_channel=True)
Check whether two images have the same shape
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BaseImage
|
BaseImage object |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the objects have the same shape, False otherwise |
Source code in otary/image/base.py
rev()
Reverse the image colors. Each pixel color value V becomes |V - 255|.
Applied on a grayscale image the black pixel becomes white and the white pixels become black.
Source code in otary/image/base.py
Image Drawer module. It only contains methods to draw objects in images.
DrawerImage
Image Drawer class to draw objects on a given image
Source code in otary/image/components/drawer/drawer.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
draw_circles(circles, render=CirclesRender())
Draw circles in the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circles
|
Sequence[Circle]
|
list of Circle geometry objects. |
required |
render
|
CirclesRender
|
circle renderer |
CirclesRender()
|
Source code in otary/image/components/drawer/drawer.py
draw_ellipses(ellipses, render=EllipsesRender())
Draw ellipses in the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ellipses
|
Sequence[Ellipse]
|
list of Ellipse geometry objects. |
required |
render
|
EllipseRender
|
renderer (uses EllipseRender for color/thickness) |
EllipsesRender()
|
Source code in otary/image/components/drawer/drawer.py
draw_ocr_outputs(ocr_outputs, render=OcrSingleOutputRender())
Return the image with the bounding boxes displayed from a list of OCR single output. It allows you to show bounding boxes that can have an angle, not necessarily vertical or horizontal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ocr_outputs
|
Sequence[OcrSingleOutput]
|
list of OcrSingleOutput objects |
required |
render
|
OcrSingleOutputRender
|
OcrSingleOutputRender object |
OcrSingleOutputRender()
|
Source code in otary/image/components/drawer/drawer.py
draw_points(points, render=PointsRender())
Draw points in the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
NDArray
|
list of points. It must be of shape (n, 2). This means n points of shape 2 (x and y coordinates). |
required |
render
|
PointsRender
|
point renderer |
PointsRender()
|
Source code in otary/image/components/drawer/drawer.py
draw_polygons(polygons, render=PolygonsRender())
Draw polygons in the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygons
|
Sequence[Polygon]
|
list of Polygon objects |
required |
render
|
PolygonsRender
|
PolygonRender object |
PolygonsRender()
|
Source code in otary/image/components/drawer/drawer.py
draw_segments(segments, render=SegmentsRender())
Draw segments in the image. It can be arrowed segments (vectors) too.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segments
|
NDArray
|
list of segments. Can be a numpy array of shape (n, 2, 2) which means n array of shape (2, 2) that define a segment by two 2D points. |
required |
render
|
SegmentsRender
|
segment renderer |
SegmentsRender()
|
Source code in otary/image/components/drawer/drawer.py
draw_splines(splines, render=LinearSplinesRender())
Draw linear splines in the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splines
|
Sequence[LinearSpline]
|
linear splines to draw. |
required |
render
|
LinearSplinesRender
|
linear splines render. Defaults to LinearSplinesRender(). |
LinearSplinesRender()
|
Source code in otary/image/components/drawer/drawer.py
Image Reader module
ReaderImage
ReaderImage class to facilitate the reading of images from different formats such as JPG, PNG, and PDF. It provides methods to load images from file paths.
Source code in otary/image/components/io/reader.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
from_file(filepath, as_grayscale=False, resolution=None)
staticmethod
Create a Image array from a file image path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
path to the image file |
required |
as_grayscale
|
bool
|
turn the image in grayscale. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
Image as array |
Source code in otary/image/components/io/reader.py
from_fillvalue(value=255, shape=(128, 128, 3))
staticmethod
Create an array image from a single value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int
|
value in [0, 255]. Defaults to 255. |
255
|
shape
|
tuple
|
image shape. If it has three elements then the last one must be a 3 for a coloscale image. Defaults to (128, 128, 3). |
(128, 128, 3)
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array with a single value |
Source code in otary/image/components/io/reader.py
from_jpg(filepath, as_grayscale=False, resolution=None)
staticmethod
Create a Image object from a JPG or JPEG file path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
path to the JPG image file |
required |
as_grayscale
|
bool
|
turn the image in grayscale. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
numpy array |
Source code in otary/image/components/io/reader.py
from_pdf(filepath, as_grayscale=False, page_nb=0, resolution=None, clip_pct=None)
staticmethod
Create an Image array from a pdf file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
path to the pdf file. |
required |
as_grayscale
|
bool
|
whether to turn the image in grayscale. Defaults to False. |
False
|
page_nb
|
int
|
as we load only one image we have to select the page that will be turned into an image. Defaults to 0. |
0
|
resolution
|
Optional[int]
|
resolution of the loaded image. Defaults to 3508. |
None
|
clip_pct
|
Rect
|
optional zone to extract in the image. This is particularly useful to load into memory only a small part of the image without loading everything into memory. This reduces considerably the image loading time especially combined with a high resolution. |
None
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
Image as array |
Source code in otary/image/components/io/reader.py
from_png(filepath, as_grayscale=False, resolution=None)
staticmethod
Create a Image array from a PNG file image path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
path to the image file |
required |
as_grayscale
|
bool
|
turn the image in grayscale. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
Image as array |
Source code in otary/image/components/io/reader.py
WriterImage module
WriterImage
WriterImage class that provide methods to save and show the image
Source code in otary/image/components/io/writer.py
save(save_filepath)
Save the image in a local file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_filepath
|
str
|
path to the file |
required |
show(title=None, figsize=(8.0, 6.0), color_conversion=cv2.COLOR_BGR2RGB, save_filepath=None)
Show the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
Optional[str]
|
title of the image. Defaults to None. |
None
|
figsize
|
tuple[float, float]
|
size of the figure. Defaults to (8.0, 6.0). |
(8.0, 6.0)
|
color_conversion
|
int
|
color conversion parameter. Defaults to cv2.COLOR_BGR2RGB. |
COLOR_BGR2RGB
|
save_filepath
|
Optional[str]
|
save the image if needed. Defaults to None. |
None
|
Source code in otary/image/components/io/writer.py
Cropper Transformer component
CropperImage
CropperImage class
Source code in otary/image/components/transformer/components/cropper/cropper.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
__crop_with_clipping(x0, y0, x1, y1)
Crop the image in a straight axis-aligned rectangle way given by the top-left point [x0, y0] and the bottom-right point [x1, y1].
Crop by clipping meaning that if the coordinates are out of the image bounds the output is only the part of the image that is in the bounds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
int
|
x coordinate of the top-left point |
required |
y0
|
int
|
y coordinate of the top-left point |
required |
x1
|
int
|
x coordinate of the bottom-right point |
required |
y1
|
int
|
y coordinate of the bottom-right point |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
NDArray
|
image cropped |
Source code in otary/image/components/transformer/components/cropper/cropper.py
__crop_with_padding(x0, y0, x1, y1, pad_value=0)
Crop the image in a straight axis-aligned rectangle way given by the top-left point [x0, y0] and the bottom-right point [x1, y1].
This method is specific to crop with padding meaning that if the coordinates are out of the image bounds, the padding is added to the output cropped image with the pad value parameter, black by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
int
|
x coordinate of the top-left point |
required |
y0
|
int
|
y coordinate of the top-left point |
required |
x1
|
int
|
x coordinate of the bottom-right point |
required |
y1
|
int
|
y coordinate of the bottom-right point |
required |
pad_value
|
int
|
pad fill value. Defaults to 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
output cropped image |
Source code in otary/image/components/transformer/components/cropper/cropper.py
crop(x0, y0, x1, y1, clip=True, pad=False, copy=False, extra_border_size=0, pad_value=0)
Crop the image in a straight axis-aligned rectangle way given by the top-left point [x0, y0] and the bottom-right point [x1, y1]
This function inputs represents the top-left and bottom-right points. This method does not provide a way to extract a rotated rectangle or a different shape from the image.
Remember that in this library the x coordinates represent the y coordinates of the image array (horizontal axis of the image). The array representation is always rows then columns. In this library this is the contrary like in opencv.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
int
|
top-left x coordinate |
required |
y0
|
int
|
top-left y coordinate |
required |
x1
|
int
|
bottom-right x coordinate |
required |
y1
|
int
|
bottom-right y coordinate |
required |
clip
|
bool
|
whether to clip or not. Defaults to True. |
True
|
pad
|
bool
|
whether to pad or not. Defaults to False. |
False
|
copy
|
bool
|
whether to copy or not. Defaults to False. |
False
|
extra_border_size
|
int
|
extra border size to add to the crop in the x and y directions. Defaults to 0 which means no extra border. |
0
|
pad_value
|
int
|
pad fill value. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Optional[Image]
|
Optional[Image]: cropped image if copy=True else None |
Source code in otary/image/components/transformer/components/cropper/cropper.py
crop_from_axis_aligned_bbox(bbox, clip=True, pad=False, copy=False, extra_border_size=0, pad_value=0)
Crop the image from an Axis-Aligned Bounding Box (AABB). Inclusive crops which means that the cropped image will have width and height equal to the width and height of the AABB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox
|
Rectangle
|
axis-aligned bounding box |
required |
clip
|
bool
|
whether to clip or not. Defaults to True. |
True
|
pad
|
bool
|
whether to pad or not. Defaults to False. |
False
|
copy
|
bool
|
whether to copy or not. Defaults to False. |
False
|
extra_border_size
|
int
|
extra border size to add to the crop in the x and y directions. Defaults to 0 which means no extra border. |
0
|
pad_value
|
int
|
pad fill value. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Optional[Image]
|
Optional[Image]: cropped image if copy=True else None |
Source code in otary/image/components/transformer/components/cropper/cropper.py
crop_from_center(center, width, height, clip=True, pad=False, copy=False, extra_border_size=0, pad_value=0)
Crop the image from a rectangle defined by its center point, its width and its height.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
NDArray
|
(x, y) coordinates of the center point |
required |
width
|
int
|
width of the rectangle to crop |
required |
height
|
int
|
height of the rectangle to crop |
required |
clip
|
bool
|
whether to clip or not. Defaults to True. |
True
|
pad
|
bool
|
whether to pad or not. Defaults to False. |
False
|
copy
|
bool
|
whether to copy or not. Defaults to False. |
False
|
extra_border_size
|
int
|
extra border size to add to the crop in the x and y directions. Defaults to 0 which means no extra border. |
0
|
pad_value
|
int
|
pad fill value. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Optional[Image]
|
Optional[Image]: image cropped if copy=True else None |
Source code in otary/image/components/transformer/components/cropper/cropper.py
crop_from_linear_spline(spline, copy=False, clip=True, pad=False, extra_border_size=0, pad_value=0)
Crop the image from a linear spline
Source code in otary/image/components/transformer/components/cropper/cropper.py
crop_from_polygon(polygon, copy=False, clip=True, pad=False, extra_border_size=0, pad_value=0)
Crop the image from a polygon
Source code in otary/image/components/transformer/components/cropper/cropper.py
crop_from_topleft(topleft, width, height, clip=True, pad=False, copy=False, extra_border_size=0, pad_value=0)
Crop the image from a rectangle defined by its top-left point, its width and its height.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topleft
|
ndarray
|
(x, y) coordinates of the top-left point |
required |
width
|
int
|
width of the rectangle to crop |
required |
height
|
int
|
height of the rectangle to crop |
required |
clip
|
bool
|
whether to clip or not. Defaults to True. |
True
|
pad
|
bool
|
whether to pad or not. Defaults to False. |
False
|
copy
|
bool
|
whether to copy or not. Defaults to False. |
False
|
extra_border_size
|
int
|
extra border size to add to the crop in the x and y directions. Defaults to 0 which means no extra border. |
0
|
pad_value
|
int
|
pad fill value. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
Optional[Image]
|
Optional[Image]: image cropped if copy=True else None |
Source code in otary/image/components/transformer/components/cropper/cropper.py
Binarizer component
BinarizerImage
BinarizerImage class
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
binary(method='sauvola')
Binary representation of the image with values that can be only 0 or 1. The value 0 is now 0 and value of 255 are now 1. Black is 0 and white is 1. We can also talk about the mask of the image to refer to the binary representation of it.
The sauvola is generally the best binarization method however it is way slower than the others methods. The adaptative or otsu method are the best method in terms of speed and quality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
the binarization method to apply. Must be in ["adaptative", "otsu", "sauvola", "niblack", "nick", "wolf"]. Defaults to "sauvola". |
'sauvola'
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array where its inner values are 0 or 1 |
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
binaryrev(method='sauvola')
Reversed binary representation of the image. The value 0 is now 1 and value of 255 are now 0. Black is 1 and white is 0. This is why it is called the "binary rev" or "binary reversed".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
the binarization method to apply. Defaults to "adaptative". |
'sauvola'
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array where its inner values are 0 or 1 |
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_adaptative()
Apply adaptive thresholding.
A median blur is applied before for better thresholding results. See https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html.
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_niblack(window_size=15, k=0.2)
Apply Niblack thresholding. See https://scikit-image.org/docs/stable/auto_examples/segmentation/ plot_niblack_sauvola.html
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window_size
|
int
|
apply on the image. Defaults to 15. |
15
|
k
|
float
|
factor to apply to regulate the impact of the std. Defaults to 0.2. |
0.2
|
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_otsu()
Apply Ostu thresholding.
A gaussian blur is applied before for better thresholding results. See https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html.
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_sauvola(window_size=15, k=0.2, r=128.0)
Apply Sauvola thresholding. See https://scikit-image.org/docs/stable/auto_examples/segmentation/ plot_niblack_sauvola.html.
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window_size
|
int
|
sauvola window size to apply on the image. Defaults to 15. |
15
|
k
|
float
|
sauvola k factor to apply to regulate the impact of the std. Defaults to 0.2. |
0.2
|
r
|
float
|
sauvola r value. Defaults to 128. |
128.0
|
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_simple(thresh)
Compute the image thesholded by a single value T. All pixels with value v <= T are turned black and those with value v > T are turned white.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thresh
|
int
|
value to separate the black from the white pixels. |
required |
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
Geometry Transformer component
GeometrizerImage
GeometrizerImage class
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
__rotate_exact(angle, is_degree=False, is_clockwise=True, reshape=True, border_fill_value=0.0)
Rotate the image by a given angle. This method is more accurate than the rotate method but way slower (about 10 times slower).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
angle to rotate the image |
required |
is_degree
|
bool
|
whether the angle is in degree or not. If not it is considered to be in radians. Defaults to False which means radians. |
False
|
is_clockwise
|
bool
|
whether the rotation is clockwise or counter-clockwise. Defaults to True. |
True
|
reshape
|
bool
|
scipy reshape option. Defaults to True. |
True
|
border_fill_value
|
float
|
value to fill the border of the image after the rotation in case reshape is True. Can only be a single integer. Does not support tuple of 3 integers for RGB image. Defaults to 0.0 which is black. |
0.0
|
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
center_to_point(point)
Shift the image so that the input point ends up in the middle of the new image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
NDArray
|
point as (2,) shape numpy array |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
translation Vector |
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
center_to_segment(segment)
Shift the image so that the segment middle point ends up in the middle of the new image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segment
|
NDArray
|
segment as numpy array of shape (2, 2) |
required |
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
vector_shift |
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
restrict_rect_in_frame(rectangle)
Create a new rectangle that is contained within the image borders. If the input rectangle is outside the image, the returned rectangle is a image frame-fitted rectangle that preserve the same shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rectangle
|
Rectangle
|
input rectangle |
required |
Returns:
Type | Description |
---|---|
Rectangle
|
geo.Rectangle: new rectangle |
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
rotate(angle, is_degree=False, is_clockwise=True, reshape=True, fill_value=(0.0,), fast=True)
Rotate the image by a given angle.
For the rotation with reshape, meaning preserving the whole image, we used the code from the imutils library: https://github.com/PyImageSearch/imutils/blob/master/imutils/convenience.py#L41
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
angle to rotate the image |
required |
is_degree
|
bool
|
whether the angle is in degree or not. If not it is considered to be in radians. Defaults to False which means radians. |
False
|
is_clockwise
|
bool
|
whether the rotation is clockwise or counter-clockwise. Defaults to True. |
True
|
reshape
|
bool
|
whether to preserve the original image or not. If True, the complete image is preserved hence the width and height of the rotated image are different than in the original image. Defaults to True. |
True
|
border_fill_value
|
Sequence[float]
|
value to fill the border of the image after the rotation in case reshape is True. Can be a tuple of 3 integers for RGB image or a single integer for grayscale image. Defaults to (0.0,) which is black. |
required |
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
shift(shift, fill_value=(0.0,))
Shift the image by performing a translation operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shift
|
NDArray
|
Vector for translation |
required |
border_fill_value
|
int | tuple[int, int, int]
|
value to fill the border of the image after the rotation in case reshape is True. Can be a tuple of 3 integers for RGB image or a single integer for grayscale image. Defaults to (0.0,) which is black. |
required |
Source code in otary/image/components/transformer/components/geometrizer/geometrizer.py
Morphologyzer Transformer component
MorphologyzerImage
MorphologyzerImage.
Source code in otary/image/components/transformer/components/morphologyzer/morphologyzer.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
add_border(size, fill_value=0)
Add a border to the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thickness
|
int
|
border thickness. |
required |
color
|
int
|
border color. Defaults to 0. |
required |
Source code in otary/image/components/transformer/components/morphologyzer/morphologyzer.py
blur(kernel=(5, 5), iterations=1, method='average', sigmax=0)
Blur the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel
|
tuple
|
blur kernel size. Defaults to (5, 5). |
(5, 5)
|
iterations
|
int
|
number of iterations. Defaults to 1. |
1
|
method
|
str
|
blur method. Must be in ["average", "median", "gaussian", "bilateral"]. Defaults to "average". |
'average'
|
sigmax
|
float
|
sigmaX value for the gaussian blur. Defaults to 0. |
0
|
Source code in otary/image/components/transformer/components/morphologyzer/morphologyzer.py
dilate(kernel=(5, 5), iterations=1, dilate_black_pixels=True)
Dilate the image by making the black pixels expand in the image. The dilatation can be parametrize thanks to the kernel and iterations arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel
|
tuple
|
kernel to dilate. Defaults to (5, 5). |
(5, 5)
|
iterations
|
int
|
number of dilatation iterations. Defaults to 1. |
1
|
dilate_black_pixels
|
bool
|
whether to dilate black pixels or not |
True
|
Source code in otary/image/components/transformer/components/morphologyzer/morphologyzer.py
erode(kernel=(5, 5), iterations=1, erode_black_pixels=True)
Erode the image by making the black pixels shrink in the image. The anti-dilatation can be parametrize thanks to the kernel and iterations arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel
|
tuple
|
kernel to erode. Defaults to (5, 5). |
(5, 5)
|
iterations
|
int
|
number of iterations. Defaults to 1. |
1
|
erode_black_pixels
|
bool
|
whether to erode black pixels or not |
True
|
Source code in otary/image/components/transformer/components/morphologyzer/morphologyzer.py
resize(factor, interpolation=cv2.INTER_AREA, copy=False)
Resize the image to a new size using a scaling factor value that will be applied to all dimensions (width and height).
Applying this method can not result in a distorted image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
factor
|
float
|
factor in [0, 5] to resize the image. A value of 1 does not change the image. A value of 2 doubles the image size. A maximum value of 5 is set to avoid accidentally producing a gigantic image. |
required |
interpolation
|
int
|
resize interpolation. Defaults to cv2.INTER_AREA. |
INTER_AREA
|
copy
|
bool
|
whether to return a new image or not. |
False
|
Source code in otary/image/components/transformer/components/morphologyzer/morphologyzer.py
resize_fixed(dim, interpolation=cv2.INTER_AREA, copy=False)
Resize the image using a fixed dimension well defined. This function can result in a distorted image if the ratio between width and height is different in the original and the new image.
If the dim argument has a negative value in height or width, then a proportional ratio is applied based on the one of the two dimension given.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim
|
tuple[int, int]
|
a tuple with two integers in the following order (width, height). |
required |
interpolation
|
int
|
resize interpolation. Defaults to cv2.INTER_AREA. |
INTER_AREA
|
copy
|
bool
|
whether to return a new image or not. |
False
|