title: Qt / OpenCV - Resizing an Image doesn't work with specific sizes
body: <p>I made an Image Editor in Qt / OpenCV where you can load the Image from the File explorer and grayscale/adaptive threshold/resize it afterwards.</p>
  <p>Bug 1: When I resize the Loaded Image to (for example) 600x600 Pixels using my ImageProcessor::Resize(int, int) method, it works fine. But when I change it to like 546x750 Pixels, the Image has a weird grayscale.</p>
  <p>Bug 2: When I want to resize my Grayscaled/Thresholded Image, it always gets a weird grayscale similiar to Bug 1.</p>
  <p>Codes:</p>
  <p>mainwindow.cpp</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &quot;mainwindow.h&quot;
  #include &quot;ui_mainwindow.h&quot;
  
  #include &quot;resizer.h&quot;
  
  MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  
  void MainWindow::Display(cv::Mat inputImage)
  {
          QImage image = QImage(inputImage.data, inputImage.cols, inputImage.rows, QImage::Format_RGB888);
          scene-&gt;addPixmap(QPixmap::fromImage(image));
          ui-&gt;graphicsView-&gt;setScene(scene);
          ui-&gt;graphicsView-&gt;show();
  }
  
  
  void MainWindow::on_actionOpen_triggered()
  {
      QString file = QFileDialog::getOpenFileName(this, &quot;Open&quot;, &quot;&quot;, &quot;Images (*.jpg *.png)&quot;);
      std::string filename = file.toStdString();
      inputImage = cv::imread(filename);
      Display(inputImage);
  
      imgProc = new ImageProcessor(inputImage);
  }
  
  
  void MainWindow::on_pushButton_clicked() // Grayscale
  {
      scene-&gt;clear();
  
      imgProc-&gt;mode = 1;
      inputImage = imgProc-&gt;Grayscale();
  
      QImage image = QImage(inputImage.data, inputImage.cols, inputImage.rows, QImage::Format_Grayscale8);
      scene-&gt;addPixmap(QPixmap::fromImage(image));
      ui-&gt;graphicsView-&gt;setScene(scene);
      ui-&gt;graphicsView-&gt;show();
  }
  
  
  void MainWindow::on_pushButton_2_clicked() // ADT
  {
      scene-&gt;clear();
  
      imgProc-&gt;mode = 2;
      inputImage = imgProc-&gt;AdaptiveThreshold();
  
      QImage image = QImage(inputImage.data, inputImage.cols, inputImage.rows, QImage::Format_Grayscale8);
      scene-&gt;addPixmap(QPixmap::fromImage(image));
      ui-&gt;graphicsView-&gt;setScene(scene);
      ui-&gt;graphicsView-&gt;show();
  }
  
  
  void MainWindow::on_pushButton_3_clicked() // Resize
  {
      scene-&gt;clear();
  
      Resizer resizer;
      resizer.exec();
  
      int newWidth = resizer.GetWidth();
      int newHeight = resizer.GetHeight();
  
      inputImage = imgProc-&gt;Resize(newWidth, newHeight);
  
      if(imgProc-&gt;mode == 1 || imgProc-&gt;mode == 2)
      {
          QImage image = QImage(inputImage.data, inputImage.cols, inputImage.rows, QImage::Format_Grayscale8);
          scene-&gt;addPixmap(QPixmap::fromImage(image));
          ui-&gt;graphicsView-&gt;setScene(scene);
          ui-&gt;graphicsView-&gt;show();
      }
      else
      {
          QImage image = QImage(inputImage.data, inputImage.cols, inputImage.rows, QImage::Format_RGB888);
          scene-&gt;addPixmap(QPixmap::fromImage(image));
          ui-&gt;graphicsView-&gt;setScene(scene);
          ui-&gt;graphicsView-&gt;show();
      }
  }
  
  
  </code></pre>
  <p>imageprocessor.cpp</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &quot;imageprocessor.h&quot;
  
  ImageProcessor::ImageProcessor(cv::Mat inputImage)
  {
      this-&gt;inputImage = inputImage;
  }
  
  cv::Mat ImageProcessor::Resize(int width, int height)
  {
      cv::Mat resized;
      cv::resize(inputImage, resized, cv::Size(width, height), cv::INTER_LINEAR);
      return resized;
  }
  
  cv::Mat ImageProcessor::Grayscale()
  {
      cv::Mat grayscaled;
      cv::cvtColor(inputImage, grayscaled, cv::COLOR_RGB2GRAY);
      return grayscaled;
  }
  
  cv::Mat ImageProcessor::AdaptiveThreshold()
  {
      cv::Mat binarized, grayscaled;
      cv::cvtColor(inputImage, grayscaled, cv::COLOR_RGB2GRAY);
      cv::adaptiveThreshold(grayscaled, binarized, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 15, 11);
      return binarized;
  }
  </code></pre>