ImageAccess

ImageAccess

new ImageAccess(height, widthopt, init_dictopt) → {ImageAccess}

Creates a new image of the specified height and width.
Properties:
Name Type Description
image Array The image stored as a 2D Array
Source:
Parameters:
Name Type Attributes Description
height Integer | Array The height of the image, or an array of [height, width], or an existing 2D array
width Integer <optional>
The width of the image
init_dict Object <optional>
Object specifying the initial values for the image
Name Type Attributes Default Description
init_value Number <optional>
0 The initial value to set to all pixels
rgb Boolean <optional>
false Boolean indicating if the image is rgb or not
Returns:
Type:
ImageAccess
Examples

Create a new image of dimensions width x height

new ImageAccess(height, width);

Provide height and width as an array

new ImageAccess([height, width]);

Create a new image with the same dimensions as an existing image img

new ImageAccess(img.shape());

Set the initial value to 255

new Image(height, width, {init_value:255});

Creating an image from an existing 2D Array arr

new Image(arr);

Methods

(static) applyBoundaryCondition(x, y, shap, paddingopt) → {Array}

Adjusts index values based on the shape and specified boudary conditions
Source:
Parameters:
Name Type Attributes Default Description
x Integer The x index
y Integer The y index
shap Array The shape (size) of the image ([ny, nx])
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')
Returns:
Type:
Array
The modified indices as an array ([x, y])

(static) arrayCompare(a1, a2, erropt, tolopt, utilObjopt) → {Boolean}

Checks if two array are equal within a certain tolerance
Source:
Parameters:
Name Type Attributes Default Description
a1 Array The first array
a2 Array The second array
err Object <optional>
Object containing the error message
Name Type Attributes Default Description
msg Boolean <optional>
null The error message, specifying the type of error and more info
tol Number <optional>
1e-5 The tolerance used for the comparison
utilObj Object <optional>
Object containing internally used variables
Name Type Attributes Default Description
mismatch Number <optional>
0 The mismatch ratio
maxErr Number <optional>
0 The maximum error between the two Arrays
count Number <optional>
0 The number of mismatched elements
Returns:
Type:
Boolean
true if the two Arrays are equal within the tolerance, false if not

(static) fromHTMLImageElement(htmlImageElement) → {ImageAccess}

Creates an ImageAccess object from an HTMLImageElement object
Source:
Parameters:
Name Type Description
htmlImageElement HTMLImageElement The HTMLImageElement where the image is stored
Returns:
Type:
ImageAccess

(static) getMax(arr) → {Number}

Calculates the maximum value of an array with arbitrary dimensions
Source:
Parameters:
Name Type Description
arr Array The input Array
Returns:
Type:
Number
The maximum

(static) getMin(arr) → {Number}

Calculates the minimum value of an array with arbitrary dimensions
Source:
Parameters:
Name Type Description
arr Array The input Array
Returns:
Type:
Number
The minimum

(static) getNbh(img, x_pos, y_pos, nx, ny, paddingopt) → {Array}

Returns a neighbourhood of an Array
Source:
Parameters:
Name Type Attributes Default Description
img Array The 2D input Array
x_pos Integer The x position of the center of the neighbourhood
y_pos Integer The y position of the center of the neighbourhood
nx Integer The width of the neighbourhood
ny Integer The height of the neighbourhood
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')
Returns:
Type:
Array
- The neighbourhood as a 2D Array

(static) isNormalizationError(img1, img2, copt, tolopt) → {Boolean}

Checks if there is a normalization error between two Arrays. A normalization error means that one array is a scalar multiple of the other.
Source:
Parameters:
Name Type Attributes Default Description
img1 Array The first array
img2 Array The second array
c Object <optional>
Name Type Attributes Default Description
c Number <optional>
null The proportionality constant to check for. If not given it is calculated from the first pixel
tol Number <optional>
1e-3 The tolerance used for the comparison
Returns:
Type:
Boolean
true if it is a normalization error, false if not

(static) min(a, b) → {Number|Array}

Calculates the minimum per color channel of two color- or graylevel pixels
Source:
Parameters:
Name Type Description
a Number | Array The first pixel
b Number | Array The second pixel
Returns:
Type:
Number | Array
- The minimum per color channel of the two pixels

(static) MultidimArray(init_value, height, widthopt, depthopt) → {Array}

Creates a 1D/2D/3D Array
Source:
Parameters:
Name Type Attributes Description
init_value Number The initial value to set to all elements of the array
height Integer The height of the array
width Integer <optional>
The width of the array
depth Integer <optional>
The depth of the array
Returns:
Type:
Array
An array of size height x width x depth initialized to init_value

(static) ndims(arr) → {Number}

Source:
Parameters:
Name Type Description
arr Array
Returns:
Type:
Number
The number of dimensions of an array

(static) shape(arr)

Source:
Parameters:
Name Type Description
arr Array
Returns:
The shape / size of an array

(static) transpose(array) → {Array}

Returns the transpose of an array
Source:
Parameters:
Name Type Description
array Array The 2D input Array
Returns:
Type:
Array
The transposed Array

copy() → {ImageAccess}

Creates a copy of the image
Source:
Returns:
Type:
ImageAccess
A copy of the image

displayImage(scaleopt, showPixelsopt, idopt) → {HTMLCanvasElement}

Returns an html canvas to display the image
Source:
Parameters:
Name Type Attributes Default Description
scale Number <optional>
1 The size scale of the image
showPixels Boolean <optional>
false Indicates whether a pixel grid is drawn or not (only use for small images)
id String <optional>
'' The html canvas id to use
Returns:
Type:
HTMLCanvasElement
- The html canvas containing the image

