如何使这样的结构返回值从0到1? [英] How to make such construction return values form 0 to 1?

查看:117
本文介绍了如何使这样的结构返回值从0到1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它只给我1秒

        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;

如何让它不仅返回1或0,而是返回0,0.1 0.001 ... 1 ???

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

推荐答案

values int 的数组,因此它只能包含整数而不是浮点数。将其更改为 float double 可以解决问题吗?此外,您的索引表达式 x * y + y 不正确:应该是 x * h + y w * y + x

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.

这篇关于如何使这样的结构返回值从0到1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