Skip to content

Instantly share code, notes, and snippets.

@unot
Last active December 20, 2015 19:19
Show Gist options
  • Save unot/6182707 to your computer and use it in GitHub Desktop.
Save unot/6182707 to your computer and use it in GitHub Desktop.
スキャン画像の面内むらを補正
/** \file shading.cpp
* \author unot
* \date 2013/08/08
* */
#include <iostream>
#include <string>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char const *argv[])
{
if(argc==1) {
std::cout << "Usage: shading input_img" << std::endl;
exit(0);
}
cv::Mat src_img = cv::imread(argv[1]);
if(src_img.empty()) {
std::cerr << "Image Load Failed!" << std::endl;
return -1;
}
static const std::string fileName_ext = argv[1];
static std::string fileName(fileName_ext, 0, fileName_ext.size()-4);
static const std::string empty_string;
static std::ostringstream os;
cv::Mat blurred, divided;
cv::GaussianBlur(src_img, blurred, cv::Size(), 60, 0);
// cv::imwrite("blurred.jpg", blurred);
src_img.convertTo(src_img, CV_32F);
blurred.convertTo(blurred, CV_32F);
divided = src_img * 255.0 / blurred;
divided.convertTo(divided, CV_8U);
cv::normalize(divided, divided, 0, 255, cv::NORM_MINMAX);
cv::erode(divided, divided, cv::Mat(), cv::Point(-1,-1), 1);
os << fileName << "_shaded.jpg";
cv::imwrite(os.str(), divided);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment