Ask Your Question

Revision history [back]

//code for passing 1 channel image pixel values to a 2D array

//declare ,read,convert image to 32float

    Mat img,dst;
    img=imread("IMG.JPG");
    img.convertTo(dst, CV_32F);
    float arrOut[dst.rows][dst.cols];

//pass data to 2D array

    for(int i = 0 ;i < dst.rows; ++i)
        for(int j = 0; j < dst.cols; ++j)
            arrOut[i][j]=dst.at<float>(i,j);

//show the array

    for(int i = 0 ;i < dst.rows; ++i)
        for(int j = 0; j < dst.cols; ++j)
        {  cout<<arrOut[i][j]<<" ";
           if(j==(dst.cols-1))
                  cout<<endl;
        }