histogram
This commit is contained in:
parent
d833cd8995
commit
f1e4e73833
@ -22,21 +22,56 @@ Histogram::~Histogram()
|
||||
delete L;
|
||||
}
|
||||
|
||||
void Histogram::generate(QImage* image)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
void Histogram::generate(QImage* image) {
|
||||
R->clear();
|
||||
G->clear();
|
||||
B->clear();
|
||||
L->clear();
|
||||
|
||||
if (image == nullptr) {
|
||||
qDebug() << "Invalid image provided.";
|
||||
return;
|
||||
}
|
||||
|
||||
for (int y = 0; y < image->height(); ++y) {
|
||||
for (int x = 0; x < image->width(); ++x) {
|
||||
QColor pixelColor = image->pixelColor(x, y);
|
||||
|
||||
R->insert(pixelColor.red(), R->value(pixelColor.red()) + 1);
|
||||
G->insert(pixelColor.green(), G->value(pixelColor.green()) + 1);
|
||||
B->insert(pixelColor.blue(), B->value(pixelColor.blue()) + 1);
|
||||
|
||||
int luminance = qRound(0.299 * pixelColor.red() + 0.587 * pixelColor.green() + 0.114 * pixelColor.blue());
|
||||
L->insert(luminance, L->value(luminance) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the maximal value of the histogram in the given channel */
|
||||
int Histogram::maximumValue(Channel selectedChannel = RGB)
|
||||
int Histogram::maximumValue(Channel selectedChannel)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
int maxVal = 0;
|
||||
|
||||
return 0;
|
||||
if (selectedChannel == RGB) {
|
||||
int maxR = maximumValue(RChannel);
|
||||
int maxG = maximumValue(GChannel);
|
||||
int maxB = maximumValue(BChannel);
|
||||
maxVal = std::max(maxR, std::max(maxG, maxB));
|
||||
}
|
||||
else {
|
||||
QHash<int, int>* hist = get(selectedChannel);
|
||||
|
||||
QHash<int, int>::const_iterator cit = hist->constBegin();
|
||||
while (cit != hist->constEnd()) {
|
||||
if (cit.value() > maxVal) {
|
||||
maxVal = cit.value();
|
||||
}
|
||||
++cit;
|
||||
}
|
||||
}
|
||||
|
||||
return maxVal;
|
||||
}
|
||||
|
||||
|
||||
/** Returns a pointer to the given channel QHash<int, int> */
|
||||
QHash<int, int>* Histogram::get(Channel channel = LChannel)
|
||||
{
|
||||
if (channel==LChannel) return L;
|
||||
|
Loading…
Reference in New Issue
Block a user