我需要为学校项目创建一个临时中值过滤器(背景减法)(基本上,选择数据集中出现最多的像素作为背景)。我收到了“数组大小未处理的异常错误”。另外,我不知道我是否正确这样做。我在编程方面很新奇。谢谢:))
const data = [{"id": 657, "name": "Amadeus Basin", "contenttype": "province"},
{"id": 1173, "name": "Amazonas Basin", "contenttype": "province"},
{"id": 373, "name": "American Samoa", "contenttype": "countries"},
{"id": 1, "name": "Samoa", "contenttype": "marine"},
{"id": 796, "name": "Amhara", "contenttype": "province"}];
const grouped = data.reduce((acc, item) => {
const found = acc.find(i => i.contenttype === item.contenttype);
const content = {id: item.id, name: item.name};
if(found) {
found.content.push(content);
} else {
acc.push({contenttype: item.contenttype, content: [content] })
}
return acc;
}, []);
console.log(grouped);
基本上,我想要做的是存储每张图片中像素的单个值并将它们存储到一个数组中,对它们应用中值函数,得到中值像素并输出它。