Class: ImgArray

ImgArray(options)

ImgArray更重要的是数组,提供数组的计算,但是数组的运算支持上偏向于图像处理, 后期可以仿照Numpy转为强大的数组计算库,支持常见的多种元素数据类型初始化,但是仅对 float32类型进行了广泛地验证和测试,其他类型未验证,使用时需要注意自行检查。

Constructor

new ImgArray(options)

constructor,数组初始化函数,采用对象的方式进行初始化,提供了默认参数。 只实现了三维数组,各维度类比于图像的高,宽和通道,即height,width,channel。
Parameters:
Name Type Description
options Object 配置对象,用于初始化图像数据。
Properties
Name Type Attributes Default Description
height number <optional>
256 表示数组(图像)的高度,默认值是256
width number <optional>
256 表示数组(图像)的宽度,默认值是256
channel number <optional>
3 表示数组(图像)的通道数,默认值是3
lazy boolean <optional>
false 默认值为false,表示进行数组元素的初始化,否则不进行元素的数组元素的初始化
dtype string <optional>
'float32' 默认为'float32',可选的值为dtypes中的值
Source:

Members

buffer :ArrayBuffer

buffer,获取 ImgArray 的 ArrayBuffer。
Type:
  • ArrayBuffer
Source:

bytesize :number

bytesize,用属性的方式获取数组占用的总字节数。
Type:
  • number
Source:

dtypes :Object

dtypes 是一个静态对象,对于存储数组数据的类型与JS TypedArray的映射关系。
Type:
  • Object
Source:
Example
//dtypes的值如下:
  dtypes = {
  float32: Float32Array,
  uint8: Uint8Array,
  uint16: Uint16Array,
  int32: Int32Array,
  uint32: Uint32Array,
  cuint8: Uint8ClampedArray,
  int16: Int16Array,
  int8: Int8Array,
  float64: Float64Array,
  };  

elbytes :number

elbytes,数组中一个元素占用的字节数。
Type:
  • number
Source:

shape :Shape

返回图像的形状对象。用属性的方式获取数组的形状,包括高,宽,通道。
Type:
Source:

size :number

size,获取数组元素的个数。
Type:
  • number
Source:

typedarray :TypedArray

typedarray,获取 ImgArray 的 TypedArray。
Type:
  • TypedArray
Source:

(static) dtypenames :Array.<string>

dtypenames 获取ImgArray#dtypes对象中所有数据类型的名称。返回一个包含所有数据类型名称的数组,数组中包含ImgArray#dtypes对象的所有键。
Type:
  • Array.<string>
Source:

Methods

abs() → {ImgArray}

abs,对数组中的每个元素计算绝对值。返回一个与原数组尺寸相同的新数组,每个元素为原数组元素的绝对值。
Source:
Returns:
Type
ImgArray

adaptiveThreshold(sizesopt, fillvalueopt, constantopt) → {ImgArray}

adaptiveThreshold,自适应阈值分割,使用给定的结构元素对图像进行自适应阈值分割。
Parameters:
Name Type Attributes Default Description
sizes Array.<Array.<number>> <optional>
[3, 3] 自适应阈值分割的结构元素,通常是一个矩阵,表示自适应阈值分割的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 自适应阈值分割中填充区域的值,默认为 0。
constant number <optional>
0 自适应阈值分割的常数,默认为 0。
Source:
Returns:
返回自适应阈值分割后的图像数据对象。
Type
ImgArray

add(otherArrayOrValue) → {ImgArray|null}

add,数组加法,支持常数加法
Parameters:
Name Type Description
otherArrayOrValue ImgArray | number 与当前数组尺寸相同,或者为一个常数
Source:
Returns:
加法后的结果,若输入的是无效的操作数,则返回null
Type
ImgArray | null

apply_along_channel(func) → {ImgArray}

apply_along_channel,沿通道的运算
Parameters:
Name Type Description
func function 一回调函数接收一个一维数组,返回一个数值
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含运算后的数据。
Type
ImgArray

astype(dtypeopt) → {ImgArray}

astype,将数组的元素类型转换为指定的类型,要注意不同类型数值表示范围差异可能带来的精度损失!
Parameters:
Name Type Attributes Default Description
dtype string <optional>
'float32' 要转换的元素类型,变量ImgArray.dtypenames里的所有类型,如 'float32' , 'uint8'等。
Source:
Returns:
返回一个具有指定元素类型的 ImgArray 对象。
Type
ImgArray

avgpooling(sizeopt, fillvalueopt) → {ImgArray}

avgpooling,应用平均值池化对图像进行降采样。
Parameters:
Name Type Attributes Default Description
size Array.<number> <optional>
[3, 3] 池化核的大小,默认为 `[3, 3]`。
fillvalue number <optional>
0 填充值,默认为 `0`。
Source:
Returns:
返回一个新的图像数据对象,应用了平均值池化。
Type
ImgArray

blackhat(patternopt, fillvalueopt) → {ImgArray}

blackhat,黑帽运算,使用给定的结构元素对图像进行黑帽运算。
Parameters:
Name Type Attributes Default Description
pattern Array.<Array.<number>> <optional>
[[1, 1, 1], [0, 1, 0], [1, 1, 1]] 黑帽运算的结构元素,通常是一个矩阵,表示黑帽运算的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 黑帽运算中填充区域的值,默认为
Source:
Returns:
返回黑帽运算后的图像数据对象。
Type
ImgArray

canny() → {ImgArray}

canny,应用 Canny 算子。对图像进行边缘检测
Source:
Returns:
返回一个新的图像数据对象,应用了 Canny 算子。
Type
ImgArray

cellsim(sizesopt) → {ImgArray}

cellsim,计算元胞自动机(Cellular Automaton)特征。 元胞自动机是一种描述自然界中复杂规则的数学模型,常用于图像处理和计算机视觉等应用。
Parameters:
Name Type Attributes Default Description
sizes Array.<Array.<number>> <optional>
[3, 3] 元胞自动机特征的邻域大小,默认为 3x3 的邻域。
Source:
Returns:
返回包含元胞自动机特征的图像数据对象。
Type
ImgArray

checkisvalid(hidx, widx, cidx) → {boolean}

checkisvalid,检查索引值是否合法,即是否在数组范围内 目前只支持正索引
Parameters:
Name Type Description
hidx number 数组元素的高索引,也就是第0维度的索引
widx number 数组元素的宽索引,也就是第1维度的索引
cidx number 数组元素的通道索引,也就是第2维度的索引
Source:
Returns:
- true表示索引合法,false表示索引不合法
Type
boolean

chw2hwc() → {ImgArray}

chw2hwc,将图像或数组的形状从 CHW 转换为 HWC 格式。 hwc2chw的逆操作,hwc2chw和chw2hwc都是transpose的简单化
Source:
Returns:
返回一个形状为 HWC 格式的 ImgArray 对象。
Type
ImgArray

clamp(vminopt, vmaxopt) → {ImgArray}

clamp,截断,将小于vmin的元素变成vmin,大于vmax的元素变成vmax
Parameters:
Name Type Attributes Default Description
vmin number <optional>
0 最小值,默认为0
vmax number <optional>
255 最大值,默认为255
Source:
Returns:
截断后的结果
Type
ImgArray

close(patternopt, fillvalueopt) → {ImgArray}

close,闭运算操作,使用给定的结构元素对图像进行闭运算。
Parameters:
Name Type Attributes Default Description
pattern Array.<Array.<number>> <optional>
[[1, 1, 1], [0, 1, 0], [1, 1, 1]] 闭运算的结构元素,通常是一个矩阵,表示闭运算的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 闭运算中填充区域的值,默认为 0。
Source:
Returns:
返回闭运算后的图像数据对象。
Type
ImgArray

conv2d(weightsopt, biasopt, fillvalueopt) → {ImgArray}

conv2d,卷积运算,weights卷积
Parameters:
Name Type Attributes Default Description
weights Array.<Array.<number>> <optional>
[[1/9, 1/9, 1/9], [1/9, 1/9, 1/9], [1/9, 1/9, 1/9]] 卷积核,是一个二维数组,表示卷积核的权重
bias number <optional>
0 偏差值,默认为0
fillvalue number <optional>
0 填充的值,默认为0
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含卷积运算后的数据。
Type
ImgArray

copy() → {ImgArray}

copy,复制当前图像数据对象,创建一个新副本。
Source:
Returns:
当前图像数据的副本。
Type
ImgArray

cossimdist(v2opt) → {ImgArray}

cossimdist,计算数组在通道方向与一个向量的余弦距离。
Parameters:
Name Type Attributes Default Description
v2 Array.<number> <optional>
[3, 4, 5] 用于计算距离的向量。
Source:
Returns:
返回一个 ImgArray 对象,表示计算得到的距离数组。
Type
ImgArray

dilate(patternopt, filfillvalueopt) → {ImgArray}

dilate,膨胀操作,使用给定的结构元素对图像进行膨胀。
Parameters:
Name Type Attributes Default Description
pattern Array.<Array.<number>> <optional>
[[1, 1, 1], [0, 1, 0], [1, 1, 1]] 膨胀操作的结构元素,通常是一个矩阵,表示膨胀的形状和大小。默认为 3x3 的邻域。
filfillvalue number <optional>
0 膨胀操作中填充区域的值,默认为 0。
Source:
Returns:
返回膨胀后的图像数据对象。
Type
ImgArray

dist(v2opt) → {ImgArray}

dist,计算数组在通道方向与一个向量的欧氏距离。
Parameters:
Name Type Attributes Default Description
v2 Array.<number> <optional>
[3, 4, 5] 用于计算距离的向量。
Source:
Returns:
返回一个 ImgArray 对象,表示计算得到的距离数组。
Type
ImgArray

div(otherArrayOrValue) → {ImgArray|null}

div,数组除法,支持常数或数组
Parameters:
Name Type Description
otherArrayOrValue ImgArray | number 与当前数组尺寸相同,或者为一个常数
Source:
Returns:
除法后的结果,若输入的除数数组中包含0元素或除数不合法,则返回null
Type
ImgArray | null

dsplit(…channels) → {ImgArray}

dsplit,提取数组的某些通道
Parameters:
Name Type Attributes Description
channels number <repeatable>
要提取的通道索引
Source:
Returns:
提取的数组
Type
ImgArray

dstack(…imgars) → {ImgArray|undefined}

dstack,将多个数组沿通道堆叠,数组的宽高必须要相同
Parameters:
Name Type Attributes Description
imgars ImgArray | ImgArray <repeatable>
一个或多个数组
Source:
Returns:
堆叠形成的新数组,若堆叠数组的宽高尺寸不一致,返回undefined
Type
ImgArray | undefined

elidxtoidx(elidxopt) → {Array.<number>|undefined}

elidxtoidx,将元素的索引转为数组的三个索引值[h,w,c] 该函数是一个内部函数,一般由其他方法调用,不对外使用
Parameters:
Name Type Attributes Default Description
elidx number <optional>
0 线性索引,默认值为0,表示获取第一个元素,即[0,0,0]
Source:
Returns:
返回一个包含三维索引的数组,或者如果 `elidx` 超出范围,返回 `undefined`。 - hidx: 高度索引,表示数组的第0维索引。 - widx: 宽度索引,表示数组的第1维索引。 - cidx: 通道索引,表示数组的第2维索引。
Type
Array.<number> | undefined

empty(lazyopt) → {ImgArray}

empty,创建一个与当前图像数据对象相同尺寸的空数组,考虑了ImgArray和Img实例。
Parameters:
Name Type Attributes Default Description
lazy boolean <optional>
false 是否启用懒加载,默认为 false。
Source:
Returns:
创建的空数组。
Type
ImgArray

erode(patternopt, fillvalueopt) → {ImgArray}

erode,腐蚀操作,使用给定的结构元素对图像进行腐蚀。
Parameters:
Name Type Attributes Default Description
pattern Array.<Array.<number>> <optional>
[[1, 1, 1], [0, 1, 0], [1, 1, 1]] 腐蚀操作的结构元素,通常是一个矩阵,表示腐蚀的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 腐蚀操作中填充区域的值,默认为 0。
Source:
Returns:
返回腐蚀后的图像数据对象。
Type
ImgArray

fill(valueopt, cidxopt) → {ImgArray}

fill,向数组填充常数数值。
Parameters:
Name Type Attributes Default Description
value number | Array.<number> <optional>
3 要填充的值,可以是一个数值,也可以是一个数组,数组长度与通道数相同,表示对每个通道进行填充
cidx number | Array.<number> <optional>
null 要填充的通道索引,可以是一个数值,也可以是一个数组,表示对多个通道进行填充
Source:
Returns:
该数组对象本身
Type
ImgArray
Examples
new ImgArray().fill(255);        //填充所有元素值为255;
new ImgArray().fill(255,1);     //只对1通道填充为255;
new ImgArray().fill(255,[0,1]); //对0,1通道填充均填充为255
new ImgArray().fill([255,120],[0,2]);    //对0通道填充255,对2道填充120

fliplr() → {ImgArray}

filiplr,在宽度轴上,进行左右翻转
Source:
Returns:
水平翻转后的结果
Type
ImgArray

flipud() → {ImgArray}

flipud, 在高度轴上,进行上下翻转
Source:
Returns:
上下翻转后的结果
Type
ImgArray

gaussianBlur(sigmaopt, kernel_sizeopt, fillvalueopt) → {ImgArray}

gaussianBlur,应用高斯模糊。 该方法生成一个高斯核,并将其应用于图像数据,实现高斯模糊效果。
Parameters:
Name Type Attributes Default Description
sigma number <optional>
2 高斯核的标准差,控制模糊的程度。默认为 `2`。
kernel_size Array.<number> <optional>
[3, 3] 高斯核的尺寸,默认为 `[3, 3]`。尺寸应该为奇数。
fillvalue number <optional>
0 邻域填充的默认值,默认为 `0`。
Source:
Returns:
返回一个新的图像数据对象,应用了高斯模糊。
Type
ImgArray

getel(hidx, widx, cidx) → {number|null}

