How to find indices of pixels outward from a detected boundary

1 次查看(过去 30 天)
Hello,
I am working on an application in which I am required to find the pixel value indices extruding out from the largest region. I have found the boundary of the region but can't of way to ensure that pixels are always looked for outwards from the boundary. I would be thankful if you guys could contribute on the matter.
a=logical([0 0 0 0 1;0 1 1 0 0;0 0 1 1 0;0 1 1 1 0; 0 0 1 1 0;1 0 0 0 0]); %Test matrix
acon=regionprops(a,'Area','PixelIdxList'); %finds the connected components
loca=find([acon.Area]==max([acon.Area])); %Pixel seq index of largest comp
%in detected regions
abound=bwboundaries(a,8,'noholes'); %Finds location of boundary of region
dom_bound=abound{loca}; %Get locations of boundary pixels
  1 个评论
Matt J
Matt J 2013-6-20
编辑:Matt J 2013-6-20
I, for one, can't tell what you mean by pixels that are "extruding". Can you post an illustration?

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2013-6-20
Not exactly sure what you want. But once you've extracted the largest blob (I've posted code for that here before), then you can call imdilate() to enlarge that blob by one layer of pixels, and then call bwboundaries(). Is that what you meant?

wond3rboy
wond3rboy 2013-6-21
Hello
Thank you for the replies. I apologise for the problem description not being clear. I attach a picture here that kind of shows what I am trying to do. I have an image that consists of regions/sets of specific pixel values (say 24 as shown in the attached image). My goal is to find the largest region/set of those pixels and give the sum of the pixel values within the region (which is quite easy once you get to know the number of pixels in the region and I have done it). My next task is to find the sum of pixels in a 2 pixel neighbourhood of the set (kind of like applying a dilation twice with a pixel structuring element, finding the sum of the pixels and subtracting the sum of the original region). The pixels are highlighted in green colour. I am looking in to the dilate suggestion and will post an update if I make progress. I didn't post the code in a proper manner so I repost the code, it only finds the locations of the largest region and its boundary of a specific pixel value (I am not using the code tags since I messed it up in my previous post).
Code:
clear a=logical([0 0 0 0 1;0 1 1 0 0;0 0 1 1 0;0 1 1 1 0; 0 0 1 1 0;1 0 0 0 0]); acon=regionprops(a,'Area','PixelIdxList'); %finds the connected components
loca=find([acon.Area]==max([acon.Area])); %Pixel seq index of largest comp %in detected regions
abound=bwboundaries(a,8,'noholes'); %Finds location of boundary of region dom_bound=abound{loca}; %Get locations of boundary pixels

Community Treasure Hunt

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

Start Hunting!

Translated by