Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- else if(operation=="region")
- {
- int suma=0;
- CImg<unsigned char> image(argv[1]);
- CImg<unsigned char> visu(image.width(),image.height(),1,3,0);
- int tablica[image.width()][image.height()];
- for(int i=0;i<image.width();i++)
- {
- for(int j=0;j<image.height();j++)
- tablica[i][j]=0;
- }
- int n=image.height()*image.width();
- int tmp=0;
- int t[255],t2[255],t3[255];
- int choice;
- cout<<"Enter '1' if you want to enter values of region of your choice. Enter 2 if you want to divide picture into few regions."<<endl;
- cin>>choice;
- switch(choice)
- {
- case 1:
- int xd,yd;
- cout<<endl<<"Enter x value of your seed";
- cin>>xd;
- cout<<"Enter y value of your seed ";
- cin>>yd;
- int sred=image(xd,yd,0);
- float kolor;
- do
- {
- cout<<endl<<"In what color I should create region?"<<endl;
- cin>>kolor;
- }while(kolor>255&&kolor<0);
- WHOLE_IMAGE_WITHOUT_BORDERS
- {
- if(image(x,y,z)<(sred+20) && image(x,y,z)>(sred-20))
- {tablica[x][y]=1;}
- }
- tablica[xd][yd]=2;
- for(int m;m<image.height();m++)
- {
- for(int z=0;z<image.width();z++)
- {
- for(int k=0;k<image.height();k++)
- {
- for(int i=-1;i<2;i++)for(int j=-1;j<2;j++)
- {
- if(tablica[k][z]==1){if(tablica[k+i][z+j]==2){tablica[k][z]=2;}}
- }
- }
- }
- }
- for(int x=0;x<image.width();x++)
- {
- for(int y=0;y<image.height();y++)
- { for(int z=0;z<spectrum;z++){
- if(tablica[x][y]==2) {image(x,y,z)=kolor; visu(x,y,z)=60;}
- }}}
- break;
- case 2:
- for(int k=0;k<4;k++)
- {
- for(int i=0;i<255;i++)
- {
- t[i]=0;
- t2[i]=0;
- t3[i]=0;
- }
- for(int x=0;x<image.width();x++)for(int y=0;y<image.height();y++)
- { if(tablica[x][y]==0){
- tmp=image(x,y,0);
- t[tmp]++;}
- }
- tmp=0;
- for(int x=0;x<image.width();x++)for(int y=0;y<image.height();y++)
- {if(tablica[x][y]==0){
- tmp=image(x,y,1);
- t2[tmp]++;}
- }
- tmp=0;
- for(int x=0;x<image.width();x++)for(int y=0;y<image.height();y++)
- {if(tablica[x][y]==0){
- tmp=image(x,y,2);
- t3[tmp]++;}
- }
- double br, bg, bb;
- for(int i=0; i<255; i++)
- {
- suma = suma + (i*t[i]);
- }
- br=suma/n;
- suma=0;
- for(int i=0; i<255; i++)
- {
- suma = suma + (i*t2[i]);
- }
- bg=suma/n;
- suma=0;
- for(int i=0; i<255; i++)
- {
- suma = suma + (i*t3[i]);
- }
- bb=suma/n;
- suma=0;
- suma=0;
- long double vr, vg, vb;
- for(int i=0; i<255; i++)
- {
- suma = suma + (((i-br)*(i-br))*t[i]);
- }
- vr=(suma/n);
- suma=0;
- for(int i=0; i<255; i++)
- {
- suma = suma + (((i-bg)*(i-bg))*t[i]);
- }
- vg=(suma/n);
- suma=0;
- for(int i=0; i<255; i++)
- {
- suma = suma + (((i-bb)*(i-bb))*t[i]);
- }
- vb=(suma/n);
- suma=0;
- long double sdr,sdg,sdb;
- sdr=sqrt(vr);
- sdg=sqrt(vg);
- sdb=sqrt(vb);
- cout<<br<<endl;
- cout<<sdr<<endl;
- cout<<vr<<endl;
- cout<<br+(sdr/4)<<" "<<br-(sdr/4)<<endl;
- WHOLE_IMAGE_WITHOUT_BORDERS
- {
- if(image(x,y,z)<(br+(sdr/4)) && image(x,y,z)>(br-(sdr/4)))
- { tablica[x][y]=1;
- visu(x,y,z)=60;
- switch(k)
- {
- case 0: visu(x,y,z)=50; break;
- case 1: visu(x,y,z)=204; break;
- case 2: visu(x,y,z)=153; break;
- case 3: visu(x,y,z)=102; break;
- }
- for(int i=-1;i<2;i++)for(int j=-1;j<2;j++)
- {
- if(image(x+i,y+j,z)>(br+(sdr/4)) && (i!=0 || j!=0)) {visu(x+i,y+j,z)=255; tablica[x+1][y+j]=1; }
- if(image(x+i,y+j,z)<(br-(sdr/4)) && (i!=0 || j!=0)) {visu(x+i,y+j,z)=255; tablica[x+1][y+j]=1;}
- }
- }
- /* if(image(x,y,z)<(br+(sdr/4)) && image(x,y,z)>(br-(sdr/4)))
- { tablica[x][y]=1;
- for(int i=-1;i<2;i++)for(int j=-1;j<2;j++)
- {
- if(image(x+i,y+j,z)>(br+(sdr/4)) && (i!=0 || j!=0)) {image(x+i,y+j,z)=0; tablica[x+1][y+j]=1; }
- if(image(x+i,y+j,z)<(br-(sdr/4)) && (i!=0 || j!=0)) {image(x+i,y+j,z)=0; tablica[x+1][y+j]=1;}
- }
- } */
- }
- } break;
- default: cout<<"Wrong instruction! ";
- break;}
- CImgDisplay obrazek(visu,"Click a point");
- CImgDisplay obrazek2(image,"Click a point");
- system("PAUSE");
- }
Add Comment
Please, Sign In to add comment