-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugUtilities.cpp
47 lines (45 loc) · 1.24 KB
/
DebugUtilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "DebugUtilities.h"
#include <fstream>
#include <iostream>
using namespace std;
/**
* Writes the image histogram to a csv file
* 0, sum of intensities at level 0
* 1, sum of intensities at level 1
* 2, sum of intensities at level 2
* 3, sum of intensities at level 3
* .
* .
* .
* 255, sum of intensities at level 255
*
* @param img - the image
* @param filePath - the path that you want to write to
* @return true if successful.
*/
bool DebugUtilities::writeHistogramDataToCSVFile(ImageGrayscale8Bit img, string filePath) {
int x;
ofstream outputFile(filePath);
if(!outputFile.is_open()){
cout << "unable to open output file" << endl;
return false;
}
//each index represents an intensity value.
//the number stored at the index represents the how many pixels are that intensity
unsigned int a[256];
for(int i = 0; i < 256; i++)
a[i] = 0;
//build histogram
for(int i = 0; i < img.size(); i++){
unsigned char intensity = img.getIntensity(i);
int val = a[intensity];
val++;
a[intensity] = val;
}
//write to csv file
for(int i = 0; i < 256; i++) {
outputFile << i << "," << a[i] << endl;
}
outputFile.close();
return true;
}