Ask Your Question
0

How to scan line by line in an image array

asked 2017-02-02 23:29:42 -0600

zms gravatar image

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 flag offensive close merge delete

Comments

May be this will be helpful

sturkmen gravatar imagesturkmen ( 2017-02-03 08:24:57 -0600 )edit

you can use this method too

LBerger gravatar imageLBerger ( 2017-02-03 08:26:46 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-02-03 04:48:16 -0600

kieranfish gravatar image

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();
    }
}
edit flag offensive delete link more

Comments

is checkforbinary(); is a predefined function?

zms gravatar imagezms ( 2017-02-08 03:23:54 -0600 )edit
0

answered 2017-02-03 08:20:50 -0600

updated 2017-02-03 08:21:28 -0600

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

edit flag offensive delete link more

Comments

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

zms gravatar imagezms ( 2017-02-07 04:45:17 -0600 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2017-02-07 04:55:26 -0600 )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.

zms gravatar imagezms ( 2017-02-08 03:16:59 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,356 times

Last updated: Feb 03 '17