Ai
1 Star 0 Fork 0

李明/imageidentification

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
componentsMethod.js 768 Bytes
一键复制 编辑 原始数据 按行查看 历史
李明 提交于 2025-06-16 21:09 +08:00 . [modify]更新内容
/**
* 将图像数据转换为指定通道的灰度图 [分量法]
* @param {NormalizeImageData} imageData - 图像数据对象,包含像素信息和操作方法
* @param {number} channel - 要灰化的通道索引 (0-2 分别对应 R/G/B)
* @throws {Error} 当通道索引无效时抛出错误
*/
export default function componentsMethod(imageData, channel) {
if (channel >= 0 && channel < 3) {
for (let row = 0; row < imageData.height; row++) {
for (let col = 0; col < imageData.width; col++) {
const gray = imageData.getSpecificPositionChannelData(
row,
col,
channel
);
imageData.setSpecificPositionData(row, col, gray);
}
}
} else {
throw new Error("Invalid channel");
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/usernameisregistered/imageidentification.git
git@gitee.com:usernameisregistered/imageidentification.git
usernameisregistered
imageidentification
imageidentification
master

搜索帮助