getel,根据数组索引获取元素值
Parameters:
Name Type Description
hidx number 数组元素的高索引,也就是第0维度的索引
widx number 数组元素的宽索引,也就是第1维度的索引
cidx number 数组元素的通道索引,也就是第2维度的索引
Source:
Returns:
元素值,若数组元素索引越界,则返回null
Type
number | null

globalminmax() → {Object}

globalminmax,获取整个数组的最小值和最大值
Source:
Returns:
包含最小值和最大值的对象
Type
Object

grid(row, col, …imgarrs) → {ImgArray|undefined}

grid,将多个尺寸相同的数组堆叠成网格
Parameters:
Name Type Attributes Description
row number 行数
col number 列数
imgarrs ImgArray <repeatable>
需要堆叠的数组
Source:
Returns:
网格堆叠后的结果,若尺寸不一致,返回undefined
Type
ImgArray | undefined

hstack(…imgars) → {ImgArray}

hstack,水平堆叠数组,沿宽度方向叠加
Parameters:
Name Type Attributes Description
imgars ImgArray <repeatable>
水平堆叠的数组
Source:
Returns:
水平堆叠后的结果
Type
ImgArray

hwc2chw() → {ImgArray}

hwc2chw,用于将hxwxc转为cxhxw的方法,返回一个排列为cxhxw的一维float32数组
Source:
Returns:
返回一个形状为 CHW 格式的 ImgArray 对象。
Type
ImgArray

idxtoelidx(hidx, widx, cidx) → {number}

idxtoelidx,将数组的三个索引值[h,w,c],转为元素索引elidx 该函数是一个内部函数,一般由其他方法调用,不对外使用
Parameters:
Name Type Description
hidx number 数组元素的高索引,也就是第0维度的索引
widx number 数组元素的宽索引,也就是第1维度的索引
cidx number 数组元素的通道索引,也就是第2维度的索引
Source:
Returns:
- 元素在数组内的真实索引值
Type
number

initarray() → {ImgArray}

initarray() 根据数组的基本信息,为数组分配存储空间。 当数组初始化时lazy=false时调用,分配空间,分配后数组元素的值为0。
Source:
Returns:
返回当前实例,以支持链式调用。
Type
ImgArray

issamech(bimgarr) → {Boolean}

issamech,判断两数组的通道是否相同
Parameters:
Name Type Description
bimgarr ImgArray 另一个数组
Source:
Returns:
两数组的通道是否相同
Type
Boolean

issamehw(bimgarr) → {Boolean}

issamehw,两数组宽高是否相同
Parameters:
Name Type Description
bimgarr ImgArray 另一个数组
Source:
Returns:
两数组宽高是否相同
Type
Boolean

issameshape(bimgarr) → {Boolean}

issameshape,两数组形状是否相同
Parameters:
Name Type Description
bimgarr ImgArray 另一个数组
Source:
Returns:
两数组形状是否相同
Type
Boolean

kmeans(k, centers, disttypeopt) → {Array}

kmeans,使用 K 均值聚类算法对图像数据进行聚类。
Parameters:
Name Type Attributes Default Description
k number 4 聚类的数量。
centers Array.<Array.<number>> | null null 初始聚类中心,是一个二维数组(kxchannel)。如果为 `null`,程序将随机选择初始中心。
disttype string <optional>
'dist' 距离度量方式,可选值为 'dist'(欧氏距离)或 'cossimdist'(余弦相似度)。
Source:
Returns:
返回两个值: - `newcenters`:更新后的聚类中心。 - `clusterresult`:一个 ImgArray 对象,表示每个像素的聚类结果。
Type
Array

laplacian(sizeopt) → {ImgArray}

laplacian,应用拉普拉斯算子对图像进行边缘检测。
Parameters:
Name Type Attributes Default Description
size number <optional>
4 拉普拉斯核的大小,默认为 `4`。
Source:
Returns:
返回一个新的图像数据对象,应用了拉普拉斯算子。
Type
ImgArray

lbp() → {ImgArray}

lbp,计算经典的局部二值模式(LBP)特征。 LBP 用于描述图像的局部纹理特征,常用于图像分类和面部识别等任务。
Source:
Returns:
返回包含 LBP 特征的图像数据对象。
Type
ImgArray

linearc(weightsopt, baisopt) → {ImgArray}

linearc,线性加权
Parameters:
Name Type Attributes Default Description
weights Array.<number> <optional>
[1, 2, 3] 线性加权系数,是一个一维数组,表示每个通道的权重
bais number <optional>
0 偏差值,默认为0
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含线性加权后的数据。
Type
ImgArray

lmi(sizesopt) → {ImgArray}

lmi,计算 LMI 特征。 LMI 用于描述图像的局部纹理特征,常用于图像分类和面部识别等任务。
Parameters:
Name Type Attributes Default Description
sizes Array.<Array.<number>> <optional>
[3, 3] LMI 特征的邻域大小,默认为 3x3 的邻域。
Source:
Returns:
返回包含 LMI 特征的图像数据对象。
Type
ImgArray

