Skip to content

Instantly share code, notes, and snippets.

@yasutomo57jp
Created February 27, 2013 02:52
Show Gist options
  • Save yasutomo57jp/5044579 to your computer and use it in GitHub Desktop.
Save yasutomo57jp/5044579 to your computer and use it in GitHub Desktop.
#include <opencv2/opencv.hpp>
cv::Mat normalize(const cv::Mat& img, double minval, double maxval){
cv::Mat vimg;
cv::Mat tmp=(img - minval)/(maxval-minval)*255;
tmp.convertTo(vimg, CV_8UC(img.channels()));
return vimg;
}
void dimshow(const std::string& name, const cv::Mat& img){
if(img.type()==CV_8UC1 || img.type()==CV_8UC3){
cv::imshow(name, img);
return;
}
int c=img.channels();
std::vector<cv::Mat> chimgs;
cv::split(img, chimgs);
double minval=std::numeric_limits<double>::max();
double maxval=std::numeric_limits<double>::min();
for(int i=0;i<c;i++){
double minv, maxv;
cv::minMaxLoc(chimgs[i], &minv, &maxv);
if(minv < minval) minval=minv;
if(maxv > maxval) maxval=maxv;
}
if(maxval-minval ==0){
cv::imshow(name, img);
return;
}
cv::Mat vimg=normalize(img, minval, maxval);
cv::imshow(name, vimg);
return;
}
void dimshow(const std::string& name, const cv::Mat& img, double minvalue, double maxvalue){
cv::Mat vimg=normalize(img, minvalue, maxvalue);
cv::imshow(name, vimg);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment