Split a cv::mat into submats based on each containing a contour

asked 2020-06-09 04:32:51 -0600

samkro gravatar image

Hey Guys,

I'm trying to process an image, so that I can do some data analysis with it afterwards. As input I have an image with one or multiple bright spots. I use some filters to reduce noise and then use threshhold to get a binary image. Now I search for all Contours in this image and get the bounding Rectangles. So far no problem. It could look similar to this (but probably with more bright spots):

It could look similar to this (but probably with more bright spots)threshholded imagecontours with bounding rectangle

But now I have to split up the image, so that I can analyse the data with better accuracy. Therefore I want to split the whole cv::mat into several rectangular submatrizes, with each containing exactly one contour.

Do anyone have a idea how to do that? To be precise, I only need the start column/row and the end column/row of each submatrix.

For Example: With the given image it should split the image along the red line: result

Thank you in advance! :)

edit retag flag offensive close merge delete

Comments

So simple. Used Region Of Interest(ROI)

supra56 gravatar imagesupra56 ( 2020-06-09 05:22:13 -0600 )edit

@supra56 Thank you for your comment. I've found some information about ROI. But I still have a problem with it. It's easy to use ROI for exactly that image above. But I will get tons of those images and have to find the values for the ROI automatically. I think this is maybe more my problem...

samkro gravatar imagesamkro ( 2020-06-09 05:33:48 -0600 )edit

@samkro

have to find the values for the ROI automatically.

you are already drawing the bounding boxes

berak gravatar imageberak ( 2020-06-09 05:39:22 -0600 )edit

@berak Yes exactly. I first thought about just using a bigger region around the bounding boxes, but this could become a problem, if the contours are too close together. I know I have a vector with all the bounding boxes, so I have the information about position, width, height etc. So there should be a way to figure out where the ROI has to be, but I don't see the right approach at the moment.

samkro gravatar imagesamkro ( 2020-06-09 05:46:09 -0600 )edit