Ask Your Question

lyw8120's profile - activity

2020-01-17 13:49:56 -0600 received badge  Famous Question (source)
2018-11-14 16:36:11 -0600 received badge  Notable Question (source)
2018-05-29 14:33:46 -0600 received badge  Popular Question (source)
2017-11-17 10:27:11 -0600 received badge  Supporter (source)
2017-08-12 03:59:21 -0600 commented answer mat output different in different data type

I am too stupid.

2017-08-12 03:58:20 -0600 received badge  Scholar (source)
2017-08-12 03:40:47 -0600 asked a question mat output different in different data type

I am confusing on the output of Mat. I tried to print the elements on the terminal using different data type, but result vary.

this is code

        Mat rowMean;
    rowMean = Mat::zeros(1, 10, CV_32F);


    for (int i=0; i<rowMean.cols; i++)
    {
            std::cout<<rowMean.at<int>(1,i)<<" ";
    }
    std::cout << std::endl;

    std::cout<<rowMean<<std::endl;

while the result is vary

65 0 1956498344 32527 1956498344 32527 0 0 0 0 
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

that is interesting, could anyone tell me what is going on? thank you.

2017-06-22 13:30:38 -0600 received badge  Taxonomist
2016-01-17 13:56:47 -0600 commented question segmentation fault

you are right the return value is 0, means it is CV_8U. I will check the input image, it is strange, becuase I thought I already have converted it to CV_32FC1.

2016-01-17 10:45:02 -0600 asked a question segmentation fault

this code can work the image size 256x256, but not work on 4096x4096. I really confuse where get problem. the img.at<float>(i,j) should not access invalid memory address.

    void dustHighValue(Mat & img, float & sigma)
{
    int m = img.rows;
    int n = img.cols;
    copyMakeBorder(img, img,2, 2, 2, 2, BORDER_CONSTANT, Scalar::all(0));
    Mat tmp;
    Scalar meanValue, stdValue;
    for ( int i=2; i<img.rows-2; ++i)
        for( int j=2; j<img.cols-2; ++j)
        {
            tmp=img(Rect(i-1,j-1,3,3));
            meanStdDev(tmp, meanValue, stdValue);
            if( img.at<float>(i,j) > (sigma * stdValue[0] + meanValue[0]))  
            {   
                img.at<float>(i,j) = meanValue[0];
            }
        }

    img=img(Rect(2,2,n,m));

}
2015-12-18 09:14:04 -0600 received badge  Enthusiast
2015-12-15 04:25:46 -0600 commented question opencv-2.4.6.1-1 and qt5 and qtcreator-2.8.0

No, it still does not work

2015-12-14 09:44:06 -0600 asked a question Qt5 + opencv invalid pointer

Dear all, I spent the whole day to solve a weird problem. Qt5 and opencv can work independently.

when I put opencv code into the qtcreater, bugs come.

