Created
April 20, 2014 17:38
-
-
Save swimmi/11120096 to your computer and use it in GitHub Desktop.
Transform a RGB image into gray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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