From a4168f64174833472f28c533e8b571a6345fbb42 Mon Sep 17 00:00:00 2001
From: qbigot <quentin.bigot@insa-rennes.fr>
Date: Fri, 21 Jul 2017 11:39:34 +0200
Subject: [PATCH] add possibility to choose the width and the height of the
 resut image for inverse Hough transform

---
 app/Operations/InverseHoughDialog.cpp |  8 +++++--
 app/Operations/InverseHoughDialog.h   |  3 ++-
 app/Operations/InverseHoughDialog.ui  | 30 ++++++++++++++++++++++-----
 app/Operations/InverseHoughOp.cpp     |  2 +-
 app/Operations/Transforms.cpp         | 26 +++++++++++------------
 app/Operations/Transforms.h           |  2 +-
 6 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/app/Operations/InverseHoughDialog.cpp b/app/Operations/InverseHoughDialog.cpp
index 5f81105..76a339f 100644
--- a/app/Operations/InverseHoughDialog.cpp
+++ b/app/Operations/InverseHoughDialog.cpp
@@ -32,8 +32,12 @@ InverseHoughDialog::~InverseHoughDialog()
     delete ui;
 }
 
-int InverseHoughDialog::getSize() const {
-    return ui->sizeBox->value();
+int InverseHoughDialog::getWidth() const {
+    return ui->widthBox->value();
+}
+
+int InverseHoughDialog::getHeight() const {
+    return ui->heightBox->value();
 }
 
 int InverseHoughDialog::getThreshodl() const {
diff --git a/app/Operations/InverseHoughDialog.h b/app/Operations/InverseHoughDialog.h
index 8e1cbee..405cb4c 100644
--- a/app/Operations/InverseHoughDialog.h
+++ b/app/Operations/InverseHoughDialog.h
@@ -33,7 +33,8 @@ class InverseHoughDialog : public QDialog
 public:
     explicit InverseHoughDialog(QWidget *parent = 0);
     ~InverseHoughDialog();
-    int getSize() const;
+    int getWidth() const;
+    int getHeight() const;
     int getThreshodl() const;
     
 private:
diff --git a/app/Operations/InverseHoughDialog.ui b/app/Operations/InverseHoughDialog.ui
index 08a3cce..fd0b42b 100644
--- a/app/Operations/InverseHoughDialog.ui
+++ b/app/Operations/InverseHoughDialog.ui
@@ -19,12 +19,12 @@
      <item row="0" column="0">
       <widget class="QLabel" name="label">
        <property name="text">
-        <string>Reconstructed image size : </string>
+        <string>Reconstructed image width : </string>
        </property>
       </widget>
      </item>
      <item row="0" column="1">
-      <widget class="QSpinBox" name="sizeBox">
+      <widget class="QSpinBox" name="widthBox">
        <property name="minimum">
         <number>1</number>
        </property>
@@ -32,27 +32,47 @@
         <number>65536</number>
        </property>
        <property name="singleStep">
-        <number>128</number>
+        <number>1</number>
        </property>
        <property name="value">
         <number>256</number>
        </property>
       </widget>
      </item>
-     <item row="1" column="0">
+     <item row="2" column="0">
       <widget class="QLabel" name="label_2">
        <property name="text">
         <string>Reconstruction threshold : </string>
        </property>
       </widget>
      </item>
-     <item row="1" column="1">
+     <item row="2" column="1">
       <widget class="QSpinBox" name="thresholdBox">
        <property name="maximum">
         <number>65536</number>
        </property>
       </widget>
      </item>
+     <item row="1" column="0">
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Reconstructed image height :</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <widget class="QSpinBox" name="heightBox">
+       <property name="minimum">
+        <number>1</number>
+       </property>
+       <property name="maximum">
+        <number>65536</number>
+       </property>
+       <property name="value">
+        <number>256</number>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>
diff --git a/app/Operations/InverseHoughOp.cpp b/app/Operations/InverseHoughOp.cpp
index 931f00d..6d7c1c0 100644
--- a/app/Operations/InverseHoughOp.cpp
+++ b/app/Operations/InverseHoughOp.cpp
@@ -40,6 +40,6 @@ void InverseHoughOp::operator()(const imagein::Image_t<double>* img, const std::
 
     if(code!=QDialog::Accepted) return;
     Image* resImg2;
-    Transforms::hough2_inverse(img, &resImg2, dialog->getSize(), dialog->getThreshodl());
+    Transforms::hough2_inverse(img, &resImg2, dialog->getWidth(), dialog->getHeight(), dialog->getThreshodl());
     outImage(resImg2, qApp->translate("Hough", "Hough inverse transform").toStdString());
 }
diff --git a/app/Operations/Transforms.cpp b/app/Operations/Transforms.cpp
index cdcf5cf..9523498 100644
--- a/app/Operations/Transforms.cpp
+++ b/app/Operations/Transforms.cpp
@@ -181,9 +181,9 @@ Image_t<double>* Transforms::hough2(const Image *image, double angleStep, double
 
     return resImg;
 }
-string Transforms::hough2_inverse(const Image_t<double> *image, Image** resImgptr, unsigned int size, unsigned int threshold) {
+string Transforms::hough2_inverse(const Image_t<double> *image, Image** resImgptr, unsigned int width, unsigned int height, unsigned int threshold) {
 
-    Image_t<uint32_t>* resImg = new Image_t<uint32_t>(size, size, image->getNbChannels(), uint32_t(0));
+    Image_t<uint32_t>* resImg = new Image_t<uint32_t>(width, height, image->getNbChannels(), uint32_t(0));
 
 //    int param = 5000 + 20 * image->getWidth() * image->getHeight();
 
@@ -203,15 +203,15 @@ string Transforms::hough2_inverse(const Image_t<double> *image, Image** resImgpt
 
     int cmpt = 0;
     for(unsigned int c = 0; c < image->getNbChannels(); ++c) {
-        for(unsigned int j = 0; j < image->getHeight(); ++j) {
-            for(unsigned int i = 0; i < image->getWidth(); ++i) {
+        for(unsigned int i = 0; i < image->getHeight(); ++i) {
+            for(unsigned int j = 0; j < image->getWidth(); ++j) {
 
-                int n = image->getPixelAt(i, j, c);
+                int n = image->getPixelAt(j, i, c);
                 if(n >= threshold)
                 {
                     cmpt++;
-                    double angle = angleStep * j / 180. * pi;
-                    double rho = rhoStep * i;
+                    double angle = angleStep * i / 180. * pi;
+                    double rho = rhoStep * j;
                     double sinte = sin(angle);
                     double coste = cos(angle);
 
@@ -219,19 +219,19 @@ string Transforms::hough2_inverse(const Image_t<double> *image, Image** resImgpt
     //                strcat( buffer, tampon);
 
                     //Construction de la droite d'quation
-                    for(unsigned int jj = 0; jj < size; ++jj) {
+                    for(unsigned int jj = 0; jj < width; ++jj) {
 
     //                    int kk = rho * (cos(angle) + tan(angle) * sin(angle)) - tan(angle)*jj;
                         int kk = (rho - sinte * jj) / coste;
-                        if( kk > 0 && kk < size) {
-                            resImg->pixelAt(kk, jj, c) += n;
+                        if( kk > 0 && kk < height) {
+                            resImg->pixelAt(jj, kk, c) += n;
                         }
                     }
-                    for(unsigned int ii = 0; ii < size; ++ii) {
+                    for(unsigned int ii = 0; ii < height; ++ii) {
     //                    int kk = ( rho * (cos(angle) + tan(angle) * sin(angle)) -ii ) / tan(angle);
                         int kk = (rho - coste * ii) / sinte;
-                        if( kk>0 && kk < size) {
-                            resImg->pixelAt(ii, kk, c) += n;
+                        if( kk>0 && kk < width) {
+                            resImg->pixelAt(kk, ii, c) += n;
                         }
                      }
 
diff --git a/app/Operations/Transforms.h b/app/Operations/Transforms.h
index 5c7fbe0..1044972 100644
--- a/app/Operations/Transforms.h
+++ b/app/Operations/Transforms.h
@@ -28,7 +28,7 @@ namespace Transforms
 {
     imagein::Image_t<double> *hough( const imagein::GrayscaleImage *im ); // This function works
     imagein::Image_t<double> *hough2( const imagein::Image *im , double angleStep, double rhoStep); // This function works
-    std::string hough2_inverse(const imagein::Image_t<double> *image, imagein::Image **resImg, unsigned int size, unsigned int threshold);
+    std::string hough2_inverse(const imagein::Image_t<double> *image, imagein::Image **resImg, unsigned int width, unsigned int height, unsigned int threshold);
     std::string Hadamard( const imagein::Image *im, imagein::Image_t<double> **result, imagein::Image **result_inverse, imagein::GrayscaleImage_t<bool> *selection = NULL);
     std::string Haar( const imagein::Image *im, imagein::Image_t<double> **result, imagein::Image **result_inverse, imagein::GrayscaleImage_t<bool> *selection = NULL );
     std::string cosinus( const imagein::Image *image, imagein::Image_t<double> **resImg, imagein::Image **invImg, imagein::GrayscaleImage_t<bool> *selection = NULL  );
-- 
GitLab