This commit is contained in:
Sebastian Spaloniak 2020-05-12 00:09:48 +02:00
parent b78ce3902b
commit 633adec165
3 changed files with 78 additions and 80 deletions

View File

@ -24,63 +24,61 @@ Histogram::~Histogram()
void Histogram::generate(QImage* image) void Histogram::generate(QImage* image)
{ {
qDebug() << Q_FUNC_INFO << "Histogram!"; int width = image->width();
qDebug() << Q_FUNC_INFO << image->height(); int height = image->height();
qDebug() << Q_FUNC_INFO << image->width(); //int i = 0;
for ( int row = 0; row < image->height(); ++row ) {
for ( int col = 0; col < image->width(); ++col ) { for (int x = 0; x<width; x++)
QColor clrCurrent( image->pixel( row, col ) ); {
if (R->contains(clrCurrent.red())) { for (int y = 0; y<height; y++)
R->insert(clrCurrent.red(), R->value(clrCurrent.red()) + 1); {
} else { QRgb pixel = image->pixel(x, y);
R->insert(clrCurrent.red(), 1);
} int r = qRed(pixel);
if (G->contains(clrCurrent.green())) { int g = qGreen(pixel);
G->insert(clrCurrent.green(), G->value(clrCurrent.green()) + 1); int b = qBlue(pixel);
} else { int l = qGray(pixel);
G->insert(clrCurrent.green(), 1); R->insert(r, R->value(r) + 1);
} G->insert(g, G->value(g) + 1);
if (B->contains(clrCurrent.blue())) { B->insert(b, B->value(b) + 1);
B->insert(clrCurrent.blue(), B->value(clrCurrent.blue()) + 1); L->insert(l, L->value(l) + 1);
} else { }
B->insert(clrCurrent.blue(), 1);
}
if (L->contains(clrCurrent.alpha())) {
L->insert(clrCurrent.alpha(), L->value(clrCurrent.alpha()) + 1);
} else {
L->insert(clrCurrent.alpha(), 1);
}
} }
}
} }
/** Returns the maximal value of the histogram in the given channel */ /** Returns the maximal value of the histogram in the given channel */
int Histogram::maximumValue(Channel selectedChannel = RGB) int Histogram::maximumValue(Channel selectedChannel = RGB)
{ {
qDebug() << Q_FUNC_INFO << "Max value!"; int max = 0;
qDebug() << Q_FUNC_INFO << selectedChannel;
int max = 1;
if (selectedChannel == RGB) { if (selectedChannel == RGB) {
qDebug() << Q_FUNC_INFO << "RGB"; if (maximumValue(RChannel) > max) {
max = maximumValue(RChannel); max = maximumValue(RChannel);
int maxG = maximumValue(GChannel); }
if (maxG > max) { if (maximumValue(GChannel) > max) {
max = maxG; max = maximumValue(GChannel);
} }
int maxB = maximumValue(BChannel); if (maximumValue(BChannel) > max) {
if (maxB > max) { max = maximumValue(BChannel);
max = maxB; }
} }
} else { else
qDebug() << Q_FUNC_INFO << "selectedChannel"; {
foreach(int value, get(selectedChannel)->values()) { QHash<int, int>* hash = get(selectedChannel);
if (value > max) { QHash<int, int>::iterator i = hash->begin();
max = value;
} for (i = hash->begin(); i != hash->end(); ++i)
} {
} if (i.value() > max)
return max; {
max = i.value();
}
}
}
return max;
} }

View File

@ -44,7 +44,7 @@ PNM::PNM(int width, int height, QImage::Format format) :
{ {
case QImage::Format_Mono: case QImage::Format_Mono:
break; break;
case QImage::Format_Grayscale8: case QImage::Format_Indexed8:
this->setColorCount(256); this->setColorCount(256);
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)

View File

@ -21,7 +21,7 @@ void Tools::negativeImage()
ImageViewer* iv = getViewer(); // Get the ImageViewer which holds the image. ImageViewer* iv = getViewer(); // Get the ImageViewer which holds the image.
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -45,7 +45,7 @@ void Tools::correctBrightnessContrastGamma()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -75,7 +75,7 @@ void Tools::histogramEqualize()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -87,7 +87,7 @@ void Tools::histogramStretch()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -113,7 +113,7 @@ void Tools::blurGauss()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -132,7 +132,7 @@ void Tools::blurLinear()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -152,7 +152,7 @@ void Tools::blurUniform()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -170,7 +170,7 @@ void Tools::binGradient()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -182,7 +182,7 @@ void Tools::binIterBimodal()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -194,7 +194,7 @@ void Tools::binManual()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -216,7 +216,7 @@ void Tools::binNiblack()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -234,7 +234,7 @@ void Tools::binOtsu()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -252,7 +252,7 @@ void Tools::noiseMedian()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -269,7 +269,7 @@ void Tools::noiseBilateral()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -294,7 +294,7 @@ void Tools::morphDilate()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -316,7 +316,7 @@ void Tools::morphErode()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -338,7 +338,7 @@ void Tools::morphOpen()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -360,7 +360,7 @@ void Tools::morphClose()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -387,7 +387,7 @@ void Tools::edgeSobel()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -399,7 +399,7 @@ void Tools::edgePrewitt()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -411,7 +411,7 @@ void Tools::edgeRoberts()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -424,7 +424,7 @@ void Tools::edgeLaplacian()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -444,7 +444,7 @@ void Tools::edgeZero()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -470,7 +470,7 @@ void Tools::mapHeight()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -483,7 +483,7 @@ void Tools::mapHorizon()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -524,7 +524,7 @@ void Tools::edgeCanny()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -549,7 +549,7 @@ void Tools::houghTransform()
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8 << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -590,7 +590,7 @@ void Tools::cornerHarris()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;
@ -633,7 +633,7 @@ void Tools::segmentation()
{ {
ImageViewer* iv = getViewer(); ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;