Can't compute power of float point [closed]

asked 2013-09-25 15:17:14 -0600

GiulSDU gravatar image

updated 2013-09-25 15:59:09 -0600

Moster gravatar image

Hi, i have a Mat<float> image. After making the fourier spectrum of the image i have to apply a Butterworth filter of equation: H(u,v)=1/(1+[D(u,v)/250]⁴) where

D(u,v)=[(u-(image.col/2)²)+(v-(image.row/2)²))]^0.5

as you can see there are many power function in the image. My image is a Mat_<float>, so i suppose that the result of each computation should be a float, so i can change each pixel of the image with the result of the equation. Unfortuntely my code seems not to work , i have problems with the function pow..seems to work only for certain type.. here is my code

Mat_<float> filter;
    moon_spectrum.copyTo(filter);//giving the same dimentions

    for (int i=0;i<filter.cols;i++)
    {
        for (int j=0;j<filter.rows;j++)
        {
            float d_x=pow((i-filter.cols),2);
            float d_y=pow((j-filter.rows),2);
            float d=pow((d_x+d_y),2);
            float d_fin=pow((d/250),4);
            filter.at<float>(i,j)=1/(1+d_fin);



        }
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-24 01:11:30.563080

Comments

you got i and j reversed here:

filter.at<float>(i,j)=1/(1+d_fin); // should be filter.at<float>(j,i)

berak gravatar imageberak ( 2013-09-25 15:29:19 -0600 )edit

oh wait, you don't need pow for a simple euclidean distance, do you ? and then if you remove the sqrt, you already saved a power of two later

 float d_x = (i-filter.cols);
 float d_y  = (j-filter.rows);
 float d     = (d_x*d_x + d_y*d_y) / (250*250);
 float d_fin = d*d;
berak gravatar imageberak ( 2013-09-25 15:33:41 -0600 )edit