Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. struct OBRAZ{
  8. int wiersze;
  9. int kolumny;
  10. int skala;
  11. int **piksel;
  12. };
  13.  
  14. void Zapis(struct OBRAZ *wpis){
  15. FILE *plik;
  16. int i,j;
  17. plik = fopen("obrazek.pgm","w");
  18. fprintf(plik,"P2\n");
  19. fprintf(plik,"%d %d\n",wpis->kolumny,wpis->wiersze);
  20. fprintf(plik,"%d\n",wpis->skala);
  21.  
  22. for(j=0;j<wpis->kolumny;j++){
  23. for(i=0;i<wpis->wiersze;i++){
  24. fprintf(plik, "%d ",wpis->piksel[j][i]);
  25. }
  26. fprintf(plik,"\n");
  27. }
  28.  
  29. }
  30.  
  31. struct OBRAZ Szum (struct OBRAZ dane){
  32. int i,j,los;
  33. srand(time(NULL));
  34. for (j=0; j<dane.wiersze; j++)
  35. {
  36. for (i=0; i<dane.kolumny; i++) {
  37. los=rand()%20;
  38. if (dane.piksel[j][i]+los>255) {
  39. dane.piksel[j][i]=dane.piksel[j][i]-los;
  40. }
  41. else dane.piksel[j][i]=dane.piksel[j][i]+los;
  42. }
  43. }
  44. return dane;
  45. }
  46.  
  47.  
  48.  
  49. struct OBRAZ Gradient(int k, int w, int s){
  50. struct OBRAZ temp;
  51. int i,j;
  52. temp.kolumny = k;
  53. temp.wiersze = w;
  54. temp.skala = s;
  55. temp.piksel = (int**)malloc(temp.wiersze*sizeof(int*));
  56. for(i=0;i<temp.kolumny;i++){
  57. temp.piksel[i] = (int*)malloc(temp.wiersze*sizeof(int));
  58. }
  59. for(j=0;j<temp.kolumny;j++){
  60. for(i=0;i<temp.wiersze;i++){
  61. temp.piksel[j][i] = i;
  62. }
  63. }
  64. return temp;
  65. }
  66.  
  67. struct OBRAZ *Wczytaj () {
  68. struct OBRAZ *obraz_we;
  69. char temp[100];
  70. FILE *wsk;
  71. int i, j;
  72. wsk=fopen("004.pgm", "r");
  73. fgets(temp,100,wsk);
  74. fgets(temp,100,wsk);
  75. obraz_we=(struct OBRAZ*)malloc(sizeof(struct OBRAZ));
  76. fscanf(wsk, "%d %d %d", &obraz_we->kolumny, &obraz_we->wiersze, &obraz_we->skala);
  77.  
  78.  
  79. obraz_we->piksel=(int**)calloc(obraz_we->kolumny, sizeof(int*));
  80. for (i=0; i<obraz_we->kolumny; i++) {
  81. obraz_we->piksel[i] = (int*)calloc(obraz_we->wiersze, sizeof(int));
  82. }
  83.  
  84.  
  85. for (j=0; j<obraz_we->kolumny; j++) {
  86. for (i=0; i<obraz_we->wiersze; i++)
  87. {
  88. fscanf(wsk, "%d", &obraz_we->piksel[j][i]);
  89. }
  90. }
  91. printf("W pliku jest %d kolumn, %d lini, a skala szarosci wynosi %d", obraz_we->kolumny, obraz_we->wiersze, obraz_we->skala);
  92. return obraz_we;
  93. }
  94. /*
  95. struct OBRAZ Negatyw (struct OBRAZ *dane) {
  96. int i, j;
  97. for (j=0; j<obraz_we->kolumny; j++) {
  98. for (i=0; i<obraz_we->wiersze; i++)
  99. {
  100. obraz_we->piksel[j][i]=255-obraz_we->piksel[j][i];
  101. }
  102. }
  103. */
  104.  
  105. int main(){
  106.  
  107. struct OBRAZ grad;
  108. struct OBRAZ *obrazek;
  109. grad = Szum(Gradient(255,255,255));
  110. obrazek = Wczytaj();
  111. Zapis(obrazek);
  112. system("pause");
  113.  
  114.  
  115. return 0;
  116.  
  117. }
  118.  
  119.  
  120. // miec napisane funkcje gradient, zaszumianie i zapis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement