Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- struct OBRAZ{
- int wiersze;
- int kolumny;
- int skala;
- int **piksel;
- };
- void Zapis(struct OBRAZ *wpis){
- FILE *plik;
- int i,j;
- plik = fopen("obrazek.pgm","w");
- fprintf(plik,"P2\n");
- fprintf(plik,"%d %d\n",wpis->kolumny,wpis->wiersze);
- fprintf(plik,"%d\n",wpis->skala);
- for(j=0;j<wpis->kolumny;j++){
- for(i=0;i<wpis->wiersze;i++){
- fprintf(plik, "%d ",wpis->piksel[j][i]);
- }
- fprintf(plik,"\n");
- }
- }
- struct OBRAZ Szum (struct OBRAZ dane){
- int i,j,los;
- srand(time(NULL));
- for (j=0; j<dane.wiersze; j++)
- {
- for (i=0; i<dane.kolumny; i++) {
- los=rand()%20;
- if (dane.piksel[j][i]+los>255) {
- dane.piksel[j][i]=dane.piksel[j][i]-los;
- }
- else dane.piksel[j][i]=dane.piksel[j][i]+los;
- }
- }
- return dane;
- }
- struct OBRAZ Gradient(int k, int w, int s){
- struct OBRAZ temp;
- int i,j;
- temp.kolumny = k;
- temp.wiersze = w;
- temp.skala = s;
- temp.piksel = (int**)malloc(temp.wiersze*sizeof(int*));
- for(i=0;i<temp.kolumny;i++){
- temp.piksel[i] = (int*)malloc(temp.wiersze*sizeof(int));
- }
- for(j=0;j<temp.kolumny;j++){
- for(i=0;i<temp.wiersze;i++){
- temp.piksel[j][i] = i;
- }
- }
- return temp;
- }
- struct OBRAZ *Wczytaj () {
- struct OBRAZ *obraz_we;
- char temp[100];
- FILE *wsk;
- int i, j;
- wsk=fopen("004.pgm", "r");
- fgets(temp,100,wsk);
- fgets(temp,100,wsk);
- obraz_we=(struct OBRAZ*)malloc(sizeof(struct OBRAZ));
- fscanf(wsk, "%d %d %d", &obraz_we->kolumny, &obraz_we->wiersze, &obraz_we->skala);
- obraz_we->piksel=(int**)calloc(obraz_we->kolumny, sizeof(int*));
- for (i=0; i<obraz_we->kolumny; i++) {
- obraz_we->piksel[i] = (int*)calloc(obraz_we->wiersze, sizeof(int));
- }
- for (j=0; j<obraz_we->kolumny; j++) {
- for (i=0; i<obraz_we->wiersze; i++)
- {
- fscanf(wsk, "%d", &obraz_we->piksel[j][i]);
- }
- }
- printf("W pliku jest %d kolumn, %d lini, a skala szarosci wynosi %d", obraz_we->kolumny, obraz_we->wiersze, obraz_we->skala);
- return obraz_we;
- }
- /*
- struct OBRAZ Negatyw (struct OBRAZ *dane) {
- int i, j;
- for (j=0; j<obraz_we->kolumny; j++) {
- for (i=0; i<obraz_we->wiersze; i++)
- {
- obraz_we->piksel[j][i]=255-obraz_we->piksel[j][i];
- }
- }
- */
- int main(){
- struct OBRAZ grad;
- struct OBRAZ *obrazek;
- grad = Szum(Gradient(255,255,255));
- obrazek = Wczytaj();
- Zapis(obrazek);
- system("pause");
- return 0;
- }
- // miec napisane funkcje gradient, zaszumianie i zapis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement