# Is it possible to erode only the outermost layer of a circle?

조회 수: 17(최근 30일)
Teshan Rezel 2022년 5월 31일
댓글: Teshan Rezel 2022년 6월 2일
Hi folks,
I am looking to erode a circle from the outside in, layer by layer. So far, I have tried to use the following:
x = imerode(x, strel('disk', 1));
but in the case of an image with a higher Euler number than 1, this erodes the holes within the image as well...Is there a way around this please?
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
Teshan Rezel 2022년 5월 31일
@Walter Roberson Unfortunately, the holes are an important part of this exercise. Essentially, I'm trying to model a physical process where something is "eaten" from the outside in (this is the nearest analogy I can find, apologies if it doesn't make sense!)

댓글을 달려면 로그인하십시오.

### 채택된 답변

Image Analyst 2022년 5월 31일
Another option would be to use bwperim and imfill. Something like (untested)
% Fill holes
% Get outer perimeter.
% Set those pixels to false/0/black.
##### 댓글 수: 1표시 없음숨기기 없음
Teshan Rezel 2022년 6월 2일
This is brilliant, thank you!

댓글을 달려면 로그인하십시오.

### 추가 답변(2개)

Image Analyst 2022년 5월 31일
Here are the steps I'd try, assuming you're starting with a binary image
Call bwboundaries to get the outer layer. Of course, tell it to ignore interior holes - there's an option for that.
Have a for loop where you visit every (x,y) location and set it's value to false.
Something like (untested)
bxy = boundaries{1};
rows = bxy(:, 1);
cols = bxy(:, 2);
for k = 1 : length(rows)
end
##### 댓글 수: 0표시 이전 댓글 수: -1숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Walter Roberson 2022년 5월 31일
negate the image so the holes and background are true and the white is false. bwareafilt requesting the largest. That will be the background. negate the background to get the filled foreground. Subtract the original image from the filled one to get the location of the holes. Erode the filled image. Subtract the holes.
You might have to filter differently if you have multiple disconnected objects.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Object Analysis in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by