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,61 +24,59 @@ Histogram::~Histogram()
void Histogram::generate(QImage* image)
{
qDebug() << Q_FUNC_INFO << "Histogram!";
qDebug() << Q_FUNC_INFO << image->height();
qDebug() << Q_FUNC_INFO << image->width();
for ( int row = 0; row < image->height(); ++row ) {
for ( int col = 0; col < image->width(); ++col ) {
QColor clrCurrent( image->pixel( row, col ) );
if (R->contains(clrCurrent.red())) {
R->insert(clrCurrent.red(), R->value(clrCurrent.red()) + 1);
} else {
R->insert(clrCurrent.red(), 1);
}
if (G->contains(clrCurrent.green())) {
G->insert(clrCurrent.green(), G->value(clrCurrent.green()) + 1);
} else {
G->insert(clrCurrent.green(), 1);
}
if (B->contains(clrCurrent.blue())) {
B->insert(clrCurrent.blue(), B->value(clrCurrent.blue()) + 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);
}
int width = image->width();
int height = image->height();
//int i = 0;
for (int x = 0; x<width; x++)
{
for (int y = 0; y<height; y++)
{
QRgb pixel = image->pixel(x, y);
int r = qRed(pixel);
int g = qGreen(pixel);
int b = qBlue(pixel);
int l = qGray(pixel);
R->insert(r, R->value(r) + 1);
G->insert(g, G->value(g) + 1);
B->insert(b, B->value(b) + 1);
L->insert(l, L->value(l) + 1);
}
}
}
/** Returns the maximal value of the histogram in the given channel */
int Histogram::maximumValue(Channel selectedChannel = RGB)
{
qDebug() << Q_FUNC_INFO << "Max value!";
qDebug() << Q_FUNC_INFO << selectedChannel;
int max = 1;
int max = 0;
if (selectedChannel == RGB) {
qDebug() << Q_FUNC_INFO << "RGB";
if (maximumValue(RChannel) > max) {
max = maximumValue(RChannel);
int maxG = maximumValue(GChannel);
if (maxG > max) {
max = maxG;
}
int maxB = maximumValue(BChannel);
if (maxB > max) {
max = maxB;
if (maximumValue(GChannel) > max) {
max = maximumValue(GChannel);
}
} else {
qDebug() << Q_FUNC_INFO << "selectedChannel";
foreach(int value, get(selectedChannel)->values()) {
if (value > max) {
max = value;
if (maximumValue(BChannel) > max) {
max = maximumValue(BChannel);
}
}
else
{
QHash<int, int>* hash = get(selectedChannel);
QHash<int, int>::iterator i = hash->begin();
for (i = hash->begin(); i != hash->end(); ++i)
{
if (i.value() > 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:
break;
case QImage::Format_Grayscale8:
case QImage::Format_Indexed8:
this->setColorCount(256);
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.
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -45,7 +45,7 @@ void Tools::correctBrightnessContrastGamma()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -75,7 +75,7 @@ void Tools::histogramEqualize()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -87,7 +87,7 @@ void Tools::histogramStretch()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -113,7 +113,7 @@ void Tools::blurGauss()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -132,7 +132,7 @@ void Tools::blurLinear()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -152,7 +152,7 @@ void Tools::blurUniform()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -170,7 +170,7 @@ void Tools::binGradient()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -182,7 +182,7 @@ void Tools::binIterBimodal()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -194,7 +194,7 @@ void Tools::binManual()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -216,7 +216,7 @@ void Tools::binNiblack()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -234,7 +234,7 @@ void Tools::binOtsu()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -252,7 +252,7 @@ void Tools::noiseMedian()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -269,7 +269,7 @@ void Tools::noiseBilateral()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -294,7 +294,7 @@ void Tools::morphDilate()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -316,7 +316,7 @@ void Tools::morphErode()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -338,7 +338,7 @@ void Tools::morphOpen()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -360,7 +360,7 @@ void Tools::morphClose()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -387,7 +387,7 @@ void Tools::edgeSobel()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -399,7 +399,7 @@ void Tools::edgePrewitt()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -411,7 +411,7 @@ void Tools::edgeRoberts()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -424,7 +424,7 @@ void Tools::edgeLaplacian()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -444,7 +444,7 @@ void Tools::edgeZero()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -470,7 +470,7 @@ void Tools::mapHeight()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -483,7 +483,7 @@ void Tools::mapHorizon()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -524,7 +524,7 @@ void Tools::edgeCanny()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -549,7 +549,7 @@ void Tools::houghTransform()
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
<< QImage::Format_Grayscale8
<< QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -590,7 +590,7 @@ void Tools::cornerHarris()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;
@ -633,7 +633,7 @@ void Tools::segmentation()
{
ImageViewer* iv = getViewer();
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
<< QImage::Format_RGB32))
return;