-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGelAnalyzer.cpp
More file actions
79 lines (57 loc) · 2 KB
/
Copy pathGelAnalyzer.cpp
File metadata and controls
79 lines (57 loc) · 2 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
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
#include "GelAnalyzer.h"
GelAnalyzer::GelAnalyzer() {}
GelAnalyzer::~GelAnalyzer(){}
std::vector<std::vector<double>> GelAnalyzer::plotLanes(
cv::Mat image,
std::vector<cv::Rect> roi_list,
double globalMin,
double globalMax)
{
// 转为单通道灰度图
if (image.channels() > 1) {
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
}
if (uncalibratedOD && image.depth() != CV_8U) {
cv::normalize(image, image, 0, 255, cv::NORM_MINMAX, CV_8U);
}
if (invertPeaks) {
// 只有 8位图 反相才有 255-x 的物理意义
if (image.depth() == CV_8U) {
cv::bitwise_not(image, image);
}
}
std::vector<std::vector<double>> allProfiles;
// 重置全局 OD 极值
if (uncalibratedOD) {
odMin = std::numeric_limits<double>::max();
odMax = -std::numeric_limits<double>::max();
}
for (cv::Rect cvRoi : roi_list) {
bool averageHorizontally = (cvRoi.height > cvRoi.width);
ProfilePlot plot(image, cvRoi, averageHorizontally);
std::vector<double> profile = plot.getProfile();
if (profile.empty()) continue;
if (uncalibratedOD) {
profile = calculateOD(profile);
}
auto minmax = std::minmax_element(profile.begin(), profile.end());
if (*minmax.first < globalMin) globalMin = *minmax.first;
if (*minmax.second > globalMax) globalMax = *minmax.second;
allProfiles.push_back(profile);
}
if (allProfiles.empty()) {
return allProfiles;
}
return allProfiles;
}
std::vector<double> GelAnalyzer::calculateOD(const std::vector<double>& profile) {
std::vector<double> odProfile(profile.size());
for (size_t i = 0; i < profile.size(); ++i) {
double pixelValue = std::min(profile[i], 254.999);
double v = 0.434294481 * std::log(255.0 / (255.0 - pixelValue));
if (v < odMin) odMin = v;
if (v > odMax) odMax = v;
odProfile[i] = v;
}
return odProfile;
}