필터 지우기
필터 지우기

How to change pixel value to "1" on the pixels of the background (from "0") neighboring the pixels of the object?

조회 수: 3 (최근 30일)
Good evening,
I have an exercise which is discribed below.
Implement in Matlab a basic algorithm of Dilation and Erosion. The implementation of Matlab for the dilation and erosion of binary images is the formal definition and may be difficult to understand when constructing algorithms for such purposes. Below is the way to create dilatation and erosion algorithms taking into account the basic and intuitive idea of these two operations:
Dilation: take each pixel of the object (with value "1") and set to the value "1" all those pixels belonging to the background that have a connectivity C (C = 4, C = 8, etc) with the pixel of the object. In short, put "1" the pixels of the background neighboring the pixels of the object.
Erosion: take each pixel of the object that has a connectivity C with the pixels of the background and set it to the value "0". In other words, set the pixels of the object to "0" neighboring the background pixels.
  댓글 수: 3
Gytis Baltrunas
Gytis Baltrunas 2018년 5월 17일
As I can understand, I have to add one more pixel around all the objects in the image, but do not know what code to use for it. Maybe you could help me sort it out ? Thank you

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

채택된 답변

Sammit Jain
Sammit Jain 2018년 5월 18일
Hi, I'm assuming that the dilation operation you want to accomplish will be modeled with the structuring element 'diamond' of pixel radius 1 px. (Because of the connectivity description) When performing dilation operations on images, it is good practice to first decide the kind of structuring element you would like to use and also define the neighborhood accordingly. Check out this for more information on structuring elements .
Here's how you proceed after you've decided your structuring element. I'm using a randomly thresholded binary image of size 50,50.
% Initialize Binary Image A
A = rand(50)>0.5;
% Initialize structuring element SE
SE = strel('diamond',1);
% Dilate the image using this SE and store as Image B
B = imdilate(A,SE);
% Observe Results
imshowpair(A,B,'montage');
The result I got is in the attached screenshot. Also, use the exact same process for erosion. I hope this helps.
Cheers.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by