Skip to content

Instantly share code, notes, and snippets.

@swimmi
Created April 20, 2014 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swimmi/11120096 to your computer and use it in GitHub Desktop.
Save swimmi/11120096 to your computer and use it in GitHub Desktop.
Transform a RGB image into gray
#include <fstream>
#include <iostream>
using namespace std;
//Transform a RGB image into gray.
int main()
{
//ifstream cin("image_transformation.txt");
int x,y;
int index=1;
while(cin>>x>>y)
{
if(x==0)
break;
int z=x*y;
int c[z][3];
for(int i=0;i<3;i++)
{
int num;
for(int j=0;j<x*y;j++)
{
cin>>num;
c[j][i]=num;
}
}
cout<<"Case "<<index<<":"<<endl;
index++;
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
int sum=0;
for(int k=0;k<3;k++)
sum+=c[i*y+j][k];
printf("%d",sum/3);
if(j!=y-1) cout<<",";
}
cout<<endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment