将任何彩色PPM图像转换为只有8种颜色的彩色图像
Converting any colored PPM image into a colored image with only 8 colors
我需要一个算法来将ppm格式的任何彩色图像转换为C++中的8种颜色。我尝试了这个代码,但我一直面临>>
和<<
运算符的错误:
#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream in;
in.open("football.ppm");
ofstream out("football8color.ppm");
string header;
int cols, rows,colors;
int r, g, b;
in >> header >> cols >> rows >> colors;
out << header << endl;
out<< cols<< " " << rows <<endl;
out<< colors<< endl;
for ( int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++){
in>> r >> g >> b;
}
out <<endl;
}
in.close();
out.close();
return 0 ;
}
我得到这些错误:
4 IntelliSense: no operator "<<" matches these operands c:usersatiyehdocumentsvisual studio 2010projectsmm ass 2mm ass 2mm ass 2.cpp 18
3 IntelliSense: no operator ">>" matches these operands c:usersatiyehdocumentsvisual studio 2010projectsmm ass 2mm ass 2mm ass 2.cpp 17
Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:usersatiyehdocumentsvisual studio 2010projectsmm ass 2mm ass 2mm ass 2.cpp 16
Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion) c:usersatiyehdocumentsvisual studio 2010projectsmm ass 2mm ass 2mm ass 2.cpp 15
对于算法,您应该查找"颜色量化"。如果你想让它看起来好看,你应该查找抖动技术,比如Floyd-Stienberg抖动。
相关文章:
- 如何使用DP绘制具有n种不同颜色的r x r字段,而无需在同一行使用相同的颜色
- Open_gl 1 种颜色着色器
- 存储多种颜色并从一种颜色切换到另一种颜色
- OpenCV将一种颜色转换为任何其他颜色
- 如何在扩展 BMP 的 IMG 中找到 16 种最常见的颜色
- 将 32bpp 位图转换为 256 种颜色
- 从一种颜色插值到另一种颜色
- 如何在 2d 颜色选取器中创建返回 2 种颜色之间的颜色的函数
- 将任何彩色PPM图像转换为只有8种颜色的彩色图像
- C++图像库 - 找到一种颜色的像素并使它们变白,其他一切都变黑
- OpenGL在更改RGBA颜色后绘制16种颜色
- cmd我如何使用24种颜色
- 在给定前景色和背景色的情况下,我如何计算第三种颜色
- OpenCV将一种颜色转换为另一种颜色
- QListView具有两种不同颜色的行背景
- 如何在顶点缓冲区中以另一种颜色绘制顶点
- 两种颜色相似度的量化方法
- CreateCompatibleDC的结果只有两种颜色
- Qt GLSL纹理仅显示一种颜色
- 从一种颜色到另一种颜色的插值