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

May be this will be helpful

( 2017-02-03 08:24:57 -0500 )edit

you can use this method too

( 2017-02-03 08:26:46 -0500 )edit

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

is checkforbinary(); is a predefined function?

( 2017-02-08 03:23:54 -0500 )edit

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?

( 2017-02-07 04:45:17 -0500 )edit

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

( 2017-02-07 04:55:26 -0500 )edit

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.

( 2017-02-08 03:16:59 -0500 )edit