fromArray(arr)

Updates the image from a provided array.
Source:
Parameters:
Name Type Description
arr Array A 2D Array containing the image

getColumn(x, paddingopt) → {ImageAccess}

Returns the column at location x
Source:
Parameters:
Name Type Attributes Default Description
x Integer The horizontal (x) location of the column
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')
Returns:
Type:
ImageAccess
The column of pixels at location x

getMax(recalcopt) → {Number}

Returns the maximum value of the image
Source:
Parameters:
Name Type Attributes Default Description
recalc Boolean <optional>
false A boolean indicating if the maximum needs to be recalculated
Returns:
Type:
Number
- The maximum value of the image

getMin(recalcopt) → {Number}

Returns the minimum value of the image
Source:
Parameters:
Name Type Attributes Default Description
recalc Boolean <optional>
false A boolean indicating if the minimum needs to be recalculated
Returns:
Type:
Number
- The minimum value of the image

getNbh(x_pos, y_pos, nx, ny, paddingopt) → {Nbh_Access}

Returns a neighbourhood of the image
Source:
Parameters:
Name Type Attributes Default Description
x_pos Integer The x position of the center of the neighbourhood
y_pos Integer The y position of the center of the neighbourhood
nx Integer The width of the neighbourhood
ny Integer The height of the neighbourhood
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero').
Returns:
Type:
Nbh_Access
- The neighbourhood

getPixel(x, y, paddingopt) → {Number}

Returns the pixel value at position (x,y)
Source:
Parameters:
Name Type Attributes Default Description
x Integer The horizontal (x) position of the pixel
y Integer The vertical (y) position of the pixel
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')
Returns:
Type:
Number
The pixel value

getRow(y, paddingopt) → {ImageAccess}

Returns the row of pixels at location y
Source:
Parameters:
Name Type Attributes Default Description
y Integer The vertical (y) location of the row
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')
Returns:
Type:
ImageAccess
The row of pixels at location y

getSubImage(x, y, nx, ny) → {ImageAccess}

Returns a sub-image from the image
Source:
Parameters:
Name Type Description
x Integer The horizontal (x) location of the top-left corner of the sub-image
y Integer The vertical (y) location of the top-left corner of the sub-image
nx Integer The width of the sub-image
ny Integer The height of the sub-image
Returns:
Type:
ImageAccess
- The extracted sub-image

imageCompare(newImage, erropt, tolopt) → {Boolean}

Checks if this image is equal to another within a certain tolerance
Source:
Parameters:
Name Type Attributes Default Description
newImage ImageAccess The second image to compare
err Object <optional>
Object containing the error message
Name Type Attributes Default Description
msg Boolean <optional>
null The error message, specifying the type of error and more info
tol Number <optional>
1e-5 The tolerance used for the comparison
Returns:
Type:
Boolean
true if the two images are equal within the tolerance, false if not

isNormalizationError(img) → {Boolean}

Checks if there is a normalization error between this image and another image. A normalization error means that one array is a scalar multiple of the other.
Source:
Parameters:
Name Type Description
img ImageAccess The other image to compare
Returns:
Type:
Boolean
true if it is a normalization error, false if not

ndims() → {Number}

Source:
Returns:
Type:
Number
The number of dimensions of the image

normalize() → {ImageAccess}

Maps the image to the range [0,1]
Source:
Returns:
Type:
ImageAccess
The remapped image

putColumn(x, new_column, paddingopt)

Inserts a new column at location x
Source:
Parameters:
Name Type Attributes Default Description
x Integer The horizontal (x) location of the column
new_column ImageAccess The new column to insert
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')

putRow(y, new_row, paddingopt)

Inserts a row at location y
Source:
Parameters:
Name Type Attributes Default Description
y Integer The vertical (y) position of the row
new_row ImageAccess The new row to insert
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')

putSubImage(x, y, img)

Inserts another image into the image
Source:
Parameters:
Name Type Description
x Integer The horizontal (x) location of the top-left corner of the sub-image
y Integer The vertical (y) location of the top-left corner of the sub-image
img ImageAccess The image to insert

setPixel(x, y, value, paddingopt)

Sets the pixel value at location (x,y)
Source:
Parameters:
Name Type Attributes Default Description
x Integer The horizontal (x) position of the pixel
y Integer The vertical (y) position of the pixel
value Number The new value to which this pixel will be set
padding String <optional>
'mirror' The boundary condition to apply ('mirror', 'repeat' or 'zero')

shape()

Source:
Returns:
The shape / size of the image

sort(bopt) → {ImageAccess}

Returns the pixel values in ascending order
Source:
Parameters:
Name Type Attributes Description
b ImageAccess <optional>
The kernel. It should be the same size as the image and contain 0s and 1s (or any other number), specifying which pixels are used during the sorting. By default, all pixels are used
Returns:
Type:
ImageAccess
The sorted pixels in ascending order

toArray() → {Array}

Source:
Returns:
Type:
Array
A Copy of the image as a 2D Array

toUint8() → {ImageAccess}

Maps the image to an 8-bit representation (range = [0,255])
Source:
Returns:
Type:
ImageAccess
The uint8 image

transposeImage()

Transposes the image in-place
Source:

visualize(decimalsopt) → {String}

Returns a formatted string that can be used to display the image in the console
Source:
Parameters:
Name Type Attributes Default Description
decimals Integer <optional>
3 The number of maximal decimals to use
Returns:
Type:
String
The image as a formatted string