//------------------ shows histogram values on the graphic---------------------------------- void MainWindow::on_pushButton_clicked() { Histogram1D graph; cv::namedWindow("histogram graph"); cv::imshow("histogram graph", graph.getHistogramImage(image)); }
void case2histogram() { cv::Mat image=cv::imread( inputImagePath4case1histogram,cv::IMREAD_GRAYSCALE );//open in b&w alert_win( image ); Histogram1D h; cv::Mat re= h.getHistogramImage(image); alert_win( re ); }
//-------------------- equalized the b&w image ------------------------------------------------- //---------------------- shows it's histogram values on a graph -------------------------------- void MainWindow::on_pushButton_6_clicked() { Histogram1D equa; cv::namedWindow("equalized"); cv::namedWindow("equalized histogram"); cv::Mat equalized=equa.equalize(image); cv::imshow("equalized",equalized); cv::imshow("equalized histogram",equa.getHistogramImage(equalized)); }
//---------------------------stretches the image on some level--------------------------------------- //--------------------------- and also show it's histogram level on a grahp-------------------------- void MainWindow::on_pushButton_5_clicked() { Histogram1D str; cv::Mat strecthLevel; cv::namedWindow("stretched"); int x= ui->lineEdit->text().toInt(); cv::Mat strecthed = str.strecth(image,x); cv::imshow("stretched", strecthed); cv::imshow("stretched histogram",str.getHistogramImage(strecthed)); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Mat image = imread("D:\\workspace\\pictures\\771413900_m.jpg",0); Mat thresholded, result; Histogram1D h; MatND histo = h.getHistogram(image); for (int i=0;i<256;i++) cout << "Value" << i << "=" << histo.at<float>(i) << endl; imshow("Orginal", image); imshow("Histogram",h.getHistogramImage(image)); //threshold(image, thresholded,128,255,THRESH_BINARY); //imshow("Threshold",thresholded); equalizeHist(image,result); //Mat stretched = h.stretch(image,100); //imshow("Stretched",stretched); imshow("Equalize",result); imshow("After Equalize Histogram",h.getHistogramImage(result)); waitKey(50000); return a.exec(); }
//-------------------- tranforms the image to negative--------------------------------------- //-------------------- shows it's histogram values on graphic-------------------------------- void MainWindow::on_pushButton_4_clicked() { Histogram1D negative; //build look up int dim(256); cv::Mat lut(1, &dim, CV_8U); // lut is a matrix which is in 1D for(int i=0; i<256; i++) { lut.at<uchar>(i)=255-i; //takes all the values and reverses it } cv::Mat negativeResult; negativeResult=negative.applyLookUp(image,lut); cv::namedWindow("negative"); cv::imshow("negative",negativeResult); //negative image histogram cv::imshow("negative histogram",negative.getHistogramImage(negativeResult)); }
int main() { Mat src; src = imread("box.png"); if( !src.data ) { cout<<"error"; } namedWindow("image", CV_WINDOW_AUTOSIZE ); imshow("image", src ); waitKey(0); // The histogram object Histogram1D h; namedWindow("Histogram"); imshow("Histogram",h.getHistogramImage(src)); waitKey(0); return 1; }
int main() { // Read input image cv::Mat image= cv::imread("waves.jpg",0); if (!image.data) return 0; // define image ROI cv::Mat imageROI; imageROI= image(cv::Rect(216,33,24,30)); // Cloud region // Display reference patch cv::namedWindow("Reference"); cv::imshow("Reference",imageROI); // Find histogram of reference Histogram1D h; cv::Mat hist= h.getHistogram(imageROI); cv::namedWindow("Reference Hist"); cv::imshow("Reference Hist",h.getHistogramImage(imageROI)); // Create the content finder ContentFinder finder; // set histogram to be back-projected finder.setHistogram(hist); finder.setThreshold(-1.0f); // Get back-projection cv::Mat result1; result1= finder.find(image); // Create negative image and display result cv::Mat tmp; result1.convertTo(tmp,CV_8U,-1.0,255.0); cv::namedWindow("Backprojection result"); cv::imshow("Backprojection result",tmp); // Get binary back-projection finder.setThreshold(0.12f); result1= finder.find(image); // Draw a rectangle around the reference area cv::rectangle(image, cv::Rect(216, 33, 24, 30), cv::Scalar(0, 0, 0)); // Display image cv::namedWindow("Image"); cv::imshow("Image",image); // Display result cv::namedWindow("Detection Result"); cv::imshow("Detection Result",result1); // Load color image ColorHistogram hc; cv::Mat color= cv::imread("waves.jpg"); // extract region of interest imageROI= color(cv::Rect(0,0,100,45)); // blue sky area // Get 3D colour histogram (8 bins per channel) hc.setSize(8); // 8x8x8 cv::Mat shist= hc.getHistogram(imageROI); // set histogram to be back-projected finder.setHistogram(shist); finder.setThreshold(0.05f); // Get back-projection of color histogram result1= finder.find(color); cv::namedWindow("Color Detection Result"); cv::imshow("Color Detection Result",result1); // Second color image cv::Mat color2= cv::imread("dog.jpg"); cv::namedWindow("Second Image"); cv::imshow("Second Image",color2); // Get back-projection of color histogram cv::Mat result2= finder.find(color2); cv::namedWindow("Result color (2)"); cv::imshow("Result color (2)",result2); // Get ab color histogram hc.setSize(256); // 256x256 cv::Mat colorhist= hc.getabHistogram(imageROI); // display 2D histogram colorhist.convertTo(tmp,CV_8U,-1.0,255.0); cv::namedWindow("ab histogram"); cv::imshow("ab histogram",tmp); // set histogram to be back-projected finder.setHistogram(colorhist); finder.setThreshold(0.05f); // Convert to Lab space cv::Mat lab; cv::cvtColor(color, lab, CV_BGR2Lab); // Get back-projection of ab histogram int ch[2]={1,2}; result1= finder.find(lab,0,256.0f,ch); cv::namedWindow("Result ab (1)"); cv::imshow("Result ab (1)",result1); // Second colour image cv::cvtColor(color2, lab, CV_BGR2Lab); // Get back-projection of ab histogram result2= finder.find(lab,0,256.0,ch); cv::namedWindow("Result ab (2)"); cv::imshow("Result ab (2)",result2); // Draw a rectangle around the reference sky area cv::rectangle(color,cv::Rect(0,0,100,45),cv::Scalar(0,0,0)); cv::namedWindow("Color Image"); cv::imshow("Color Image",color); // Get Hue colour histogram hc.setSize(180); // 180 bins colorhist= hc.getHueHistogram(imageROI); // set histogram to be back-projected finder.setHistogram(colorhist); // Convert to HSV space cv::Mat hsv; cv::cvtColor(color, hsv, CV_BGR2HSV); // Get back-projection of hue histogram ch[0]=0; result1= finder.find(hsv,0.0f,180.0f,ch); cv::namedWindow("Result Hue (1)"); cv::imshow("Result Hue (1)",result1); // Second colour image color2= cv::imread("dog.jpg"); // Convert to HSV space cv::cvtColor(color2, hsv, CV_BGR2HSV); // Get back-projection of hue histogram result2= finder.find(hsv,0.0f,180.0f,ch); cv::namedWindow("Result Hue (2)"); cv::imshow("Result Hue (2)",result2); cv::waitKey(); return 0; }
cv::Mat ImageProcessor::getHistogram(cv::Mat &origImage) { Histogram1D h; return h.getHistogramImage(origImage); }
int main() { // Read input image cv::Mat image= cv::imread("group.jpg",0); if (!image.data) return 0; // Resize by 70% for book printing cv::resize(image, image, cv::Size(), 0.7, 0.7); // save grayscale image cv::imwrite("groupBW.jpg", image); // Display the image cv::namedWindow("Image"); cv::imshow("Image",image); // The histogram object Histogram1D h; // Compute the histogram cv::Mat histo= h.getHistogram(image); // Loop over each bin for (int i=0; i<256; i++) cout << "Value " << i << " = " << histo.at<float>(i) << endl; // Display a histogram as an image cv::namedWindow("Histogram"); cv::imshow("Histogram",h.getHistogramImage(image)); // creating a binary image by thresholding at the valley cv::Mat thresholded; // output binary image cv::threshold(image,thresholded, 60, // threshold value 255, // value assigned to pixels over threshold value cv::THRESH_BINARY); // thresholding type // Display the thresholded image cv::namedWindow("Binary Image"); cv::imshow("Binary Image",thresholded); thresholded = 255 - thresholded; cv::imwrite("binary.bmp",thresholded); // Equalize the image cv::Mat eq= h.equalize(image); // Show the result cv::namedWindow("Equalized Image"); cv::imshow("Equalized Image",eq); // Show the new histogram cv::namedWindow("Equalized Histogram"); cv::imshow("Equalized Histogram",h.getHistogramImage(eq)); // Stretch the image, setting the 1% of pixels at black and 1% at white cv::Mat str= h.stretch(image,0.01f); // Show the result cv::namedWindow("Stretched Image"); cv::imshow("Stretched Image",str); // Show the new histogram cv::namedWindow("Stretched Histogram"); cv::imshow("Stretched Histogram",h.getHistogramImage(str)); // Create an image inversion table int dim(256); cv::Mat lut(1, // 1 dimension &dim, // 256 entries CV_8U); // uchar // or cv::Mat lut(256,1,CV_8U); for (int i=0; i<256; i++) { lut.at<uchar>(i)= 255-i; } // Apply lookup and display negative image cv::namedWindow("Negative image"); cv::imshow("Negative image",h.applyLookUp(image,lut)); cv::waitKey(); return 0; }
int main_his() { // Read input image cv::Mat image= cv::imread("Koala.jpg",0); if (!image.data) return 0; // Display the image cv::namedWindow("Image"); cv::imshow("Image",image); // The histogram object Histogram1D h; // Compute the histogram cv::MatND histo= h.getHistogram(image); // Loop over each bin for (int i=0; i<256; i++) cout << "Value " << i << " = " << histo.at<float>(i) << endl; // Display a histogram as an image cv::namedWindow("Histogram"); cv::imshow("Histogram",h.getHistogramImage(image)); // creating a binary image by thresholding at the valley cv::Mat thresholded; cv::threshold(image,thresholded,60,255,cv::THRESH_BINARY); // Display the thresholded image cv::namedWindow("Binary Image"); cv::imshow("Binary Image",thresholded); cv::imwrite("binary.bmp",thresholded); // Equalize the image cv::Mat eq= h.equalize(image); // Show the result cv::namedWindow("Equalized Image"); cv::imshow("Equalized Image",eq); // Show the new histogram cv::namedWindow("Equalized Histogram"); cv::imshow("Equalized Histogram",h.getHistogramImage(eq)); // Stretch the image ignoring bins with less than 5 pixels cv::Mat str= h.stretch(image,5); // Show the result cv::namedWindow("Stretched Image"); cv::imshow("Stretched Image",str); // Show the new histogram cv::namedWindow("Stretched Histogram"); cv::imshow("Stretched Histogram",h.getHistogramImage(str)); // Create an image inversion table //uchar lookup[256]; // Create lookup table int dims[1]={256}; cv::MatND lookup(1,dims,CV_8U); for (int i=0; i<256; i++) { lookup.at<uchar>(i)=255-i; } // Apply lookup and display negative image cv::namedWindow("Negative image"); cv::imshow("Negative image",h.applyLookUp(image,lookup)); cv::waitKey(); return 0; }