Fixed grayscale image handling

This commit is contained in:
Andrzej Wójtowicz 2019-10-14 10:24:36 +02:00
parent ecc73e34fe
commit d8d63a6a7a
10 changed files with 39 additions and 40 deletions

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_Indexed8: case QImage::Format_Grayscale8:
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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< 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_Indexed8 if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Grayscale8
<< QImage::Format_RGB32)) << QImage::Format_RGB32))
return; return;

View File

@ -17,7 +17,7 @@ PNM* ConversionGrayscale::transform()
int width = image->width(); int width = image->width();
int height = image->height(); int height = image->height();
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
if (image->format() == QImage::Format_Mono) if (image->format() == QImage::Format_Mono)
{ {

View File

@ -22,7 +22,7 @@ PNM* EdgeCanny::transform()
int upper_thresh = getParameter("upper_threshold").toInt(), int upper_thresh = getParameter("upper_threshold").toInt(),
lower_thresh = getParameter("lower_threshold").toInt(); lower_thresh = getParameter("lower_threshold").toInt();
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; qDebug() << Q_FUNC_INFO << "Not implemented yet!";

View File

@ -21,7 +21,7 @@ PNM* EdgeZeroCrossing::transform()
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
int t = getParameter("threshold").toInt(); int t = getParameter("threshold").toInt();
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; qDebug() << Q_FUNC_INFO << "Not implemented yet!";

View File

@ -15,7 +15,7 @@ PNM* MapHeight::transform()
int width = image->width(), int width = image->width(),
height = image->height(); height = image->height();
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; qDebug() << Q_FUNC_INFO << "Not implemented yet!";

View File

@ -33,7 +33,7 @@ PNM* MapHorizon::transform()
dy = -1; dy = -1;
} }
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; qDebug() << Q_FUNC_INFO << "Not implemented yet!";

View File

@ -33,9 +33,8 @@ PNM* NegativeImage::transform()
newImage->setPixel(x,y, color == Qt::white ? Qt::color0 : Qt::color1); newImage->setPixel(x,y, color == Qt::white ? Qt::color0 : Qt::color1);
} }
} }
else if (image->format() == QImage::Format_Indexed8) else if (image->format() == QImage::Format_Grayscale8) // Iterate over image space
{ {
// Iterate over image space
for (int x=0; x<width; x++) for (int x=0; x<width; x++)
for (int y=0; y<height; y++) for (int y=0; y<height; y++)
{ {
@ -44,7 +43,7 @@ PNM* NegativeImage::transform()
int v = qGray(pixel); // Get the 0-255 value of the L channel int v = qGray(pixel); // Get the 0-255 value of the L channel
v = PIXEL_VAL_MAX - v; v = PIXEL_VAL_MAX - v;
newImage->setPixel(x,y, v); newImage->setPixel(x,y, QColor(v,v,v).rgb());
} }
} }
else //if (image->format() == QImage::Format_RGB32) else //if (image->format() == QImage::Format_RGB32)

View File

@ -135,7 +135,7 @@ QString MainWindow::textFormat(QImage::Format format)
{ {
if (format == QImage::Format_RGB32) if (format == QImage::Format_RGB32)
return "Color RGB 32-bit"; return "Color RGB 32-bit";
else if (format == QImage::Format_Indexed8) else if (format == QImage::Format_Grayscale8)
return "Grayscale 8-bit"; return "Grayscale 8-bit";
else if (format == QImage::Format_Mono) else if (format == QImage::Format_Mono)
return "Black & white 1-bit"; return "Black & white 1-bit";

View File

@ -2,7 +2,7 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#define PROGRAM_NAME "PTO" #define PROGRAM_NAME "PTO"
#define PROGRAM_VER "3.1.3.37" #define PROGRAM_VER "3.1.3.38"
#define DEFAULT_IMG "lenna_512x512.pnm" #define DEFAULT_IMG "lenna_512x512.pnm"
#include <QMainWindow> #include <QMainWindow>