Class: Img

Img(options) → {Img}

ImgArray类是一个用于表示图像的类,继承自ImgArray类。 Img 继承自ImgArray类,虽然支持ImgArray的所有方法,但是不保证运行正确, 更主要的是用于图像的存取和简单变换,Img 本身就是图像 Img的图像类型只支持RGBA排列一种

Constructor

new Img(options) → {Img}

创建一个Img对象。
Parameters:
Name Type Description
options Object 可选参数对象。
Properties
Name Type Attributes Default Description
height number <optional>
256 图像的高度。
width number <optional>
256 图像的宽度。
lazy boolean <optional>
false 是否延迟创建图像数据。
Source:
Returns:
返回一个Img对象。
Type
Img

Extends

Members

buffer :ArrayBuffer

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

bytesize :number

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

dtypes :Object

dtypes 是一个静态对象,对于存储数组数据的类型与JS TypedArray的映射关系。
Type:
  • Object
Overrides:
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
Overrides:
Source:

shape :Shape

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

size :number

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

typedarray :TypedArray

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

Methods

RGBtoYCbCr() → {Img}

RGBtoYCbCr,将RGB图像转换为YCbCr图像
Source:
Returns:
- 生成的图像对象。
Type
Img

YCbCrtoRGB() → {Img}

YCbCrtoRGB,将YCbCr图像转换为RGB图像
Source:
Returns:
- 生成的图像对象。
Type
Img

abs() → {ImgArray}

abs,对数组中的每个元素计算绝对值。返回一个与原数组尺寸相同的新数组,每个元素为原数组元素的绝对值。
Overrides:
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。
Overrides:
Source:
Returns:
返回自适应阈值分割后的图像数据对象。
Type
ImgArray

add(otherArrayOrValue) → {ImgArray|null}

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

apply_along_channel(func) → {ImgArray}

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

applycolormap() → {Img}

applycolormap,将图像转灰度后,为灰度图像添加warm to cool的通过添加伪彩色warm to cool cool to warm from vtkjs colormaps.json 颜色映射的计算来自于vtkjs colormaps.json中的定义
Source:
Returns:
- 生成的图像对象。
Type
Img

astype(dtypeopt) → {ImgArray}

astype,将数组的元素类型转换为指定的类型,要注意不同类型数值表示范围差异可能带来的精度损失!
Parameters:
Name Type Attributes Default Description
dtype string <optional>
'float32' 要转换的元素类型,变量ImgArray.dtypenames里的所有类型,如 'float32' , 'uint8'等。
Overrides:
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`。
Overrides:
Source:
Returns:
返回一个新的图像数据对象,应用了平均值池化。
Type
ImgArray

bitplane(cidx, bitnum) → {Img}

bitplane,计算比特面,cidx取哪个通道,bitnum取哪个比特位,返回值是0、1的数组Imgarray对象
Parameters:
Name Type Description
cidx number 取哪个通道,取值0~3。
bitnum number 取哪个比特位,取值0~7。
Source:
Returns:
- 生成的图像对象。
Type
Img

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 黑帽运算中填充区域的值,默认为
Overrides:
Source:
Returns:
返回黑帽运算后的图像数据对象。
Type
ImgArray

canny() → {ImgArray}

canny,应用 Canny 算子。对图像进行边缘检测
Overrides:
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 的邻域。
Overrides:
Source:
Returns:
返回包含元胞自动机特征的图像数据对象。
Type
ImgArray

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

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

chw2hwc() → {ImgArray}

chw2hwc,将图像或数组的形状从 CHW 转换为 HWC 格式。 hwc2chw的逆操作,hwc2chw和chw2hwc都是transpose的简单化
Overrides:
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
Overrides:
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。
Overrides:
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
Overrides:
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含卷积运算后的数据。
Type
ImgArray

copy() → {ImgArray}

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

cossimdist(v2opt) → {ImgArray}

cossimdist,计算数组在通道方向与一个向量的余弦距离。
Parameters:
Name Type Attributes Default Description
v2 Array.<number> <optional>
[3, 4, 5] 用于计算距离的向量。
Overrides:
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。
Overrides:
Source:
Returns:
返回膨胀后的图像数据对象。
Type
ImgArray

dist(v2opt) → {ImgArray}

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

div(otherArrayOrValue) → {ImgArray|null}

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

drawbox(xopt, yopt, wopt, hopt, coloropt, linewidthopt, fillopt, fillcoloropt) → {Img}

drawbox,在图像上画一个指定大小的矩形
Parameters:
Name Type Attributes Default Description
x number <optional>
50 矩形左上角的x坐标,默认为50。
y number <optional>
50 矩形左上角的y坐标,默认为50。
w number <optional>
50 矩形的宽度,默认为50。
h number <optional>
50 矩形的高度,默认为50。
color string <optional>
'#000000' 矩形的颜色,默认为'#000000'。
linewidth number <optional>
2 矩形的线宽,默认为2。
fill boolean <optional>
false 是否填充矩
fillcolor string <optional>
'#000000' 填充的颜色,默认为'#000000'。
Source:
Returns:
- 生成的图像对象。
Type
Img

drawtext(xopt, yopt, textopt, coloropt, linewidthopt, fontSizeopt) → {Img}

drawtext,在图像上绘制文字
Parameters:
Name Type Attributes Default Description
x number <optional>
50 文字的x坐标,默认为50。
y number <optional>
50 文字的y坐标,默认为50。
text string <optional>
'Hello' 要绘制的文字,默认为'Hello'。
color string <optional>
'red' 文字的颜色,默认为'red'。
linewidth number <optional>
2 文字的线宽,默认为2。
fontSize number <optional>
20 文字的字体大小,默认为20。
Source:
Returns:
- 生成的图像对象。
Type
Img

dsplit(…channels) → {ImgArray}

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

dstack(…imgars) → {ImgArray|undefined}

dstack,将多个数组沿通道堆叠,数组的宽高必须要相同
Parameters:
Name Type Attributes Description
imgars ImgArray | ImgArray <repeatable>
一个或多个数组
Overrides:
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]
Overrides:
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。
Overrides:
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。
Overrides:
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 要填充的通道索引,可以是一个数值,也可以是一个数组,表示对多个通道进行填充
Overrides:
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,在宽度轴上,进行左右翻转
Overrides:
Source:
Returns:
水平翻转后的结果
Type
ImgArray

flipud() → {ImgArray}

flipud, 在高度轴上,进行上下翻转
Overrides:
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`。
Overrides:
Source:
Returns:
返回一个新的图像数据对象,应用了高斯模糊。
Type
ImgArray

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

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

getpixel(x, y) → {Uint8ClampedArray(4)}

getpixel,获取图像的像素值
Parameters:
Name Type Description
x number 像素的x坐标,横坐标
y number 像素的y坐标,纵坐标
Source:
Returns:
rgba,范围为0~255
Type
Uint8ClampedArray(4)

globalminmax() → {Object}

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

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

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

hist(channelopt) → {Uint32Array|Array.<Uint32Array>}

hist,获取直方图。
Parameters:
Name Type Attributes Default Description
channel number <optional>
3 通道数。
Source:
Returns:
- 生成的直方图。
Type
Uint32Array | Array.<Uint32Array>

hstack(…imgars) → {ImgArray}

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

hwc2chw() → {ImgArray}

hwc2chw,用于将hxwxc转为cxhxw的方法,返回一个排列为cxhxw的一维float32数组
Overrides:
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维度的索引
Overrides:
Source:
Returns:
- 元素在数组内的真实索引值
Type
number

initarray() → {ImgArray}

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

issamech(bimgarr) → {Boolean}

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

issamehw(bimgarr) → {Boolean}

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

issameshape(bimgarr) → {Boolean}

issameshape,两数组形状是否相同
Parameters:
Name Type Description
bimgarr ImgArray 另一个数组
Overrides:
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'(余弦相似度)。
Overrides:
Source:
Returns:
返回两个值: - `newcenters`:更新后的聚类中心。 - `clusterresult`:一个 ImgArray 对象,表示每个像素的聚类结果。
Type
Array

laplacian(sizeopt) → {ImgArray}

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

lbp() → {ImgArray}

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

max(ischannelopt) → {number|ImgArray}

