1

I have a gray scale image add1, however there are only two pixel intensities in it (0 for Black and 255 for White). I am able to track the coordinate of my pixel of consideration i.e. add1(i,j). now I want to display the connected component of which this pixel is part of. I have tried it with the regionprop using 'PixelIdxList' and 'PixelList' unsuccesfully.
Can someone help please.Thanks in advance.

4

2 回答 2

2

据我了解,你想要这个:

            clc
            clear all
            close all

            im = imread('labelProb.png');
            im = im2bw(im);

            labelIm = bwlabel(im);
            rg = regionprops(im,'PixelIdxList','Centroid');

            figure,imshow(labelIm,[]),hold on
            for i = 1:length(rg)
                cc = rg(i).Centroid;
                text(cc(1),cc(2),['label: ',num2str(i)],'Color','b','FontSize',9)
            end
            f = getframe();
            lab = frame2im(f);
            hold off

            % suppose you want label number 3 only.

            cc = rg(3).Centroid; % this is your pixel index;
            % Extract label number through this index.
            cc = round(cc);
            labelNumber = labelIm(cc(2),cc(1));

            % create a new blank image.
            blankImage = false(size(im));

            for i = 1:length(rg)
                if i == labelNumber
                    blankImage(rg(i).PixelIdxList) = true;
                end
            end
            figure,imshow(blankImage,[])

上述执行的结果是:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

于 2015-10-30T10:34:07.120 回答
1

如果我理解你的问题,你想要的是:给定一个特定的坐标(i,j),标签是什么,以及作为一部分的连接组件的掩码(i,j)

add = bwlabel( add1 ); %// convert to label mask
lij = add(i,j); %// get the label to which i,j belongs to
figure;
imshow( add == lij, [] ); %// select only the relevant label
于 2015-11-02T13:10:08.713 回答