c++ - 如何将图像从彩色去饱和到黑白?
问题描述
我一直在使用我的代码来更改图像的颜色,但我不知道在嵌套的 for 循环中下一步该做什么?
到目前为止,我只有平均图像中每个像素位置的红色、绿色和蓝色像素值。
谁能帮助/建议我下一步该怎么做?
#include "desaturate.h"
void Desaturate(graphics::Image &image) {
// Returns the width and height of the image.
int GetWidth();
int GetHeight();
// Create variable
int red;
int green;
int blue;
// Gets the red, green or blue pixel value at an (x, y) pixel location.
int GetRed(int x, int y);
int GetGreen(int x, int y);
int GetBlue(int x, int y);
// Sets the red, green or blue pixel value at an (x, y) pixel location.
bool SetRed(int x, int y, int red);
bool SetGreen(int x, int y, int green);
bool SetBlue(int x, int y, int blue);
// Gets the width of the image.
int width = image.GetWidth();
// Gets the height of the image.
int height = image.GetHeight();
for (int i = 0; i < width; i++) {
for (int j = 0; i < height; j++) {
int average = (red + green + blue) / 3;
// What should I do next for this part?
}
}
解决方案
推荐阅读
- reactjs - 显示不良动画的材质 ui 工具提示
- django - django rest框架ImageField中的自定义验证错误消息
- nvidia-jetson - 无法在 Jetson Nano 4GB 上查看 IMX219-83,GStreamer-CRITICAL 错误
- google-app-engine - Github 操作问题与 main.yaml 文件在部署期间创建 .env 文件有关
- python - 标记字符串中的重复元素
- python-3.x - 使用 Python3 的 Web 应用程序在 Dockerized 时无法正常工作
- node.js - 如何从 API 道具响应中获取键值
- shell - 如何在文件中转换为日期格式(DD MMM YYYY)而不将输出写入新文件
- python - Dash/Plotly:带有动画图的实时图,在同一图上添加其他线
- python - 如何在 pandas 中将日期格式从 01-Mar-19 更改为 2019-03-01?