Advertisement
Guest User

HiBoost

a guest
May 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. ade dua satu hiboos, satu minmax
  2.  
  3. 1) void hiboos(char *fileName, Data data){
  4.     ifstream tifFile;
  5.     ofstream lowPassFile, highPassFile, highBoostFile, medianFile;
  6.     double pixelTemp;
  7.     unsigned short pixel, min, max;
  8.  
  9.     tifFile.open(fileName, ios::binary);
  10.     tifFile.seekg(data.firstData, ios::beg);
  11.     for(int i = 0; i < data.length; i++){
  12.         for(int j = 0; j < data.width; j++){
  13.             tifFile.read((char*) &rawData[i][j],1);
  14.         }
  15.     }
  16.     tifFile.close();
  17.  
  18.     int c;
  19.  
  20.     cout << "Enter value c: ";
  21.     cin >> c;
  22.    
  23.  // High Boost Filtering
  24.     highBoostFile.open("highBoost.raw", ios::binary);
  25.  
  26.     for(int row=0; row<data.length; row++){
  27.         for(int col=0; col<data.width; col++){
  28.             // Inside Border Pixel
  29.             if(row >= 1 && row <= (data.length - 2) && col >= 1 && col<= (data.width - 2)){
  30.                 // Compute
  31.                 pixelTemp = ((rawData[row - 1][col - 1] * -1) +
  32.                              (rawData[row - 1][col    ] * -1) +
  33.                              (rawData[row - 1][col + 1] * -1) +
  34.                              (rawData[row    ][col - 1] * -1) +
  35.                              (rawData[row    ][col    ] * c) +
  36.                              (rawData[row    ][col + 1] * -1) +
  37.                              (rawData[row + 1][col - 1] * -1) +
  38.                              (rawData[row + 1][col    ] * -1) +
  39.                              (rawData[row + 1][col + 1] * -1)) / 9.0;
  40.  
  41.                 // Find 'min' and 'max'
  42.                 getMinMax(row, col, min, max);
  43.  
  44.                 // Compute Value for Mapping
  45.                 pixelTemp = ((pixelTemp + min) / (min + max)) * 255;
  46.  
  47.                 // Round-off
  48.                 pixel = roundOff(pixelTemp);
  49.             }
  50.  
  51.             // Border Pixel
  52.             else
  53.                 pixel = 0;
  54.  
  55.             highBoostFile.write(reinterpret_cast<char *>(&pixel), 1);
  56.         }
  57.     }
  58.     highBoostFile.close();
  59.  
  60.     cout << "High Boost files successfully created!\n";
  61. }
  62.  
  63. 2) void getMinMax(int row, int col, unsigned short &min, unsigned short &max){
  64.     min = max = rawData[row - 1][col - 1];
  65.  
  66.     for(int rowCount = row - 1; rowCount <= row + 1; rowCount++){
  67.         for (int colCount = col - 1; colCount <= col + 1; colCount++){
  68.             if(rawData[rowCount][colCount] < min)
  69.                 min = rawData[rowCount][colCount];
  70.  
  71.             else if(rawData[rowCount][colCount] > max)
  72.                 max = rawData[rowCount][colCount];
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement