Created
February 27, 2013 02:52
-
-
Save yasutomo57jp/5044579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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