OpenCV superpixels - How to reorganize data into a 2D array ?
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.
" even if I have the mean of the xy coordinates of each superpixel." - just curious, how did you get there ?
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
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 :(
this might be a pathologic example, but i don't think, your 8 connectivity assumption holds true:
(SLICO) (SLIC)
( btw, using this code )
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
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
https://www.google.com.sg/url?sa=t&so...
Sorry forgot to mention its question 6.1 part 2
"scan the labeled image along rows and columns and look for transitions" -- isn't this done in the border mask already ?