Commit a56ee450 authored by Jesse Mapel's avatar Jesse Mapel
Browse files

Fixed Scharr and Sobel filters applying blur to the original images causing...

Fixed Scharr and Sobel filters applying blur to the original images causing issues with repeated usage. Fixes #4904.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7834 41f8697f-d340-4b68-9986-7bafba869bb8
parent 744e1d55
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -48,6 +48,20 @@ QString ImageTransform::name() const {
  return ( m_name );  
}


/**
 * Perform the transformation on an image matrix.
 * Child classes should override this method with to implement transformation
 * process.
 * 
 * @param image The input image data matrix to transform.
 * 
 * @return @b cv::Mat The transformed matrix.
 * 
 * @note The cv::Mat class implicilty shares, so if the input image matrix, or
 *       a copy of it, will be modified you need to clone() the matrix prior
 *       to modification or the input matrix will be changed.
 */
cv::Mat ImageTransform::render(const cv::Mat &image) const {
 return (image);
}
+4 −1
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ namespace Isis {
 * @author 2014-07-01 Kris Becker 
 * @internal 
 *   @history 2014-07-01 Kris Becker - Original Version
 *   @history 2017-06-22 Jesse Mapel - Added a warning to render about
 *                                     cv::Mat copying and modification.
 *                                     References #4904.
 */

class ImageTransform {
+26 −2
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ namespace Isis {
 * @author 2015-10-14 Kris Becker 
 * @internal 
 *   @history 2015-10-14 Kris Becker - Original Version
 *   @history 2017-06-22 Jesse Mapel - Modified render to make a deep copy of
 *                                     the input matrix. References #4904.
 */

class ScharrTransform : public ImageTransform {
@@ -50,16 +52,38 @@ class ScharrTransform : public ImageTransform {
                   ImageTransform(name), m_reduceNoise(reduceNoise) { } 
    virtual ~ScharrTransform() { }


    /**
     * Perform the transformation on an image matrix. If the reduce noise flag
     * is set, then this will apply a Gaussian filter with a 3x3 kernel prior
     * to performing the Scharr transformation.
     * 
     * @param image The input image data matrix to transform.
     * 
     * @return @b cv::Mat The transformed matrix.
     * 
     * @note If the reduce noise flag is set, this method creates a deep copy
     *       of the image data matrix which may consume a large amount of memory.
     */
    virtual cv::Mat render(const cv::Mat &image) const {
      int scale = 1;
      int delta = 0;
      int ddepth = CV_16S;

      // Initialize and reduce noise if requested
      cv::Mat src = image;
      //   cv::Mat creates shallow copies by default and does not detach on
      //   modification. So, if applying the Gaussian filter, a deep copy of
      //   the matrix must be created. Otherwise cv::Mat's copy constructor
      //   can be used.
      //   For more details about this see ticket #4904. JAM
      cv::Mat src;
      if ( m_reduceNoise ) {
        src = image.clone();
        cv::GaussianBlur(src, src, cv::Size(3, 3), 0, 0, cv::BORDER_REFLECT ); 
      }
      else {
        src = image;
      }

      /// Generate grad_x and grad_y
      cv::Mat grad_x, grad_y;
+24 −1
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ namespace Isis {
 * @author 2015-10-14 Kris Becker 
 * @internal 
 *   @history 2015-10-14 Kris Becker - Original Version 
 *   @history 2017-06-22 Jesse Mapel - Modified render to make a deep copy of
 *                                     the input matrix. References #4904.
 */

class SobelTransform : public ImageTransform {
@@ -50,16 +52,37 @@ class SobelTransform : public ImageTransform {
                   ImageTransform(name), m_reduceNoise(reduceNoise) { } 
    virtual ~SobelTransform() { }

    /**
     * Perform the transformation on an image matrix. If the reduce noise flag
     * is set, then this will apply a Gaussian filter with a 3x3 kernel prior
     * to performing the Sobel transformation.
     * 
     * @param image The input image data matrix to transform.
     * 
     * @return @b cv::Mat The transformed matrix.
     * 
     * @note If the reduce noise flag is set, this method creates a deep copy
     *       of the image data matrix which may consume a large amount of memory.
     */
    virtual cv::Mat render(const cv::Mat &image) const {
      int scale = 1;
      int delta = 0;
      int ddepth = CV_16S;

      // Initialize and reduce noise if requested
      cv::Mat src = image;
      //   cv::Mat creates shallow copies by default and does not detach on
      //   modification. So, if applying the Gaussian filter, a deep copy of
      //   the matrix must be created. Otherwise cv::Mat's copy constructor
      //   can be used.
      //   For more details about this see ticket #4904. JAM
      cv::Mat src;
      if ( m_reduceNoise ) {
        src = image.clone();
        cv::GaussianBlur(src, src, cv::Size(3, 3), 0, 0, cv::BORDER_REFLECT ); 
      }
      else {
        src = image;
      }

      /// Generate grad_x and grad_y
      cv::Mat grad_x, grad_y;
+6 −0
Original line number Diff line number Diff line
@@ -1181,6 +1181,12 @@ Group = MatchSolution
       method to MatchImage and made the MatchImages used by each algorithm
       specification independent. Fixes #4765.
    </change>
    <change name="Jesse Mapel" date="2017-06-22"> 
       Modified the Sobel and Scharr filters to create a deep copy of the image
       before being applied. This corrects repeated applications of a Gaussian
       filter when using these filters with multiple algorithm specifications.
       Fixes #4904.
    </change>
    <change name="Jesse Mapel" date="2017-06-23"> 
       Corrected several errors in documentation. Fixed the MSER algorithm name.
       Fixed AKAZE being flagged as only an extractor. Fixes #4950.
Loading