max,计算最大值,膨胀,最大值池化
Parameters:
Name Type Attributes Default Description
ischannel boolean <optional>
false 当ischannel为True时,沿通道计算最大值,否则计算全局最大值
Overrides:
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`。
Overrides:
Source:
Returns:
返回一个新的图像数据对象,应用了最大值池化。
Type
ImgArray

mean(ischannelopt) → {number|ImgArray}

mean,计算均值
Parameters:
Name Type Attributes Default Description
ischannel boolean <optional>
false 当ischannel为True时,沿通道计算均值,否则计算全局均值
Overrides:
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
Overrides:
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。
Overrides:
Source:
Returns:
返回形态学梯度后的图像数据对象。
Type
ImgArray

min(ischannelopt) → {number|ImgArray}

min,计算最小值,腐蚀,最小值池化
Parameters:
Name Type Attributes Default Description
ischannel boolean <optional>
false 当ischannel为True时,沿通道计算最小值,否则计算全局最小值
Overrides:
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`。
Overrides:
Source:
Returns:
返回一个新的图像数据对象,应用了最小值池化。
Type
ImgArray

mul(otherArrayOrValue) → {ImgArray|null}

mul,数组乘法,支持常数或数组
Parameters:
Name Type Description
otherArrayOrValue ImgArray | number 与当前数组尺寸相同,或者为一个常数
Overrides:
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
Overrides:
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含邻域展开后的数据。
Type
ImgArray

opacity(valueopt) → {Img}

opacity,设置图像不透明度,越大越不透明,取值0~255
Parameters:
Name Type Attributes Default Description
value number <optional>
255 不透明度的值,默认为255。
Source:
Returns:
- 生成的图像对象。
Type
Img

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。
Overrides:
Source:
Returns:
返回开运算后的图像数据对象。
Type
ImgArray

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

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

opposite() → {ImgArray}

opposite,取反,即每个元素取负
Overrides:
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
Overrides:
Source:
Returns:
返回一个新的 `ImgArray` 实例,包含填充后的数据。
Type
ImgArray

pow(value) → {ImgArray}

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

prewittx() → {ImgArray}

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

prewittxy() → {ImgArray}

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

prewitty() → {ImgArray}

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

print()

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

relu(valueopt) → {ImgArray}

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

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

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

resize(heightopt, widthopt) → {Img}

resize,将图像resize到指定大小
Parameters:
Name Type Attributes Default Description
height number <optional>
256 输出图像的高度,默认为256。
width number <optional>
256 输出图像的宽度,默认为256。
Source:
Returns:
- 生成的图像对象。
Type
Img

rolllr(dxopt) → {ImgArray}

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

rollud(dyopt) → {ImgArray}

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

rotate(degopt) → {Img}

rotate,将图像旋转deg角度
Parameters:
Name Type Attributes Default Description
deg number <optional>
45 旋转角度,默认为45度。
Overrides:
Source:
Returns:
- 生成的图像对象。
Type
Img

scale(scale)

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

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

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

setpixel(x, y, rgbaopt)

setpixel,设置图像的像素值
Parameters:
Name Type Attributes Default Description
x number 像素的x坐标,横坐标
y number 像素的y坐标,纵坐标
rgba Array.<number> <optional>
[0, 0, 0, 255] ,元素值的范围要为0~255
Source:

sharrx() → {ImgArray}

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

sharrxy() → {ImgArray}

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

sharry() → {ImgArray}

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

show(casopt) → {Img}

show,向网页中插入图像
Parameters:
Name Type Attributes Default Description
cas HTMLCanvasElement <optional>
null 要插入的canvas元素,默认为null。
Overrides:
Source:
Returns:
- 生成的图像对象。
Type
Img

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

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

sobelx() → {ImgArray}

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

sobelxy() → {ImgArray}

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

sobely() → {ImgArray}

sobely,对图像应用 Sobel 算子,计算图像在 Y 方向上的梯度。
Overrides:
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
Overrides:
Source:
Returns:
区间变换结果
Type
ImgArray

square() → {ImgArray}

square,计算数组中每个元素的平方。
Overrides:
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
Overrides:
Source:
Returns:
拉伸后的结果
Type
ImgArray

structure(pattern, fillvalueopt) → {ImgArray}

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

sub(otherArrayOrValue) → {ImgArray|null}

sub,数组减法,支持常数或数组
Parameters:
Name Type Description
otherArrayOrValue ImgArray | number 与当前数组尺寸相同,或者为一个常数
Overrides:
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
Overrides:
Source:
Returns:
阈值处理结果
Type
ImgArray

toString() → {string}

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

toarray(droptransopt) → {ImgArray}

toarray,将图像转为数组。
Parameters:
Name Type Attributes Default Description
droptrans boolean <optional>
true 是否丢弃通道信息。
Source:
Returns:
- 生成的数组对象。
Type
ImgArray

