Mat initModify::getImageTri(Mat & sourceImage) {
	// create the same size of the source image. 
	Mat resultImage(sourceImage.rows, sourceImage.cols, sourceImage.type(), CV_RGB(255, 0, 0));

	// get the image which has been histogram equalization..
	histogramImage = histogramEqualization(sourceImage);
	tempImage = histogramImage.clone();

	// show the window and set the listener of the mouse click..
	namedWindow(winName, WINDOW_AUTOSIZE);
	imshow(winName, tempImage);
	setMouseCallback(winName, onMouseClickToGetTri, this);
	waitKey();

	// on the result image, draw the basic boundary green color ....
	myDraw::fillPoly(resultImage, outerPoint, CV_RGB(0, 255, 0));

	// establish the image which is used for grab cut..
	cutImage = Mat::zeros(sourceImage.size(), CV_8UC1);
	myDraw::fillPoly(cutImage, outerPoint, Scalar(GC_PR_FGD));

	// of course, fill the inner site blue color...
	myDraw::fillPoly(resultImage, innerPoint, CV_RGB(0, 0, 255));
	myDraw::fillPoly(cutImage, innerPoint, Scalar(GC_FGD));

	innerPoint.clear();
	outerPoint.clear();

	modifyCutAndHistogram(cutImage, histogramImage);
	destroyWindow(winName);

	winName = "grabcut";
	namedWindow(winName, WINDOW_AUTOSIZE);
	imshow(winName, tempImage);

	// use grab cut to get the real boundary...

	isMouseDwon = false;
	setMouseCallback(winName, onMouseClickToCut, this);
	waitKey();
	destroyWindow(winName);
	// send the result back to the result image..
	int nRows = resultImage.rows, nCols = resultImage.cols, nChannels = resultImage.channels();
	for (int i = 0; i < nRows; i++) {
		uchar * u = resultImage.ptr<uchar>(i);
		uchar * cut = cutImage.ptr<uchar>(i);
		for (int j = 0; j < nCols; j++) {
			if (u[j * nChannels] == 0 && u[j * nChannels + 1] == 255 && u[j * nChannels + 2] == 0) {
				if (cut[j] == GC_FGD || cut[j] == GC_PR_FGD) {
					u[j * nChannels] = 255;
					u[j * nChannels + 1] = 0;
					u[j * nChannels + 2] = 0;
				}
			}
		}
	}
	return resultImage;
}
示例#2
0
void MainWindow::equalization()
{	
	Histogram hist(image);
	histogram = hist.getImage();
	
	image = histogramEqualization(image,hist);
	
	setImages();
}
示例#3
0
int HistogramEqualization::Process(uchar* bitmap, size_t n, QVector<QString> argv)
{
    if(!bitmap)
        return 1;
    QSize imgSize;
    imgSize.setHeight(argv.at(1).toInt());
    imgSize.setWidth(argv.at(2).toInt());

    histogramEqualization(bitmap, n, imgSize);
    return 0;
}
示例#4
0
void Image::writeAsHDRPPM2(const char *outputFile){	
	unsigned char *img_out = new unsigned char [width*height*numComponents];
	#if ADAPTIVE == 0
	float cdf[L]={0.0};
	uint n;
	uint hist[L] = {0};
	
	for(uint i = 0; i < height; ++i)
		for(uint j = 0; j < width; ++j){
			uint index = (i*width+j)*numComponents;
			float gray_scale =  sqrt( 0.241*pow(buffer[index],2) + 0.691*pow(buffer[index+1],2) + 0.068*pow(buffer[index+2],2) );
			gray_scale *= (float) (L-1);
			hist[(uint) gray_scale]++;
	}



	n = width * height;

	cdf[0] = (float) hist[0]/(float)n;;
	
	for (uint i = 1; i < L; ++i){
		cdf[i] = cdf[i-1] + (float)hist[i]/(float)n;
	}	

	for(uint i = 0; i < height; ++i)
		for(uint j = 0; j < width; ++j)
			for(uint k = 0; k < numComponents; ++k){
			uint index = (i*width+j)*numComponents + k;
	 		float hi = buffer[index]*(L-1);
			float res = (float) cdf[(uint) hi] * 255.0f;
			if (res > 255.0f){
				res = 255.0f;
			}
	 		img_out[index] = (unsigned char)(res);
	}

	#else
	for(uint i = 0; i < height; ++i)
		for(uint j = 0; j < width; ++j){
			histogramEqualization(&img_out, i, j, W_SIZE, (*this).width, (*this).height);		
	}
	#endif
	WritePNM(outputFile, width, height, numComponents, img_out);
	delete img_out;

}