max(ischannelopt) → {number|ImgArray}

max,计算最大值,膨胀,最大值池化
Parameters:
Name Type Attributes Default Description
ischannel boolean <optional>
false 当ischannel为True时,沿通道计算最大值,否则计算全局最大值
Source:
Returns:
返回一个数值或一个新的 `ImgArray` 实例,包含最大值或最大值数组。
Type
number | ImgArray

maxpooling(sizeopt, fillvalueopt) → {ImgArray}

maxpooling,应用最大值池化对图像进行降采样。
Parameters:
Name Type Attributes Default Description
size Array.<number> <optional>
[3, 3] 池化核的大小,默认为 `[3, 3]`。
fillvalue number <optional>
0 填充值,默认为 `0`。
Source:
Returns:
返回一个新的图像数据对象,应用了最大值池化。
Type
ImgArray

mean(ischannelopt) → {number|ImgArray}

mean,计算均值
Parameters:
Name Type Attributes Default Description
ischannel boolean <optional>
false 当ischannel为True时,沿通道计算均值,否则计算全局均值
Source:
Returns:
返回一个数值或一个新的 `ImgArray` 实例,包含均值或均值数组。
Type
number | ImgArray

median(sizesopt, fillvalueopt) → {ImgArray}

median,中值滤波,对通道数为1的数组结果正确
Parameters:
Name Type Attributes Default Description
sizes Array.<Array.<number>> <optional>
[3, 3] 邻域大小,是一个二维数组,表示邻域的大小
fillvalue number <optional>
0 填充的值,默认为0
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含中值滤波后的数据。
Type
ImgArray

mgradient(sizesopt, fillvalueopt) → {ImgArray}

mgradient,形态学梯度操作,使用给定的结构元素对图像进行形态学梯度操作。
Parameters:
Name Type Attributes Default Description
sizes Array.<Array.<number>> <optional>
[3, 3] 形态学梯度操作的结构元素,通常是一个矩阵,表示形态学梯度的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 形态学梯度操作中填充区域的值,默认为 0。
Source:
Returns:
返回形态学梯度后的图像数据对象。
Type
ImgArray

min(ischannelopt) → {number|ImgArray}

min,计算最小值,腐蚀,最小值池化
Parameters:
Name Type Attributes Default Description
ischannel boolean <optional>
false 当ischannel为True时,沿通道计算最小值,否则计算全局最小值
Source:
Returns:
返回一个数值或一个新的 `ImgArray` 实例,包含最小值或最小值数组。
Type
number | ImgArray

minpooling(sizeopt, fillvalueopt) → {ImgArray}

minpooling,应用最小值池化对图像进行降采样。
Parameters:
Name Type Attributes Default Description
size Array.<number> <optional>
[3, 3] 池化核的大小,默认为 `[3, 3]`。
fillvalue number <optional>
0 填充值,默认为 `0`。
Source:
Returns:
返回一个新的图像数据对象,应用了最小值池化。
Type
ImgArray

mul(otherArrayOrValue) → {ImgArray|null}

mul,数组乘法,支持常数或数组
Parameters:
Name Type Description
otherArrayOrValue ImgArray | number 与当前数组尺寸相同,或者为一个常数
Source:
Returns:
乘法后的结果,若输入的是无效的操作数,则返回null
Type
ImgArray | null

neighbor(sizesopt, fillvalueopt) → {ImgArray}

neighbor,按尺寸进行邻域展开,sizes是2个元素组成的数组,表示邻域的高和宽,里边应当是奇数 该方法实际上不操作,只生成pattern,调用strcuture完成邻域的生成
Parameters:
Name Type Attributes Default Description
sizes Array.<number> <optional>
[3, 3] 邻域的尺寸,是一个2个元素的数组,表示邻域的高和宽
fillvalue number <optional>
0 填充的值,默认为0
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含邻域展开后的数据。
Type
ImgArray

open(patternopt, fillvalueopt) → {ImgArray}

open,开运算操作,使用给定的结构元素对图像进行开运算。
Parameters:
Name Type Attributes Default Description
pattern Array.<Array.<number>> <optional>
[[1, 1, 1], [0, 1, 0], [1, 1, 1]] 开运算的结构元素,通常是一个矩阵,表示开运算的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 开运算中填充区域的值,默认为 0。
Source:
Returns:
返回开运算后的图像数据对象。
Type
ImgArray

operateArrayOperation(otherArray, func) → {ImgArray|null}

operateArrayOperation,数组间运算,运算方式由参数func决定
Parameters:
Name Type Description
otherArray ImgArray 与当前数组尺寸相同
func function 是一个具有两个参数的函数,返回一个值
Source:
Returns:
运算结果,若两数组的尺寸不匹配或类型不匹配,则返回null
Type
ImgArray | null

