Beispiel #1
0
void BasicSonar::createAccumulatedShadowAndNoise(int horizontal_scans, int vertical_scans, int pixels_per_line,
        std::vector<double> noise_percentage, std::vector<double>* result)
{
    for (int i=0; i < horizontal_scans; i++)
    {
        int accumulated_num_of_rays = 0;
        for (int j=0; j < pixels_per_line; j++)
        {
            if (noise_percentage.at(i*pixels_per_line + j) > 0)
            {
                accumulated_num_of_rays += noise_percentage.at(i*pixels_per_line + j);
                result->at(i*pixels_per_line + j) += gaussianNoise(0,gaussian_kernel);
            }
            else if (result->at(i*pixels_per_line + j) == 0)
            {
                result->at(i*pixels_per_line + j) = ( 1 - (accumulated_num_of_rays/ (double) vertical_scans)) * base_water_noise + gaussianNoise(0,gaussian_kernel);
            }
            else
            {
                result->at(i*pixels_per_line + j) += gaussianNoise(0,gaussian_kernel);
            }
        }
    }
}
void convertImages(Arguments* args){
    char** mask = NULL;
    TwoPoints source, dest;
    FILE* eyeList;
    char line[ FILE_LINE_LENGTH ];
    char filename[MAX_FILENAME_LENGTH];
    char imagename[MAX_FILENAME_LENGTH];
    char suffix[MAX_FILENAME_LENGTH];
    int i;

    scaleArgs(args, args->scale);

    dest.x1 = args->eyeLx;
    dest.y1 = args->eyeLy;
    dest.x2 = args->eyeRx;
    dest.y2 = args->eyeRy;

    /* Prepare file suffix encoding preprocessing settings, blank if not requested */
    if (args->configSuffix) {
        sprintf(suffix,"_%s", imageSuffix(args)); }
    else {
        suffix[0] = '\0'; }	

    if(args->maskType == CL_YES){
        MESSAGE("Creating Mask.");
        mask = generateMask(args->sizeWidth, args->sizeHeight, args->ellipseX, args->ellipseY, args->ellipseA, args->ellipseB);
    }

    eyeList = fopen(args->eyeFile,"r");
    DEBUG_CHECK(eyeList,"Error opening eye coordinates file");

    for(i = 1;;i++){
        Image pgm;
        Image geo;
        Matrix transform;

        fgets(line, FILE_LINE_LENGTH, eyeList);
        if(feof(eyeList)) break;

        if(sscanf(line,"%s %lf %lf %lf %lf",filename, &(source.x1), &(source.y1), &(source.x2), &(source.y2)) != 5){
            printf("Error parsing line %d of eye coordinate file. Exiting...",i);
            exit(1);
        }

        /* shift the eye coordinates if neccessary */
        source.x1 += args->shiftX;
        source.y1 += args->shiftY;
        source.x2 += args->shiftX;
        source.y2 += args->shiftY;

        sprintf(imagename,"%s\\%s.pgm",args->inputDir,filename);

        MESSAGE1ARG("Processing image: %s",filename);

        pgm = readPGMImage(imagename);

        if(args->histType == HIST_PRE){
            DEBUG(1,"   Performing Pre Histogram Equalization.");
            histEqual(pgm,256);
        }

        if(args->preNormType == CL_YES){
            DEBUG(1,"   Performing Pre Pixel Normalization.");
            ZeroMeanOneStdDev(pgm);
        }

        if(args->preEdge){
            smoothImageEdge(pgm, args->preEdge);
        }

        if(args->geoType == CL_YES){
            DEBUG(1,"   Performing Geometric Normalization.");
            transform = generateTransform(&source,&dest,args->reflect);
            geo = transformImage(pgm,args->sizeWidth,args->sizeHeight,transform);
        }
        else{
            transform = makeIdentityMatrix(3);
            geo = transformImage(pgm,args->sizeWidth,args->sizeHeight,transform);
        }

        if(args->noise != 0.0){
            DEBUG(1,"   Adding Gausian Noise.");
            gaussianNoise(geo,args->noise);
        }


        if(args->histType == HIST_POST){
            DEBUG(1,"   Performing Post Histogram Equalization.");
            histEqualMask(geo,256, (const char**) mask);
        }

        if(args->nrmType == CL_YES){
            DEBUG(1,"   Performing final value normalization and Applying Mask.");
            ZeroMeanOneStdDevMasked(geo, (const char **) mask);
        }
        else{
            DEBUG(1,"   No Value Normalization. Just Applying Mask.");
            applyMask(geo, (const char **) mask);
        }

        if(args->postEdge){
            smoothImageEdge(geo, args->postEdge);
        }

        if(args->nrmDir){
            sprintf(imagename,"%s\\%s%s.nrm", args->nrmDir, filename, suffix);
            DEBUG_STRING(1,"   Saving nrm: %s",imagename);
            writeFeretImage(geo,imagename);
        }
        if(args->pgmDir){
            sprintf(imagename,"%s\\%s%s.pgm", args->pgmDir, filename, suffix);
            DEBUG_STRING(1,"   Saving pgm: %s",imagename);
            writePGMImage(geo,imagename,0);
        }
        if(args->sfiDir){
            sprintf(imagename,"%s\\%s%s.sfi", args->sfiDir, filename, suffix);
            DEBUG_STRING(1,"   Saving sfi: %s",imagename);
            writeRawImage(geo,imagename);
        }

        freeImage(geo);
        freeImage(pgm);
        freeMatrix(transform);
    }

    fclose(eyeList);

}
Beispiel #3
0
int main(void)
{
	

	// 讀圖
	cv::Mat mImg = cv::imread("lena.bmp", cv::IMREAD_GRAYSCALE);

	// 防止找不到圖
	if (mImg.empty())
	{
		std::cout << "Not Found!" << std::endl;
		exit(EXIT_FAILURE);
	}

	// 宣告空間
	cv::Mat oriImg = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat gauImg = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);

	cv::Mat Gaussian = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat GaussianNoise = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);

	cv::Mat SP = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat SPNoise = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);

	cv::Mat Uniform = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat UniformNoise = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);

	cv::Mat AFilter = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat Adaptive = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	
	cv::Mat SAdaptive = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat UAdaptive = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);
	cv::Mat Gdaptive = cv::Mat::zeros(mImg.rows, mImg.cols, CV_8UC1);


	int histogram[256] = { 0 };
	int hisGaussian[256] = { 0 };
	int hisSP[256] = { 0 };
	int hisUniform[256] = { 0 };
	int hisA[256] = { 0 };
	int hisB[256] = { 0 };
	int hisC[256] = { 0 };
	char windowname[] = { 0 };


	// gaussianNoise(oriImg, gauImg, amp);
	// gaussianNoise(mImg, GaussianNoise);
	spNoise(mImg, SPNoise, hisSP);
	uniformNoise(mImg, UniformNoise, hisUniform);
	gaussianNoise(mImg, GaussianNoise, hisGaussian);
	//AdaptivefFilter(mImg, Adaptive, hisA);
	AdaptivefFilter(SPNoise, SAdaptive, hisB);
	AdaptivefFilter(UniformNoise, UAdaptive, hisC);
	AdaptivefFilter(GaussianNoise, Gdaptive, hisA);



	
	// 叫圖

	histDisplay(hisUniform, "hisUniform");
	histDisplay(hisSP, "hisSP");
	histDisplay(hisGaussian, "hisGaussian");
	//histDisplay(histogram, "histogram");
	histDisplay(hisA, "hisA");

	
	cv::namedWindow("LenaOutputOne", cv::WINDOW_AUTOSIZE);
	cv::imshow("LenaOutputOne", mImg);

	cv::namedWindow("GaussianOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("GaussianOut", GaussianNoise);

	cv::namedWindow("SPOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("SPOut", SPNoise);

	cv::namedWindow("UniformOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("UniformOut", UniformNoise);

	cv::namedWindow("UniformOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("UniformOut", UniformNoise);

	cv::namedWindow("SAdaptiveOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("SAdaptiveOut", SAdaptive);

	cv::namedWindow("UAdaptiveOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("UAdaptiveOut", UAdaptive);

	cv::namedWindow("GAdaptiveOut", cv::WINDOW_AUTOSIZE);
	cv::imshow("GAdaptiveOut", Gdaptive);

	




	cv::waitKey(0);
	return 0;
}