* Error in `/home/think/QtProject/build-opencv-test2-Desktop-Debug/opencv-test2': realloc(): invalid pointer: 0x00000032c5eed840 *

======= Backtrace: =========

/usr/lib64/libc.so.6[0x36b0077d9e] /usr/lib64/libc.so.6(realloc+0x290)[0x36b00845d0] /usr/lib64/libQt5Core.so.5(_ZN9QListData7reallocEi+0x1f)[0x3d24f0a3ef] /usr/lib64/libQt5Core.so.5(_ZN9QListData6appendEi+0x6e)[0x3d24f0a4ae] /usr/lib64/libQt5Core.so.5[0x3d24fdb474] /usr/lib64/libQt5Core.so.5(_Z21qRegisterResourceDataiPKhS0_S0_+0x326)[0x3d24fd7596] /usr/lib64/libQt5Core.so.5[0x3d24e7a333] /lib64/ld-linux-x86-64.so.2[0x36afc0ff2a] /lib64/ld-linux-x86-64.so.2[0x36afc1003b] /lib64/ld-linux-x86-64.so.2[0x36afc00d2a]

======= Memory map: ========

00400000-00405000 r-xp 00000000 fd:02 14286978 /home/think/QtProject/build-opencv-test2-Desktop-Debug/opencv-test2 00604000-00605000 r--p 00004000 fd:02 14286978 /home/think/QtProject/build-opencv-test2-Desktop-Debug/opencv-test2 00605000-00606000 rw-p 00005000 fd:02 14286978 /home/think/QtProject/build-opencv-test2-Desktop-Debug/opencv-test2 01610000-01652000 rw-p 00000000 00:00 0 [heap]

I thought it was the problem of finding the correct position of opencv libs, and tried to use differrent way,all of them did not work.

LIBS += pkg-config opencv --libs

LIBS += -L /usr/local/lib/libopencv_core.so \

    /usr/local/lib/libopencv_imgproc.so \

    /usr/local/lib/libopencv_highgui.so

LIBS += -L/usr/local/lib

LIBS += -lopencv_core

LIBS += -lopencv_imgproc

LIBS += -lopencv_highgui

it was caused by the Qt, conflict by different Qt version.

2015-12-14 09:09:45 -0600 commented question opencv-2.4.6.1-1 and qt5 and qtcreator-2.8.0

I have the same problem, it is very strange. I do not know where is going wrong. could you tell me? Here I cannot post the pro file, it is unformat.

2015-01-20 08:03:26 -0600 commented question type wrong?

img was a power spectrum image, and its type is float. I tried to calculate radial average.

yes, I initialized the array Mat M(MaxRadius, 3, CV_32F, Scalar::all(0)); Mat_<float> & average_p = (Mat_<float>&) M;

2015-01-20 04:52:45 -0600 asked a question type wrong?
    int r = img.rows;
int c = img.cols;
int MaxRadius=0;
int radius_p = 0;
r > c ? MaxRadius=c/2 : MaxRadius = r/2;
int MaxRadius_p = MaxRadius*MaxRadius;
Mat M(MaxRadius, 3, CV_32F, Scalar::all(0));
Mat_<float> & average_p = (Mat_<float>&) M;
    for (auto i=0; i<r; ++i)
for(auto j=0; j<c; ++j)
    {                   
        radius_p = std::pow((i-r/2),2)+std::pow((j-c/2),2);
        if(img.at<Vec2f>(i,j)[1] != 1 && radius_p <=MaxRadius_p)
        {
            average_p(radius_p, 0) += img.at<Vec2f>(i,j)[0];
            average_p(radius_p, 1) += 1;

        }
        else
        continue;
    }

I want to calculate the sum and count the number of pixels in an image. but it is very strange, I cannot count the number of pixels.

average_p(radius_p, 1) += 1;

this code did not work, I print them on the terminal, it shows a huge number, like this. 4.7146e+11 4.82613e+11 3.06337e+11 6.53814e+11 5.3117e+11 5.24466e+11 2.63879e+10 7.74249e+10

2014-07-23 04:47:25 -0600 asked a question dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space.

when I do fourier transform on the result image, I find they are not zero, but lower value.

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

/////////////////////

I think there is a problem on DFT.

step 1. do some operation in fourier space(fig.1 is the amplitude of it).

step 2. dft back to real space

dft(clean_sf,clean_sf,DFT_INVERSE|DFT_REAL_OUTPUT);

step 3. dft back to fourier space and generate the amplitude spectrum(fig. 2)

void FftOperation(Mat & img, Mat & complexI){ 
Mat padded;                           
int m = getOptimalDFTSize( img.rows );
int n = getOptimalDFTSize( img.cols ); 
copyMakeBorder(img, padded, 0, m - img.rows, 0, n - img.cols, BORDER_CONSTANT, Scalar::all(0));


padded = Mat_<float>(padded);
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};  
merge(planes, 2, complexI);         

dft(complexI, complexI);            
complexI = complexI(Rect(0, 0, complexI.cols & -2, complexI.rows & -2));

SwitchQua(complexI);

}

void ShowMagnitude(string WindowName,Mat img) {

Mat planes[] = { Mat::zeros(img.size(),CV_32F), Mat::zeros(img.size(), CV_32F) };   

 //split 
split(img,planes);

//magintude
magnitude(planes[0],planes[1],planes[0]);
Mat magI = planes[0];

magI += Scalar::all(1);
log(magI,magI);

normalize(magI, magI, 0, 1, CV_MINMAX);
imshow(WindowName, magI);
Mat saveImg;
magI.convertTo(saveImg, CV_8UC1,255);
imwrite(WindowName+".tif", saveImg);

}

fig.1 and fig.2 should the same. but it different.I mean the part out of circle in fig.2 should be zero, just like fig.1. but it is not.

fig.1 image description

fig.2 image description

2013-05-23 05:18:50 -0600 commented answer corrupted double-linked list

m represent horizontal and n for vertical (m = i -2; n = j-2), while i will go through image rows and j for image cols. That also puzzled me for a day. anyway, thank you.

2013-05-23 03:04:03 -0600 commented answer corrupted double-linked list

there is only the memory problem( type problem as you said) and thank you very much. This error let me understood type deeply.

By the way, you know why the result image is rotated to compare the original image when I processed in the main function (the main function above, but the problem is here, I think the problem about the variables "i", "j", "m", "n")?

2013-05-22 12:39:51 -0600 commented question corrupted double-linked list

I have uploaded my code, and hope this can help you find the bug. Thanks

2013-05-22 07:24:20 -0600 commented question corrupted double-linked list

they are try to remove the background of image. their definitions show as follow: void mv_background_aveage(Mat & img) void mv_background_rotation(Mat & img)

2013-05-22 00:11:38 -0600 edited question corrupted double-linked list

I have a problem which probably is the memory problem, but I do not where is error and how to solve it. the code is followed.

when removed the two lines code

mv_background_average(image); mv_background_rotation(image);

it can work, I still can not find the bug.

please help me to check it and tell me what happened. Thanks a lot.

int main (int argc, char * argv[])
{
   string filename = string(argv[1]);
   Mat image = imread(filename.c_str(),0);
   mv_background_average(image);
   mv_background_rotation(image);
   int r = image.rows;
   int c = image.cols;
   int k=0; 
   Mat_<uchar> dst(r,c);
   for (int i=3; i<r-3; ++i)
     for (int j=3; j<c-3; ++j)
      {
        int m = i-2;
        int n = j-2;
        double maxval;
        Rect roi(m,n,5,5);

       Mat temp(image,roi);
       minMaxLoc(temp,0,&maxval,0,0);
          if ((maxval >= 100) && (image.at<uchar>(i,j) == maxval))
            {
               dst(i,j) == 255;
               cout << temp << " ";
               k++;
            }
       }
        cout << k <<endl;
  return 0;
  }

void mv_background_average(Mat & img)
{
    int r = img.rows;
    int c = img.cols;
    int length =  r/4;
    int r2 =  3*r/8;
    int c2 =  3*c/8;

    Scalar mean, stddev;
    Mat RoiA(img,Rect(r2,c2,length,length));
    meanStdDev(RoiA,mean,stddev);
    float m = mean.val[0];
    float std = stddev.val[0];
    int threshold = ceil(m + 2 * std);

    for (int i = 0; i<r ; ++i)
     { 
      ushort *  data = img.ptr<ushort>(i);
      for (int j = 0; j<c; ++j)
         {
             if(data[j] <= threshold) { data[j] = 0;}
         }
     }
}

void mv_background_rotation(Mat & img)
{
    int r = img.rows;
    int c = img.cols;
    int max_radius = 0;
    int radius = 0;

    r > c ? max_radius = c/2 : max_radius = r/2;

    Mat rotation_sum(max_radius,3,CV_32FC1,Scalar::all(0));

   for (int i = 0; i< r; ++i)
   {
       ushort * data = img.ptr<ushort>(i);
       for (int j = 0; j<c; ++j)
          {
             radius = round(sqrt((i-r/2)*(i-c/2) + (j-r/2)*(j-c/2)));
             if (radius <= max_radius)
              { 
                rotation_sum.at<float>(radius,0) += data[j];
                rotation_sum.at<float>(radius,1) += 1;
              }

          }
   }



  for (int i=0; i<=max_radius; ++i)
  {
     rotation_sum.at<float>(i,2) = rotation_sum.at<float>(i,0) / rotation_sum.at<float>(i,1);
  }    

  for (int i = 0; i< r; ++i)
   {
       ushort * data = img.ptr<ushort>(i);
       for (int j = 0; j<c; ++j)
          {
             radius = round(sqrt((i-r/2)*(i-c/2) + (j-r/2)*(j-c/2)));
             int mean = ceil(rotation_sum.at<float>(radius,2));
             if (radius <= max_radius && data[j] <= 4*mean)
              { 
                data[j] = 0;
              }

          }
   }

}

image description

2013-05-22 00:10:20 -0600 received badge  Editor (source)