Example #1
0
File: e022.c Project: githubix/c
int main(){
    float data1, data2;
    
    data1 = 0.00006F;
    printf("data1 value = %f\n", data1);
    
    data2 = 1.23456F - 1.23450F;
    printf("data2 value = %f\n\n", data2);
    
    printf("data1 structure = ", data1);
    showFloat(data1);
    
    printf("data2 structure = ", data2);
    showFloat(data2);
    printf("\n");
    
    printf("data1 x 100000 = %f\n", data1 * 100000);
    
    printf("data2 x 100000 = %f\n\n", data2 * 100000);
    
    printf("1.23456 structure = ");
    showFloat(1.23456F);
    printf("1.23450 structure = ");
    showFloat(1.23450F);
    
    return 0;
}
Example #2
0
//align is optional
void SegDisp::showFloat(float num, int dec, int ms){
	showFloat(num,dec,ms,'R');
}
    void initKernel(Mat& kernel, const Mat& blurredGray, const int width, const Mat& mask, 
                    const int pyrLevel, const int iterations, float thresholdR, float thresholdS) {
        
        assert(blurredGray.type() == CV_8U && "gray value image needed");
        assert(mask.type() == CV_8U && "mask should be binary image");
        
        // #ifndef NDEBUG
        //     imshow("blurred", blurredGray);
        // #endif
        
        // save min and maximum value of the original image to be able to restore
        // the latent image with the correct brightness
        double grayMin; double grayMax;
        minMaxLoc(blurredGray, &grayMin, &grayMax);

        // build an image pyramid with gray value images
        vector<Mat> pyramid, masks;
        pyramid.push_back(blurredGray);
        masks.push_back(mask);

        for (int i = 0; i < (pyrLevel - 1); i++) {
            Mat downImage, downMask;
            pyrDown(pyramid[i], downImage, Size(pyramid[i].cols/2, pyramid[i].rows/2));
            pyrDown(masks[i], downMask, Size(masks[i].cols/2, masks[i].rows/2));

            pyramid.push_back(downImage);
            masks.push_back(downMask);
        }

        // init kernel but in the iterations the tmp-kernel is used
        kernel = Mat::zeros(width, width, CV_32F);
        Mat tmpKernel;

        // go through image pyramid from small to large
        for (int l = pyramid.size() - 1; l >= 0; l--) {
            #ifdef IMWRITE
                imshow("pyr Image", pyramid[l]);
                double min; double max;
                minMaxLoc(pyramid[l], &min, &max);
                cout << "pyr: " << min << " " << max << endl;
                waitKey();
            #endif

            // compute image gradient for x and y direction
            // 
            // gaussian blur (in-place operation is supported)
            GaussianBlur(pyramid[l], pyramid[l], Size(3,3), 0, 0, BORDER_DEFAULT);

            // parameter for sobel filtering to obtain gradients
            array<Mat,2> gradients, tmpGradients;
            const int delta = 0;
            const int ddepth = CV_32F;
            const int ksize = 3;
            const int scale = 1;

            // gradient x and y
            Sobel(pyramid[l], tmpGradients[0], ddepth, 1, 0, ksize, scale, delta, BORDER_DEFAULT);
            Sobel(pyramid[l], tmpGradients[1], ddepth, 0, 1, ksize, scale, delta, BORDER_DEFAULT);

            // cut off gradients outside the mask
            tmpGradients[0].copyTo(gradients[0], masks[l]);
            tmpGradients[1].copyTo(gradients[1], masks[l]);

            // normalize gradients into range [-1,1]
            normalizeOne(gradients);

            // #ifdef IMWRITE
            //     showGradients("x gradient", gradients[0]);
            //     showGradients("y gradient", gradients[1]);
            // #endif
            

            // compute gradient confidence for al pixels
            Mat gradientConfidence;
            computeGradientConfidence(gradientConfidence, gradients, width, masks[l]);

            // #ifdef IMWRITE
            //     showFloat("confidence", gradientConfidence);
            // #endif


            // each iterations works on an updated image
            Mat currentImage;
            pyramid[l].copyTo(currentImage);

            // assert(iterations == 1 && "Implement multiple iterations");

            for (int i = 0; i < iterations; i++) {
                #ifdef IMWRITE
                    imshow("current Image", currentImage);
                    minMaxLoc(currentImage, &min, &max);
                    cout << "current: " << min << " " << max << endl;
                    waitKey();
                #endif

                // select edges for kernel estimation (normalized gradients [-1,1])
                array<Mat,2> selectedEdges;
                selectEdges(currentImage, gradientConfidence, thresholdR, thresholdS, selectedEdges);

                #ifdef IMWRITE
                    showGradients("x gradient selection", selectedEdges[0]);
                    showGradients("y gradient selection", selectedEdges[1]);
                    minMaxLoc(selectedEdges[0], &min, &max);
                    cout << "x gradients: " << min << " " << max << endl;
                    waitKey();
                #endif


                // estimate kernel with gaussian prior
                fastKernelEstimation(selectedEdges, gradients, kernel, 0.0);

                #ifdef IMWRITE
                    showFloat("tmp-kernel", kernel, true);
                    minMaxLoc(kernel, &min, &max);
                    cout << "kernel: " << min << " " << max << " sum: " << sum(kernel)[0] << endl;
                    waitKey();
                #endif


                // coarse image estimation with a spatial prior
                Mat latentImage;
                // FIXME: it looks like there are some edges of the gradients in the latent image.
                //        with more iterations it becomes worse
                // coarseImageEstimation(pyramid[l], kernel, selectedEdges, latentImage);
                
                // use oother spatial deconv method for now
                deconvolveIRLS(pyramid[l], latentImage, kernel);

                #ifdef IMWRITE
                    string name = "two-phase-latent-" + to_string(i);
                    imshow(name, latentImage);
                    waitKey();

                    string filename = name + ".png";
                    imwrite(filename, latentImage);
                #endif


                // set current image to coarse latent image
                latentImage.copyTo(currentImage);

                // decrease thresholds τ_r and τ_s will to include more and more edges
                thresholdR = thresholdR / 1.1;
                thresholdS = thresholdS / 1.1;
            }

            // set next pyramid image to the upscaled latent image
            if (l > 0) {
                Mat upImage;
                pyrUp(currentImage, upImage, Size(pyramid[l - 1].cols, pyramid[l - 1].rows));
                pyramid[l - 1] = upImage;
            }
        }

        // #ifdef IMWRITE
        //     imshow("kernel", kernel);
        //     waitKey();
        // #endif
    }