How to dialte a binary matrix?

10 次查看(过去 30 天)
Ahmad Adee
Ahmad Adee 2017-5-29
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

回答(1 个)

Image Analyst
Image Analyst 2017-5-29
Use imdilate()
B = imdilate(A, ones(3));

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by