Ejemplo n.º 1
0
//----------------- shows image's histogram on terminal-----------------------------------
void MainWindow::on_pushButton_2_clicked()
{
    Histogram1D terminal;

    cv::MatND histo=terminal.getHistogram(image);
// shows values of histgoram on terminal
   for (int i=0; i<256; i++)
        std::cout<<"value"<<i<<"="<<histo.at<float>(i)<<std::endl;
}
Ejemplo n.º 2
0
void case1histogram() {
    cv::Mat image=cv::imread( inputImagePath4case1histogram,cv::IMREAD_GRAYSCALE );//open in b&w
    Histogram1D h;
    cv::MatND histo=h.getHistogram(image);

    for(int i=0; i<256; i++) {
        cout<<"Value "<< i << " = " << histo.at<float>( i )<<endl;
    }
}
Ejemplo n.º 3
0
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();
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
int main()
{
    VideoCapture cap(1);
    cap.set(CV_CAP_PROP_FRAME_WIDTH,640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT,480);
    if(!cap.isOpened())
        return -1;
    Mat edges, dst, color_dst,gredst;
    CvMemStorage* storage =NULL;
    IplImage* img = NULL;
    for(;;)
    {
        Mat frame;
        cap >> frame;
        edges = frame;
        cvtColor(frame, gredst, CV_BGR2GRAY);
        cvtColor(frame, dst, CV_BGR2GRAY);
        vertx1.clear();
        vertx2.clear();
        vertx3.clear();
        vertx4.clear();
        Mat bgr[3];
        split(edges, bgr);
        Histogram1D h;
        MatND histo = h.getHistogram(bgr[0]);



        colorSegmentation(edges, dst);
        colorSegmentation1(edges,gredst);
        //imshow("rectanger", dst);
        //Houghlinesp
        //GaussianBlur(dst, dst, Size(7,7),1.5,1.5);

        cvtColor( dst, color_dst, CV_GRAY2BGR );

        //Canny( dst, dst, 60, 180, 3 );
        //for(int i = 0; i < 1; i++)GaussianBlur(dst, dst, Size(7,7),3,3);

        //double
        /*vector<Vec4i> lines;


        //cvShowImage("Transform",&img);


        HoughLinesP( dst, lines, 1, CV_PI/180, 60, 30, 0);



        for( size_t i = 0; i < lines.size(); i++ )
        {
            double theta = atan( fabs(lines[i][3] - lines[i][1]) / fabs(lines[i][2] - lines[i][0]));
            if (fabs(theta - CV_PI / 2) < CV_PI/180 * 6 || fabs(theta) < CV_PI/180 * 6)
            {
                line( color_dst, Point(lines[i][0], lines[i][1]),
                      Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
            }

        }*/



        //Canny(edges, edges,0,90,3);
        imshow("init graph", edges);
        //imshow("rectanger", dst);

        // 转换成opencv1.x处理

        //IplImage img0(dst);
        pyrUp(dst,dst,Size(dst.cols*2,dst.rows*2));
        pyrDown(dst,dst,Size(dst.cols/2,dst.rows/2));
        pyrUp(gredst,gredst,Size((gredst.cols)*2,(gredst.rows)*2));
        pyrDown(gredst,gredst,Size((gredst.cols)/2,(gredst.rows)/2));


        IplImage img0 = IplImage(dst);
        IplImage img1 = IplImage(gredst);
        img = &img0;
        //img = &IplImage(dst);
        //cvShowImage("Transform",img);
        storage = cvCreateMemStorage(0);
        drawSquares( img, findSquares4( img, storage ) );
        img = &img1;
        storage = cvCreateMemStorage(0);
        drawSquares1( img, findSquares4( img, storage ) );



        //imshow("rectanger_line", color_dst);
        //imshow("qq", dst);
        char c= waitKey(33);
        if(c==27)  break;
    }
}
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;
}
Ejemplo n.º 7
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;
}