tocanvas(canvasele, isfullopt)

tocanvas,将图像转为canvas标签元素在网页中展示出来。
Parameters:
Name Type Attributes Default Description
canvasele HTMLCanvasElement canvas标签元素。
isfull boolean <optional>
false 是否使canvas适配图像。
Source:

tofile(nameopt)

tofile,将图像保存为文件。
Parameters:
Name Type Attributes Default Description
name string <optional>
'download' 文件名。
Overrides:
Source:

toimg(imgele)

toimg,将图像转为img标签元素在网页中展示出来。
Parameters:
Name Type Description
imgele HTMLImageElement img标签元素。
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。
Overrides:
Source:
Returns:
返回顶帽运算后的图像数据对象。
Type
ImgArray

totensor(dtypeopt) → {ort.Tensor}

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

tourl() → {string}

tourl,将图像转为url。
Source:
Returns:
- url
Type
string

update()

update,更新图像数据到画布中,根据标志位进行数据和canvas同步。
Source:

vectorize(func) → {ImgArray}

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

vectorizemath() → {ImgArray}

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

vstack(…imgarrs) → {ImgArray}

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

(static) fromarray(imgarray) → {Img|null}

fromarray,将 ImgArray 对象转换为 Img 对象。 该方法支持灰度图 (channel = 1)、RGB 图 (channel = 3)、RGBA 图 (channel = 4) 的转换。
Parameters:
Name Type Description
imgarray ImgArray 包含图像数据的 ImgArray 对象。
Properties
Name Type Description
height number 图像的高度。
width number 图像的宽度。
channel number 图像的通道数: - 1 表示灰度图。 - 3 表示 RGB 图。 - 4 表示 RGBA 图。
data Uint8Array 一维数组,存储图像的像素值。 - 若 `channel = 1`,数组长度为 height * width。 - 若 `channel = 3`,数组长度为 height * width * 3。 - 若 `channel = 4`,数组长度为 height * width * 4。
Source:
Throws:
如果 `imgarray.channel` 不是 1、3 或 4,则打印错误信息。
Type
Error
Returns:
- 转换后的 Img 对象(包含 RGBA 格式的像素值),或在不支持的通道数时返回 `null`。
Type
Img | null

(static) fromblob(blob) → {Promise.<Img>}

fromblob,从blob对象生成图像。
Parameters:
Name Type Description
blob Blob blob对象。
Source:
Returns:
- 生成的图像对象。
Type
Promise.<Img>

(static) fromcamera(hopt, wopt) → {Promise.<Img>}

fromcamera,从摄像头头获取一幅图像。
Parameters:
Name Type Attributes Default Description
h number <optional>
null 输出图像的高度。
w number <optional>
null 输出图像的宽度。
Source:
Returns:
- 生成的图像对象。
Type
Promise.<Img>

(static) fromcanvas(canvasele) → {Img}

fromcanvas,从canvas元素生成图像。
Parameters:
Name Type Description
canvasele HTMLCanvasElement canvas元素。
Source:
Returns:
- 生成的图像对象。
Type
Img

(static) fromfile(fileobj) → {Promise.<Img>}

fromfile,从本地文件生成图像。
Parameters:
Name Type Description
fileobj File 本地文件对象。
Source:
Returns:
- 生成的图像对象。
Type
Promise.<Img>

(static) fromimg(imgele) → {Img}

fromimg,从图像元素生成图像。
Parameters:
Name Type Description
imgele HTMLImageElement 图像元素。
Source:
Returns:
- 生成的图像对象。
Type
Img

(static) fromurl(imgurl) → {Promise.<Img>}

fromurl,从图像链接生成图像。
Parameters:
Name Type Description
imgurl string 图像链接。
Source:
Returns:
- 生成的图像对象,需要使用await。
Type
Promise.<Img>

(static) fromvideo(videoele, hopt, wopt) → {Img}

fromvideo,从视频流生成图像。
Parameters:
Name Type Attributes Default Description
videoele HTMLVideoElement 视频元素。
h number <optional>
null 输出图像的高度。
w number <optional>
null 输出图像的宽度。
Source:
Returns:
- 生成的图像对象。
Type
Img

(static) videotocanvas(canvasel)

videotocanvas,在canvas element 上显示画布。
Parameters:
Name Type Description
canvasel HTMLCanvasElement canvas元素。
Source: