I am currently working on a project in the field of medical technology. I have a large image with several sub-images of the cell, so my first task is to split the image.
I thought of the following:
Convert Image to Binary
projectes the brightness pixels onto the x axis, so I can see where there are gaps between the brightness values, and then split the image.
The problem arises when I try to reach the second part. My idea uses the vector as a projection and sums all the brightness values โโin one column, so the position number 0 of the vector is the sum of all the brightness values โโthat are in the first column of the image, the same until I get to the last column, therefore at the end I have a projection.
Here is how I tried:
void calculo(cv::Mat &result,cv::Mat &binary){ //result=the sum,binary the imag. int i,j; for (i=0;i<=binary.rows;i++){ for(j=0;j<=binary.cols;j++){ cv::Scalar intensity= binaria.at<uchar>(j,i); result.at<uchar>(i,i)=result.at<uchar>(i,i)+intensity.val[0]; } cv::Scalar intensity2= result.at<uchar>(i,i); cout<< "content" "\n"<< intensity2.val[0] << endl; } }
While executing this code, I have a violation error. Another problem is that I cannot create a matrix with one unique row, so ... I do not know what I could do.
Any ideas ?! Thanks!
In the end, this will not work, I need to sum all the pixels in one COLUMN. I did:
cv::Mat suma(cv::Mat& matrix){ int i; cv::Mat output(1,matrix.cols,CV_64F); for (i=0;i<=matrix.cols;i++){ output.at<double>(0,i)=norm(matrix.col(i),1); } return output; }
but this gave me an error: Assertion failed (0 <= colRange.start & colRange.start <= colRange.end & colRange.end <= m.cols) in Mat, file / home / usuario / OpenCV-2.2. 0 / modules / core / src / matrix.cpp, line 276
I donโt know, any idea would be useful, anyway, thanks mevatron, you really left me on the way.