Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check image dimension in vpImageFilter::gaussianBlur function #1535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

s-trinh
Copy link
Contributor

@s-trinh s-trinh commented Jan 5, 2025

To avoid segfault when the image is too small, e.g.:

  • exe --sigma 2 --height 18 --width 11
#include <visp3/core/vpImage.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/core/vpImageFilter.h>
#include <visp3/core/vpGaussianFilter.h>

int main(int argc, const char *argv[])
{
  float sigma = 1.0f;
  unsigned int width = 17, height = 11;

  for (int i = 1; i < argc; i++) {
    if (std::string(argv[i]) == "--sigma" && i + 1 < argc) {
      sigma = std::atof(argv[++i]);
    }
    else if (std::string(argv[i]) == "--width" && i + 1 < argc) {
      width = std::atoi(argv[++i]);
    }
    else if (std::string(argv[i]) == "--height" && i + 1 < argc) {
      height = std::atoi(argv[++i]);
    }
    else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
      std::cout << "\nUsage: " << argv[0]
        << " [--sigma <Gaussian sigma value>]"
        << " [--width <image width>] [--height <image height>]"
        << " [--help] [-h]\n"
        << std::endl;
      return EXIT_SUCCESS;
    }
  }

  const unsigned int kernelSize = 6*sigma + 1;
  std::cout << "Gaussian sigma: " << sigma << std::endl;
  std::cout << "Gaussian kernel size: " << kernelSize << std::endl;
  std::cout << "Image size: " << width << "x" << height << std::endl;

  vpImage<unsigned char> I(height, width, 0), I_blur;
  for (unsigned int i = 0; i < I.getHeight(); i++) {
    for (unsigned int j = 0; j < I.getWidth(); j++) {
      I[i][j] = static_cast<unsigned char>(i*I.getWidth() + j);
    }
  }

  vpImage<vpRGBa> I_color, I_color_blur;
  vpImageConvert::convert(I, I_color);

  vpImageFilter::gaussianBlur(I_color, I_color_blur, kernelSize, 0);

  return EXIT_SUCCESS;
}

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 54.01%. Comparing base (ef5fc77) to head (a82c454).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
modules/core/src/image/vpImageFilter.cpp 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1535      +/-   ##
==========================================
- Coverage   54.01%   54.01%   -0.01%     
==========================================
  Files         441      441              
  Lines       53859    53863       +4     
==========================================
+ Hits        29092    29093       +1     
- Misses      24767    24770       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant