How to make such construction return values form 0 to 1?

房东的猫 提交于 2019-12-25 06:26:38

问题


It give me only 1s

        int maxVal;
        int minVal;
        int wh = w*h;
        int values[1000];
        for(x=0;x<w;x++){
            for(y=0;y<h;y++){
                double RealColor = cvGetReal2D(source, y, x);
                values[x*y + y] = RealColor; 
            }
        }
        minVal = *min_element(values,(values+wh));
        maxVal = *max_element(values,(values+wh));
        float dif = maxVal - minVal;
        float fminVal;
        fminVal = minVal;
        for(x=0;x<w;x++){
            for(y=0;y<h;y++){
                float rc = cvGetReal2D(source, y, x);
                float normRealColor =(rc - fminVal + 1) / dif;
                file << normRealColor << " ";
            }
            file << endl;
        }file << endl;

How to make it to return not only 1 or 0 but 0, 0.1 0.001 ... 1 HOW??? wall


回答1:


The values array is an array of int, so it can only contain integers rather than floating-point numbers. Does changing it to float or double fix the problem? Also, your indexing expression x*y + y is incorrect: it should be x*h + y or w*y + x.



来源:https://stackoverflow.com/questions/4918437/how-to-make-such-construction-return-values-form-0-to-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!