-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimageprocessor.cpp
More file actions
50 lines (41 loc) · 1.45 KB
/
imageprocessor.cpp
File metadata and controls
50 lines (41 loc) · 1.45 KB
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
#include "imageprocessor.h"
cv::Mat ImageProcessor::applyBrightnessContrast(cv::Mat image, double alpha, int beta) {
cv::Mat result;
image.convertTo(result, -1, alpha, beta);
return result;
}
cv::Mat ImageProcessor::applyGaussianBlur(cv::Mat image, int kernelSize) {
if (kernelSize <= 0 || kernelSize % 2 == 0)
return image.clone();
cv::Mat result;
cv::GaussianBlur(image, result, cv::Size(kernelSize, kernelSize), 0);
return result;
}
cv::Mat ImageProcessor::applyThreshold(cv::Mat image, double threshValue) {
cv::Mat gray, binary;
if (image.channels() == 3)
cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
else
gray = image.clone();
cv::threshold(gray, binary, threshValue, 255, cv::THRESH_BINARY);
return binary;
}
cv::Mat ImageProcessor::addGaussianNoise(cv::Mat image, double stddev) {
if (stddev <= 0.0) return image.clone();
cv::Mat noise(image.size(), image.type());
cv::RNG rng(cv::getTickCount());
rng.fill(noise, cv::RNG::NORMAL, 0, stddev);
cv::Mat result;
cv::add(image, noise, result, cv::noArray(), image.type());
return result;
}
cv::Mat ImageProcessor::loadImage(const QString& path) {
cv::Mat image = cv::imread(path.toStdString(), cv::IMREAD_COLOR);
if (image.empty()) {
return cv::Mat();
}
return image;
}
bool ImageProcessor::saveImage(const cv::Mat& image, const QString& path) {
return cv::imwrite(path.toStdString(), image);
}