-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
84 lines (70 loc) · 2.62 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* file: main.cpp
* purpose: Implements a small executable which takes in an image filename from
* and applies a custom CLAHE algorithm to it before showing the new
* image with OpenCV's HighGUI.
*/
#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <chrono>
#include "clahe.hpp"
#include "utility.hpp"
static void unityMapping(ImageHistogram const & histogram, LookupTable * outputTable)
{
for (auto i = 0u; i < outputTable->size(); ++i)
{
outputTable->operator[](i) = static_cast<uint8_t >(i);
}
}
int main(int argc, char ** argv)
{
if (argc < 2)
{
std::cerr << "Must provide an input image." << std::endl;
return 1;
}
auto image = cv::imread(argv[1], cv::IMREAD_GRAYSCALE);
cv::Mat processedImage;
int retVal(-1);
auto start = std::chrono::high_resolution_clock::now();
if (argc == 3)
{
retVal = clahe(image, processedImage, atoi(argv[2]));
}
else
{
// In order to specify your own mapping function:
// retVal = clahe(image, processedImage, unityMapping);
retVal = clahe(image, processedImage);
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << "Duration (us): " << duration.count() << std::endl;
std::string const windowNameNewImage("Histogram Equalized Image");
cv::namedWindow(windowNameNewImage, cv::WINDOW_NORMAL);
cv::imshow(windowNameNewImage, processedImage);
// Get the histogram of the original image
ImageHistogram originalHistogram;
generateGrayscaleHistogram(image, originalHistogram);
cv::Mat originalHistogramImage;
createHistogramPlot(originalHistogram, 512, 512, originalHistogramImage);
// Display it
std::string const windowOriginalHistogram("Original Histogram");
cv::namedWindow(windowOriginalHistogram, cv::WINDOW_NORMAL);
cv::imshow(windowOriginalHistogram, originalHistogramImage);
// Get the histogram of the new image
ImageHistogram claheHistogram;
generateGrayscaleHistogram(processedImage, claheHistogram);
cv::Mat claheHistImage;
createHistogramPlot(claheHistogram, 512, 512, claheHistImage);
// Display it
std::string const windowNewHistogram("New Histogram");
cv::namedWindow(windowNewHistogram, cv::WINDOW_NORMAL);
cv::imshow(windowNewHistogram, claheHistImage);
cv::waitKey(0);
cv::destroyAllWindows();
cv::imwrite("output-clahe.jpg", processedImage);
std::cout << "clahe returned with " << retVal << std::endl;
return 0;
}