OpenCV superpixels - How to reorganize data into a 2D array ?

asked 2016-08-29 04:30:04 -0600

Nbb gravatar image

updated 2016-08-29 23:41:48 -0600

EDIT: No one has any idea ????

I am working on a school project on image segmentation and object recognition and am trying out conditional / markov random fields on superpixels. getLabels() returns a Mat where pixels belonging to the same superpixels are assigned the same integer for eg. from 0 to 1000. So I now have a 1D vector where each vector contains the mean coordinate of each superpixel.

However, since the structure of CRFs/MRFs in image processing are in a "2D" layout, Id like to reorganize the superpixels into a 2D array where neighbouring contents signify adjacent superpixels but am having a lot of problems doing so even if I have the mean of the xy coordinates of each superpixel.

I was hoping someone would have a suggestion on how I can achieve this.

edit retag flag offensive close merge delete

Comments

" even if I have the mean of the xy coordinates of each superpixel." - just curious, how did you get there ?

berak gravatar imageberak ( 2016-08-30 00:58:29 -0600 )edit

Hi thanks! GetLabels() returns a matrix with the width and height equal to the input image. The contents of the matrix denote the superpixel ID. So to get the mean of superpixel 13 I run a for loop through the entire image to scan for the number 13 and accumulate the coordinates in a vector. Then I just average it to get the center of superpixel 13

Nbb gravatar imageNbb ( 2016-08-30 01:44:19 -0600 )edit

Im using SLIC superpixels so I guess I can make the assumption that the superpixels can be at most 8 connected to make my life easier. However, if anyone has any suggestion for an arbitrary number of connections it would be great :(

Nbb gravatar imageNbb ( 2016-08-30 01:46:10 -0600 )edit

this might be a pathologic example, but i don't think, your 8 connectivity assumption holds true:

image description (SLICO) image description (SLIC)

( btw, using this code )

berak gravatar imageberak ( 2016-08-30 01:55:48 -0600 )edit
1

Yeah but it still doesnt tell me the neighbours of the superpixels. And just to correct my prev comment, I think it would be better to form an adjacency matrix so the superpixel can have an arbitrary number of neighbours

Nbb gravatar imageNbb ( 2016-08-30 02:20:39 -0600 )edit

I think I found a simple solution from an assignment of CMU. It says to just scan the labeled image along rows and columns and look for transitions

Nbb gravatar imageNbb ( 2016-08-30 02:26:37 -0600 )edit
1

Sorry forgot to mention its question 6.1 part 2

Nbb gravatar imageNbb ( 2016-08-30 02:37:33 -0600 )edit

"scan the labeled image along rows and columns and look for transitions" -- isn't this done in the border mask already ?

berak gravatar imageberak ( 2016-08-30 03:07:43 -0600 )edit