Clear Filters
Clear Filters

How to dialte a binary matrix?

10 views (last 30 days)
Ahmad Adee
Ahmad Adee on 29 May 2017
Answered: Image Analyst on 29 May 2017
I want to dilate a binary matrix (containing 0 and 1). So if I have a matrix 10x10 Note that dilation is all 4 sides (row left, row right, column left and column right). The Output matrix should be of the same size.
if true
A=
1 1 1 1 1 1 1 1 1
1 0 0 0 1 1 0 0 1
1 0 0 0 1 1 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 1 1 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1
% i need this
B=
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1
1 1 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
or this
B=
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1
1 1 0 0 1 1 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 1 1 0 0 1 1
1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 0 1 1
1 1 0 1 1 0 1 1 1
1 1 1 1 1 1 1 1 1
end

Answers (1)

Image Analyst
Image Analyst on 29 May 2017
Use imdilate()
B = imdilate(A, ones(3));

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!