opposite() → {ImgArray}

opposite,取反,即每个元素取负
Source:
Returns:
取反结果
Type
ImgArray

pad(options) → {ImgArray}

pad,对高和宽进行常数填充的扩边操作,顺序是左上右下
Parameters:
Name Type Description
options Object 填充选项
Properties
Name Type Attributes Default Description
l number <optional>
1 左边填充的个数,默认为1
r number <optional>
2 右边填充的个数,默认为2
t number <optional>
3 上边填充的个数,默认为3
b number <optional>
4 下边填充的个数,默认为4
fillvalue number <optional>
0 填充的值,默认为0
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含填充后的数据。
Type
ImgArray

pow(value) → {ImgArray}

pow,幂运算,计算数组中每个元素的幂。
Parameters:
Name Type Description
value number 幂数
Source:
Returns:
幂运算结果
Type
ImgArray

prewittx() → {ImgArray}

prewittx,对图像应用 Prewitt 算子,计算图像在 X 方向上的梯度。
Source:
Returns:
返回计算后的图像数据对象。
Type
ImgArray

prewittxy() → {ImgArray}

prewittxy,计算图像的梯度幅值,结合 Prewitt X 和 Prewitt Y 方向的梯度。
Source:
Returns:
返回图像的梯度幅值。
Type
ImgArray

prewitty() → {ImgArray}

prewitty,对图像应用 Prewitt 算子,计算图像在 Y 方向上的梯度。
Source:
Returns:
返回计算后的图像数据对象。
Type
ImgArray

print()

在控制台以格式化的字符串打印数组。
Source:

relu(valueopt) → {ImgArray}

ReLU函数,将小于value的元素变成value,大于value的不变
Parameters:
Name Type Attributes Default Description
value number <optional>
0 阈值,默认为0
Source:
Returns:
ReLU函数结果
Type
ImgArray

repeat(row, col) → {ImgArray|undefined}

repeat,在水平和竖直方向重复数组
Parameters:
Name Type Description
row number 在高度方向上重复的次数,也就是在行方向上重复的次数
col number 在宽度方向上重复的次数,也就是在列方向上重复的次数
Source:
Returns:
重复后的结果,若row * col < 2,则返回undefined
Type
ImgArray | undefined

rolllr(dxopt) → {ImgArray}

rolllr,左右滚动
Parameters:
Name Type Attributes Default Description
dx number <optional>
100 滚动距离,默认为100
Source:
Returns:
滚动后的结果
Type
ImgArray

rollud(dyopt) → {ImgArray}

rollud,上下滚动
Parameters:
Name Type Attributes Default Description
dy number <optional>
100 滚动距离,默认为100
Source:
Returns:
滚动后的结果
Type
ImgArray

rotate(degreeopt) → {ImgArray}

rotate,旋转
Parameters:
Name Type Attributes Default Description
degree number <optional>
90 旋转角度,默认为90
Source:
Returns:
旋转后的结果
Type
ImgArray

scale(scale)

最近邻放大 scale,数组,使用最近邻方法进行对数组在宽度和高度上进行整数倍的缩放。
Parameters:
Name Type Description
scale number 尺寸
Source:

setel(hidx, widx, cidx, value) → {ImgArray|null}

setel,根据索引设置指定元素的值
Parameters:
Name Type Description
hidx number 数组元素的高索引,也就是第0维度的索引
widx number 数组元素的宽索引,也就是第1维度的索引
cidx number 数组元素的通道索引,也就是第2维度的索引
value number 要设置的元素值
Source:
Returns:
该数组对象本身,若数组元素索引越界,则返回null
Type
ImgArray | null

sharrx() → {ImgArray}

sharrx,对图像应用 Sobel 算子,计算图像在 X 方向上的梯度。
Source:
Returns:
返回计算后的图像数据对象。
Type
ImgArray

sharrxy() → {ImgArray}

sharrxy,计算图像的梯度幅值,通过结合 Sobel X 和 Sobel Y 方向的梯度计算结果。
Source:
Returns:
返回图像的梯度幅值。
Type
ImgArray

sharry() → {ImgArray}

sharry,对图像应用 Sobel 算子,计算图像在 Y 方向上的梯度。
Source:
Returns:
返回计算后的图像数据对象。
Type
ImgArray

show(options) → {Img}

show,显示数组的内容,当数组为图像时,直接在网页中显示图像,方便观察。 与matploblib的imshow很相似
Parameters:
Name Type Description
options Object 可选参数对象。
Properties
Name Type Attributes Default Description
vmin number <optional>
0 数组的最小值。
vmax number <optional>
255 数组的最大值。
cas number <optional>
null 可选的画布对象。
Source:
Returns:
返回显示的图像对象。
Type
Img

slice(sthidx, edhidx, stwidx, edwidx) → {ImgArray}

slice,对高和宽进行切片操作
Parameters:
Name Type Description
sthidx number 高的起始位置(不包含结束位置)
edhidx number 高的结束位置(不包含结束位置)
stwidx number 宽的起始位置(不包含结束位置)
edwidx number 宽的结束位置(不包含结束位置)
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含切片后的数据。
Type
ImgArray

sobelx() → {ImgArray}

sobelx,对图像应用 Sobel 算子,计算图像在 X 方向上的梯度。
Source:
Returns:
返回计算后的图像数据对象。
Type
ImgArray

sobelxy() → {ImgArray}

sobelxy,计算图像的梯度幅值,结合 Sobel X 和 Sobel Y 方向的梯度。
Source:
Returns:
返回图像的梯度幅值。
Type
ImgArray

sobely() → {ImgArray}

sobely,对图像应用 Sobel 算子,计算图像在 Y 方向上的梯度。
Source:
Returns:
返回计算后的图像数据对象。
Type
ImgArray

span(lower, upper, vminopt, vmaxopt) → {ImgArray}

span 区间变换
Parameters:
Name Type Attributes Default Description
lower number 下限
upper number 上限
vmin number <optional>
0 最小值,默认为0
vmax number <optional>
255 最大值,默认为255
Source:
Returns:
区间变换结果
Type
ImgArray

square() → {ImgArray}

square,计算数组中每个元素的平方。
Source:
Returns:
平方结果
Type
ImgArray

stretch(vminopt, vmaxopt) → {ImgArray}

stretch,拉伸到指定的数值范围内
Parameters:
Name Type Attributes Default Description
vmin number <optional>
0 最小值,默认为0
vmax number <optional>
255 最大值,默认为255
Source:
Returns:
拉伸后的结果
Type
ImgArray

structure(pattern, fillvalueopt) → {ImgArray}

structure,按照结构元素进行邻域展开
Parameters:
Name Type Attributes Default Description
pattern Array 结构元素,是一个二维数组,表示邻域的形状
fillvalue number <optional>
0 填充的值,默认为0
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含邻域展开后的数据。
Type
ImgArray

sub(otherArrayOrValue) → {ImgArray|null}

sub,数组减法,支持常数或数组
Parameters:
Name Type Description
otherArrayOrValue ImgArray | number 与当前数组尺寸相同,或者为一个常数
Source:
Returns:
减法后的结果,若输入的是无效的操作数,则返回null
Type
ImgArray | null

threshold(thresholdopt, methodopt, maxvalopt) → {ImgArray}

todo:分成5个函数,分别对应不同的阈值处理方式
Parameters:
Name Type Attributes Default Description
threshold number <optional>
100 阈值,默认为100
method string <optional>
'binary' 阈值处理方式,默认为'binary',可选值有'binary'、'truncate'、'binary_inv'、'tozero'、'tozero_inv'
maxval number <optional>
255 最大值,默认为255
Source:
Returns:
阈值处理结果
Type
ImgArray

toString() → {string}

toString,参照Numpy的方式将数组转为字符显示,对于大数组的显示存在问题。
Source:
Returns:
数组的字符串表示
Type
string

tofile(nameopt, typeopt)

tofile,将数组保存为文件。*实验性质的方法,先解决有没有,后续根据需要再完善*
Parameters:
Name Type Attributes Default Description
name string <optional>
'download' 文件名。
type string <optional>
'txt' 文件类型,可以是 'txt' 或 'bin'。
Source:

tophat(patternopt, fillvalueopt) → {ImgArray}

tophat,顶帽运算,使用给定的结构元素对图像进行顶帽运算。
Parameters:
Name Type Attributes Default Description
pattern Array.<Array.<number>> <optional>
[[1, 1, 1], [0, 1, 0], [1, 1, 1]] 顶帽运算的结构元素,通常是一个矩阵,表示顶帽运算的形状和大小。默认为 3x3 的邻域。
fillvalue number <optional>
0 顶帽运算中填充区域的值,默认为 0。
Source:
Returns:
返回顶帽运算后的图像数据对象。
Type
ImgArray

totensor(dtypeopt) → {ort.Tensor}

totensor,将数组转为onnxruntime中的张量。
Parameters:
Name Type Attributes Default Description
dtype string <optional>
'float32' 张量数据类型,可以是 'float32' 或 'uint8'。
Source:
Returns:
返回一个张量对象。
Type
ort.Tensor

vectorize(func) → {ImgArray}

vectorize,逐元素运算,function的形式参考array.map接受的回调函数的形式
Parameters:
Name Type Description
func function 函数,形式为(x)=>y
Source:
Returns:
运算结果
Type
ImgArray

vectorizemath() → {ImgArray}

vectorizemath,对Math中的函数进行运算
Source:
Returns:
函数运算结果
Type
ImgArray

vstack(…imgarrs) → {ImgArray}

vstack,垂直堆叠数组,沿高度方向叠加
Parameters:
Name Type Attributes Description
imgarrs ImgArray <repeatable>
垂直堆叠的数组
Source:
Returns:
垂直堆叠后的结果
Type
ImgArray

(static) fromArray(arr, shape, dtypeopt) → {ImgArray}

fromArray,从一个数组创建一个 ImgArray。
Parameters:
Name Type Attributes Default Description
arr Array 用于创建 ImgArray 的数组。
shape ImgArray 创建 ImgArray 的形状。
dtype string <optional>
'float32' 创建 ImgArray 的数据类型,默认为 'float32'。
Source:
Throws:
如果数组的类型与 ImgArray 的类型不匹配,则抛出异常。
Type
Error
Returns:
返回一个ImgArray 对象,表示从数组创建的 ImgArray
Type
ImgArray

(static) fromBuffer(arraybuffer, shape, dtypeopt) → {ImgArray}

fromBuffer,从一个 ArrayBuffer 创建一个 ImgArray。
Parameters:
Name Type Attributes Default Description
arraybuffer ArrayBuffer 用于创建 ImgArray 的 ArrayBuffer。
shape ImgArray 创建 ImgArray 的形状。
dtype string <optional>
'float32' 创建 ImgArray 的数据类型,默认为 'float32'。
Source:
Throws:
  • 如果 dtype 不是 ImgArray 支持的数据类型,则抛出异常。
    Type
    Error
  • 如果 ArrayBuffer 的长度与 shape 不匹配,则抛出异常。
    Type
    Error
Returns:
返回一个ImgArray 对象,表示从 ArrayBuffer 创建的 ImgArray
Type
ImgArray

(static) fromtensor(tensor) → {ImgArray}

fromtensor,将onnxruntime中的张量转为数组。
Parameters:
Name Type Description
tensor ort.Tensor 张量对象。
Source:
Returns:
返回一个 ImgArray 对象。
Type
ImgArray

(static) full(options) → {ImgArray}

full,创建一个指定尺寸的指定值数组。
Parameters:
Name Type Description
options Object 创建数组的选项。
Properties
Name Type Attributes Default Description
height number <optional>
256 数组的高度,默认为 256。
width number <optional>
256 数组的宽度,默认为 256。
channel number <optional>
3 数组的通道数,默认为 3。
value number <optional>
0 数组元素的值,默认为 0。
Source:
Returns:
返回一个 ImgArray 对象,表示创建的指定值数组。
Type
ImgArray

(static) meshgrid(hrangeopt, wrangeopt) → {Array.<ImgArray>}

meshgrid,创建一个规则格网,用于在图像处理中生成网格特征。
Parameters:
Name Type Attributes Default Description
hrange Array.<number> <optional>
[0, 256] 格网在垂直方向的范围,默认为 [0, 256]。
wrange Array.<number> <optional>
[0, 256] 格网在水平方向的范围,默认为 [0, 256]。
Source:
Returns:
返回一个包含两个 ImgArray 对象的数组,其中第一个数组表示垂直方向的格网,第二个数组表示水平方向的格网。
Type
Array.<ImgArray>

(static) ones(options) → {ImgArray}

ones,创建一个指定尺寸的 ones 数组。
Parameters:
Name Type Description
options Object 创建数组的选项。
Properties
Name Type Attributes Default Description
height number <optional>
256 数组的高度,默认为 256。
width number <optional>
256 数组的宽度,默认为 256。
channel number <optional>
3 数组的通道数,默认为 3。
Source:
Returns:
返回一个 ImgArray 对象,表示创建的 ones 数组。
Type
ImgArray

(static) random(options) → {ImgArray}

random,创建一个指定尺寸的,指定范围的均值分布的数组。
Parameters:
Name Type Description
options Object 创建数组的选项。
Properties
Name Type Attributes Default Description
height number <optional>
256 数组的高度,默认为 256。
width number <optional>
256 数组的宽度,默认为 256。
channel number <optional>
3 数组的通道数,默认为 3。
vmin number <optional>
0 数组元素的最小值,默认为 0。
vmax number <optional>
255 数组元素的最大值,默认为 255。
Source:
Returns:
返回一个 ImgArray 对象,表示创建的随机数组。
Type
ImgArray

(static) zeros(options) → {ImgArray}

zeros,创建一个指定尺寸的零数组。
Parameters:
Name Type Description
options Object 创建数组的选项。
Properties
Name Type Attributes Default Description
height number <optional>
256 数组的高度,默认为 256。
width number <optional>
256 数组的宽度,默认为 256。
channel number <optional>
3 数组的通道数,默认为 3。
Source:
Returns:
返回一个 ImgArray 对象,表示创建的零数组。
Type
ImgArray