How to scan line by line in an image array

Hello, I have an small ROI (binary iamge) and i need to scan line by line to look on the value of the image pixels and plot it to either 1 or 0 in a graph. Is there any method which i can use to achieve this?

thanks

edit retag close merge delete

Sort by » oldest newest most voted

I'm not sure how to check for binary, but this works for scanning through each pixel.

for( int y=0; y< roi.rows; y+=1){
for (int x=0;x< roi.cols;x+=1){
checkforbinary();
}
}
more

If the image is binary (1 and 0 values, or 255 and 0 values), then you can use the function findNonZero() which gives you all pixels with a value, not equal to zero!

This is always more performant than going for a double for loop as suggested by @kieranfish

more

i had tried using this and did give me the binary coordinates and I should be able to plot for a 2D graph right?

Ofcourse, because you can now count the amount of pixels having a 0 and a non zero value.

I look back at the referred website, may i know what is the purpose of

Point pnt = locations.at<Point>(i);

cv::Mat binaryImage; // input, binary image
cv::Mat locations;   // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
// access pixel coordinates
Point pnt = locations.at<Point>(i);

after looking back the coordinates from the output as below, is the array can use ; instead of , . ? and this array size 2 X (how many line having a non zero pixel)? Output

location =
[0, 0;
1, 0;
6, 0;
7, 0;
8, 0;
9, 0;
0, 1;
1, 1;
2, 1;
3, 1;
4, 1;
5, 1;
6, 1;
7, 1;
8, 1;
9, 1]

as i want to plot a 2D line for each line pixel from 0 to 1 transition and not the total of zero vs non zero pixel.

Stats

Asked: 2017-02-02 23:29:42 -0500

Seen: 609 times

Last updated: Feb 03 '17