vignetting correction

asked 2020-07-01 03:02:21 -0600

snehal gravatar image

updated 2020-07-17 04:22:47 -0600

Hello,

I want to do a 16bit image vignetting correction. I attached my code below. when I run this code the output image is not as expected(It should be vignetting free image). I am not getting where I m going wrong or something is missing please help me to find a solution.

#include<iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <fstream>

using namespace std;
using namespace cv;

void mult(double *m1,double *m2,double *result,int i_1,int j_12,int j_2)
{
    int i,j,k;
    for(i=0;i<i_1;i++)
        for(j=0;j<j_2;j++)
        {
            result[i*j_2+j]=0.0;

            for(k=0;k<j_12;k++)
                result[i*j_2+j] += m1[i*j_12+k]*m2[j+k*j_2];
        }
    return;
}

/*Matrix Inverse*/
int invers_matrix(double *m1,int n)
{ 
    int *is,*js;
    int i,j,k,l,u,v;
    double temp,max_v;
    is=(int *)malloc(n*sizeof(int));
    js=(int *)malloc(n*sizeof(int));
    if(is==NULL||js==NULL)
    {
        printf("out of memory!\n");
        return(0);
    }
    for(k=0;k<n;k++)
    {
        max_v=0.0;
        for(i=k;i<n;i++)
            for (j = k; j < n; j++)
            {
                temp = fabs(m1[i*n + j]);
                if (temp > max_v)
                {
                    max_v = temp; is[k] = i; js[k] = j;
                }
            }
        if(max_v==0.0)
        {
            free(is); free(js);
            printf("invers is not availble!\n");
            return(0);
        }
        if(is[k]!=k)
        {
            for (j = 0; j<n; j++) 
            {
                u = k*n + j; v = is[k] * n + j;
                temp = m1[u]; m1[u] = m1[v]; m1[v] = temp;
            }
        }

        if(js[k]!=k)
        {
            for (i = 0; i<n; i++) {
                u = i*n + k; v = i*n + js[k];
                temp = m1[u]; m1[u] = m1[v]; m1[v] = temp;
            }
        }

        l=k*n+k;
        m1[l]=1.0/m1[l];
        for(j=0;j<n;j++)
        if(j!=k)
        {
            u=k*n+j;
            m1[u]*=m1[l];
        }
        for (i = 0; i < n; i++)
        {
            if (i != k)
                for (j = 0; j < n; j++)
                    if (j != k)
                    {
                        u = i*n + j;
                        m1[u] -= m1[i*n + k] * m1[k*n + j];
                    }
        }
        for(i=0;i<n;i++)
        {
            if (i != k)
            {
                u = i*n + k;
                m1[u] *= -m1[l];
            }
        }

    }
    for(k=n-1;k>=0;k--)
    {
        if(js[k]!=k)
        {
            for (j = 0; j<n; j++) {
                u = k*n + j; v = js[k] * n + j;
                temp = m1[u]; m1[u] = m1[v]; m1[v] = temp;
            }
        }

        if(is[k]!=k)
        {
            for (i = 0; i<n; i++) {
                u = i*n + k; v = i*n + is[k];
                temp = m1[u]; m1[u] = m1[v]; m1[v] = temp;
            }
        }

    }
    free(is); 
    free(js);
    return(1);
}
/*Matrix Transpose*/
void transpose(double *m1,double *m2,int m,int n)
{ 
    int i,j;
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            m2[j*m+i]=m1[i*n+j];
    return;
}

int VignettingCorrectionUsingRG_16bit(unsigned short* pImage, int ht, int wd, vector<double>& vp)
{
    ofstream myfile;
    myfile.open("E:\\Vignetting_image\\vig_vector_16bit_.txt");
    int halfWd = wd*0.5;
    int halfHt = ht*0.5;

    int nRadius = sqrt(double(halfHt*halfHt ...
(more)
edit retag flag offensive close merge delete

Comments

1

please show your code here, not someone elses github ... thank you.

berak gravatar imageberak ( 2020-07-17 01:27:39 -0600 )edit

its not working properly.

that's a very poor description

berak gravatar imageberak ( 2020-07-17 03:48:07 -0600 )edit
2

mul(), invert(), transpose() are all builtin opencv functions. don't reinvent the wheel

berak gravatar imageberak ( 2020-07-17 04:07:16 -0600 )edit