image processing - Get the object position by using bwconncomp in Matlab -
for segmentation, there function in matlab bwconncomp
. can calculate number of detected objects.
im=imread('mountain.ppm'); [seg_im] = normalize_segmentation(im); im_filt=medfilt2(seg_im,[3 3]); se=strel('disk',2); seg_im = imclose(im_filt,se); obj_im= bwconncomp(seg_im,6) obj_im = connectivity: 6 imagesize: [30 32] numobjects: 1 pixelidxlist: {[129x1 double]}
and when acces pixelidxlist
, maximum value 834.
what 834? because image size 30x32.
and how can positon of object using pixelidxlist
/bwconncomp
information?
a @ manual tell linear index:
pixelidxlist: 1-by-numobjects cell array kth element in cell array vector containing linear indices of pixels in kth object.
if want them in x
, y
format, use ind2sub
function:
[x,y]=ind2sub(size(im), obj_im.pixelidxlist)
one example:
[x,y]=ind2sub(size(im), 834) x = 24 y = 28
Comments
Post a Comment