Question

I have a matlab code in which the image x has 512*512 size were M=512 and N=512 next step is this

 r=x(:, 2:N) - x(:, 1:(N-1));
 d= mean2(abs(r(:, 8:8:8*(floor(N/8)-1))));
 a= (8*mean2(abs(r)) - d)/7;

Now I have to convert this steps in to opencv code so I am stuck with logic

 cv::Mat scrImage =imread(argv[1],CV_LOAD_IMAGE_ANYCOLOR); // Read the file 
 cv::Mat dst(scrImage.size(),CV_64FC3);//Image double
 int nrows = dst.rows;
 int ncols = dst.cols*dst.channels();
 for(int j=0;j<nrows;j++){
 for(int i=0;i<ncols;i++)
 {
}}

Any idea on this? Thanks in advance

Était-ce utile?

La solution

There are many ways to do this. Most clean way would be setting ROI (Region of Interest) and then applying matrix operations. Something like:

subtract(x(Rect(1,0,NumCols-1,NumRows)),x(Rect(0,0,NumCols-1,NumRows),R)
singleLineMask = Mat(1,NumCols,CV_8U)
for (int i=1;i<NumCols;i++)
    singleLineMask.at<int>(1,i)=1;
repeat(singleLineMask,NumRows,1,MaskImage)
d=mean(R,MaskImage)
a=(8*mean(abs(R))-d)/7

assuming you create R and compute NumRows,NumCols prior to this operation and allocate MaskImage.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top