Excluding Perimeter values of Boundary using regionprops

2 views (last 30 days)
Hi.
I have an image that I create a binary image from with an aim to use this as a mask to read values of the foreground on the original image.
I use the following code to obtain the regions that I then mask back onto the raw image and take the mean of them.
labeledImage = bwlabel(Binary, 8); % Label each blob so we can make measurements of it
blobMeasurements = regionprops(labeledImage, ROI, 'all'); %ROI is original image
numberOfBlobs = size(blobMeasurements, 1);
hold on;
boundaries = bwboundaries(Binary);
numberOfBoundaries = size(boundaries);
subplot(4,5,[3,4,8,9])
hold on
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 1);
end
hold off;
%Get mean intensity of foreground by blobmeasurements
allBlobIntensities = [blobMeasurements.MeanIntensity]
meanI=mean(allBlobIntensities(:))
My question is, I want to exclude the values that are say within 1 pixel of the actual region boundary (for all boundaries, i.e exclude the perimeter of each boundary.
Is this possible? Thanks Jason

Accepted Answer

Image Analyst
Image Analyst on 14 Dec 2015
Contract your mask by calling imerode() before you label it:
Binary = imerode(Binary, true(3));
  2 Comments
Image Analyst
Image Analyst on 14 Dec 2015
It makes a 3 by 3 array of "true" values, meaning that it takes into consideration all 9 values in that little square window as it scans the image, finding the min value, which will be zero/false/black. So it has the effect of eating/dissolving a layer from your binary image, essentially shrinking it by one pixel all around.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!