Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- bool czyKontrastuje(int glownyPixel, int lewyPixel, int gornyPixel, int dolnyPixel, int prawyPixel) {
- bool czyLewyPixelKontrastuje = abs(glownyPixel - lewyPixel) > 128 && lewyPixel > -1;
- bool czyPrawyPixelKontrastuje = abs(glownyPixel - prawyPixel) > 128 && prawyPixel > -1;
- bool czyDolnyPixelKontrastuje = abs(glownyPixel - dolnyPixel) > 128 && dolnyPixel > -1;
- bool czyGornyPixelKontrastuje = abs(glownyPixel - gornyPixel) > 128 && gornyPixel > -1;
- return czyLewyPixelKontrastuje || czyPrawyPixelKontrastuje || czyGornyPixelKontrastuje || czyDolnyPixelKontrastuje;
- }
- int main () {
- fstream plik;
- ofstream zapis;
- plik.open("dane.txt");
- int liczba;
- int matrix[200][320];
- int wiersz = 0;
- int licznikPixeliKontrastujacych = 0;
- while(!plik.eof()) {
- for(int i=0; i<320; i++) {
- plik >> liczba;
- matrix[wiersz][i] = liczba;
- }
- wiersz++;
- }
- for(int i=0; i<200; i++) { // [][]
- for(int j=0; j<320; j++) { // ---------
- int glownyPixel = matrix[i][j]; // [][] | [199][319]| [199][320]
- int lewyPixel = matrix[i][j-1]; // ---------
- int prawyPixel = matrix[i][j+1];// [200][319]
- int gornyPixel = matrix[i-1][j];
- int dolnyPixel = matrix[i+1][j];
- if(i-1 < 0) {
- gornyPixel = -1;
- }
- if(j-1 < 0) {
- lewyPixel = -1;
- }
- if(j+1 > 319) {
- prawyPixel = -1;
- }
- if(i+1 > 199) {
- dolnyPixel = -1;
- }
- if(czyKontrastuje(glownyPixel, lewyPixel, gornyPixel, dolnyPixel, prawyPixel) == true) {
- licznikPixeliKontrastujacych++;
- }
- }
- }
- cout << licznikPixeliKontrastujacych << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement