Finding pixel locations of labels

1 visualización (últimos 30 días)
med-sweng
med-sweng el 19 de Dic. de 2013
Respondida: Anand el 19 de Dic. de 2013
Assume that we have a labeled image. The labels (regions) I'm interested in that image are:
15 76 87 99 102 177
For all those labels, how can we find the following:
- Pixel with lowest column number - Pixel with lowest row number - Pixel with highest row number - Pixel with highest column number
Thanks.

Respuestas (2)

Image Analyst
Image Analyst el 19 de Dic. de 2013
It's basically the same as my answer to your duplicate question http://www.mathworks.com/matlabcentral/answers/110210#answer_118845. Did you look at that?
You use ismember() to extract only the blobs with those indexes from your original labeled image. Then you call regionprops() or any() or find() and min() to find the bounding box of all those. Something like (untested)
keeperIndexes = [15 76 87 99 102 177];
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% Find bounding box (one method to do it).
[rows, columns] = find(keeperBlobsImage);
topRow = min(rows(:));
bottomRow = max(rows(:));
leftCol = min(columns(:));
rightCol = max(columns(:));

Anand
Anand el 19 de Dic. de 2013
You're question could be clearer. We don't know what your end goal is so its difficult to give a good answer.
If you just need the indices with the lowest and highest row and column numbers, you should use the 'PixelList' property offered by regionprops. Read more about it here. Then compute the maximum and minimum from the returned pixel indices.
So for the connected component with label 15,
stats = regionprops(im,'PixelList');
min(stats(15).PixelList) %lowest row and col.
max(stats(15).PixelList) %highest row and col.
If you want the indices needed to index into the image and get the pixels corresponding to that, just use the 'Image' property of regionprops. Read more about this here.
stats = regionprops(im,'Image');
imshow(stats(15).Image)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by