Cody

# Problem 839. Compute the dilation of a binary image

Solution 2957572

Submitted on 17 Sep 2020 by Michael Neiman
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
f = fopen('mymorphop.m','rt'); code = lower(fread(f,Inf,'*char'))'; fclose(f); assert(isempty(strfind(code,'dilat'))) assert(isempty(strfind(code,'erode'))) assert(isempty(strfind(code,'bwmorph'))) assert(isempty(strfind(code,'filt'))) assert(isempty(strfind(code,'conv')))

2   Pass
in = zeros(3,3); out = in; assert(isequal(mymorphop(in),out));

neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 2 neighborLeft = 2 neighborRight = 3 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 3 neighborLeft = 2 neighborRight = 3 neighborTop = 2 neighborBottom = 3 neighborLeft = 1 neighborRight = 2 neighborTop = 2 neighborBottom = 3 neighborLeft = 1 neighborRight = 3 neighborTop = 2 neighborBottom = 3 neighborLeft = 2 neighborRight = 3

3   Pass
in = zeros(10,5); in(4,3) = 1; out = in; out(3:5,2:4) = 1; assert(isequal(mymorphop(in),out));

neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 2 neighborLeft = 2 neighborRight = 4 neighborTop = 1 neighborBottom = 2 neighborLeft = 3 neighborRight = 5 neighborTop = 1 neighborBottom = 2 neighborLeft = 4 neighborRight = 5 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 3 neighborLeft = 2 neighborRight = 4 neighborTop = 1 neighborBottom = 3 neighborLeft = 3 neighborRight = 5 neighborTop = 1 neighborBottom = 3 neighborLeft = 4 neighborRight = 5 neighborTop = 2 neighborBottom = 4 neighborLeft = 1 neighborRight = 2 neighborTop = 2 neighborBottom = 4 neighborLeft = 1 neighborRight = 3 neighborTop = 2 neighborBottom = 4 neighborLeft = 2 neighborRight = 4 neighborTop = 2 neighborBottom = 4 neighborLeft = 3 neighborRight = 5 neighborTop = 2 neighborBottom = 4 neighborLeft = 4 neighborRight = 5 neighborTop = 3 neighborBottom = 5 neighborLeft = 1 neighborRight = 2 neighborTop = 3 neighborBottom = 5 neighborLeft = 1 neighborRight = 3 neighborTop = 3 neighborBottom = 5 neighborLeft = 2 neighborRight = 4 neighborTop = 3 neighborBottom = 5 neighborLeft = 3 neighborRight = 5 neighborTop = 3 neighborBottom = 5 neighborLeft = 4 neighborRight = 5 neighborTop = 4 neighborBottom = 6 neighborLeft = 1 neighborRight = 2 neighborTop = 4 neighborBottom = 6 neighborLeft = 1 neighborRight = 3 neighborTop = 4 neighborBottom = 6 neighborLeft = 2 neighborRight = 4 neighborTop = 4 neighborBottom = 6 neighborLeft = 3 neighborRight = 5 neighborTop = 4 neighborBottom = 6 neighborLeft = 4 neighborRight = 5 neighborTop = 5 neighborBottom = 7 neighborLeft = 1 neighborRight = 2 neighborTop = 5 neighborBottom = 7 neighborLeft = 1 neighborRight = 3 neighborTop = 5 neighborBottom = 7 neighborLeft = 2 neighborRight = 4 neighborTop = 5 neighborBottom = 7 neighborLeft = 3 neighborRight = 5 neighborTop = 5 neighborBottom = 7 neighborLeft = 4 neighborRight = 5 neighborTop = 6 neighborBottom = 8 neighborLeft = 1 neighborRight = 2 neighborTop = 6 neighborBottom = 8 neighborLeft = 1 neighborRight = 3 neighborTop = 6 neighborBottom = 8 neighborLeft = 2 neighborRight = 4 neighborTop = 6 neighborBottom = 8 neighborLeft = 3 neighborRight = 5 neighborTop = 6 neighborBottom = 8 neighborLeft = 4 neighborRight = 5 neighborTop = 7 neighborBottom = 9 neighborLeft = 1 neighborRight = 2 neighborTop = 7 neighborBottom = 9 neighborLeft = 1 neighborRight = 3 neighborTop = 7 neighborBottom = 9 neighborLeft = 2 neighborRight = 4 neighborTop = 7 neighborBottom = 9 neighborLeft = 3 neighborRight = 5 neighborTop = 7 neighborBottom = 9 neighborLeft = 4 neighborRight = 5 neighborTop = 8 neighborBottom = 10 neighborLeft = 1 neighborRight = 2 neighborTop = 8 neighborBottom = 10 neighborLeft = 1 neighborRight = 3 neighborTop = 8 neighborBottom = 10 neighborLeft = 2 neighborRight = 4 neighborTop = 8 neighborBottom = 10 neighborLeft = 3 neighborRight = 5 neighborTop = 8 neighborBottom = 10 neighborLeft = 4 neighborRight = 5 neighborTop = 9 neighborBottom = 10 neighborLeft = 1 neighborRight = 2 neighborTop = 9 neighborBottom = 10 neighborLeft = 1 neighborRight = 3 neighborTop = 9 neighborBottom = 10 neighborLeft = 2 neighborRight = 4 neighborTop = 9 neighborBottom = 10 neighborLeft = 3 neighborRight = 5 neighborTop = 9 neighborBottom = 10 neighborLeft = 4 neighborRight = 5

4   Pass
in = [0,0,1,0,0,1,0 0,1,0,0,0,1,1 1,1,0,0,0,0,0 1,0,0,0,0,0,1 1,0,0,0,0,1,1]; out = [1,1,1,1,1,1,1 1,1,1,1,1,1,1 1,1,1,0,1,1,1 1,1,1,0,1,1,1 1,1,0,0,1,1,1]; assert(isequal(mymorphop(in),out));

neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 2 neighborLeft = 2 neighborRight = 4 neighborTop = 1 neighborBottom = 2 neighborLeft = 3 neighborRight = 5 neighborTop = 1 neighborBottom = 2 neighborLeft = 4 neighborRight = 6 neighborTop = 1 neighborBottom = 2 neighborLeft = 5 neighborRight = 7 neighborTop = 1 neighborBottom = 2 neighborLeft = 6 neighborRight = 7 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 3 neighborLeft = 2 neighborRight = 4 neighborTop = 1 neighborBottom = 3 neighborLeft = 3 neighborRight = 5 neighborTop = 1 neighborBottom = 3 neighborLeft = 4 neighborRight = 6 neighborTop = 1 neighborBottom = 3 neighborLeft = 5 neighborRight = 7 neighborTop = 1 neighborBottom = 3 neighborLeft = 6 neighborRight = 7 neighborTop = 2 neighborBottom = 4 neighborLeft = 1 neighborRight = 2 neighborTop = 2 neighborBottom = 4 neighborLeft = 1 neighborRight = 3 neighborTop = 2 neighborBottom = 4 neighborLeft = 2 neighborRight = 4 neighborTop = 2 neighborBottom = 4 neighborLeft = 3 neighborRight = 5 neighborTop = 2 neighborBottom = 4 neighborLeft = 4 neighborRight = 6 neighborTop = 2 neighborBottom = 4 neighborLeft = 5 neighborRight = 7 neighborTop = 2 neighborBottom = 4 neighborLeft = 6 neighborRight = 7 neighborTop = 3 neighborBottom = 5 neighborLeft = 1 neighborRight = 2 neighborTop = 3 neighborBottom = 5 neighborLeft = 1 neighborRight = 3 neighborTop = 3 neighborBottom = 5 neighborLeft = 2 neighborRight = 4 neighborTop = 3 neighborBottom = 5 neighborLeft = 3 neighborRight = 5 neighborTop = 3 neighborBottom = 5 neighborLeft = 4 neighborRight = 6 neighborTop = 3 neighborBottom = 5 neighborLeft = 5 neighborRight = 7 neighborTop = 3 neighborBottom = 5 neighborLeft = 6 neighborRight = 7 neighborTop = 4 neighborBottom = 5 neighborLeft = 1 neighborRight = 2 neighborTop = 4 neighborBottom = 5 neighborLeft = 1 neighborRight = 3 neighborTop = 4 neighborBottom = 5 neighborLeft = 2 neighborRight = 4 neighborTop = 4 neighborBottom = 5 neighborLeft = 3 neighborRight = 5 neighborTop = 4 neighborBottom = 5 neighborLeft = 4 neighborRight = 6 neighborTop = 4 neighborBottom = 5 neighborLeft = 5 neighborRight = 7 neighborTop = 4 neighborBottom = 5 neighborLeft = 6 neighborRight = 7

5   Pass
in = [0,0,1,0,0,0,0,0,1 0,1,0,0,0,0,0,0,1 1,1,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]; out = [1,1,1,1,0,0,0,1,1 1,1,1,1,0,0,0,1,1 1,1,1,0,0,0,0,1,1 1,1,1,0,0,0,0,1,1 1,1,0,0,0,0,0,1,1]; assert(isequal(mymorphop(in),out));

neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 2 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 2 neighborLeft = 2 neighborRight = 4 neighborTop = 1 neighborBottom = 2 neighborLeft = 3 neighborRight = 5 neighborTop = 1 neighborBottom = 2 neighborLeft = 4 neighborRight = 6 neighborTop = 1 neighborBottom = 2 neighborLeft = 5 neighborRight = 7 neighborTop = 1 neighborBottom = 2 neighborLeft = 6 neighborRight = 8 neighborTop = 1 neighborBottom = 2 neighborLeft = 7 neighborRight = 9 neighborTop = 1 neighborBottom = 2 neighborLeft = 8 neighborRight = 9 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 2 neighborTop = 1 neighborBottom = 3 neighborLeft = 1 neighborRight = 3 neighborTop = 1 neighborBottom = 3 neighborLeft = 2 neighborRight = 4 neighborTop = 1 neighborBottom = 3 neighborLeft = 3 neighborRight = 5 neighborTop = 1 neighborBottom = 3 neighborLeft = 4 neighborRight = 6 neighborTop = 1 neighborBottom = 3 neighborLeft = 5 neighborRight = 7 neighborTop = 1 neighborBottom = 3 neighborLeft = 6 neighborRight = 8 neighborTop = 1 neighborBottom = 3 neighborLeft = 7 neighborRight = 9 neighborTop = 1 neighborBottom = 3 neighborLeft = 8 neighborRight = 9 neighborTop = 2 neighborBottom = 4 neighborLeft = 1 neighborRight = 2 neighborTop = 2 neighborBottom = 4 neighborLeft = 1 neighborRight = 3 neighborTop = 2 neighborBottom = 4 neighborLeft = 2 neighborRight = 4 neighborTop = 2 neighborBottom = 4 neighborLeft = 3 neighborRight = 5 neighborTop = 2 neighborBottom = 4 neighborLeft = 4 neighborRight = 6 neighborTop = 2 neighborBottom = 4 neighborLeft = 5 neighborRight = 7 neighborTop = 2 neighborBottom = 4 neighborLeft = 6 neighborRight = 8 neighborTop = 2 neighborBottom = 4 neighborLeft = 7 neighborRight = 9 neighborTop = 2 neighborBottom = 4 neighborLeft = 8 neighborRight = 9 neighborTop = 3 neighborBottom = 5 neighborLeft = 1 neighborRight = 2 neighborTop = 3 neighborBottom = 5 neighborLeft = 1 neighborRight = 3 neighborTop = 3 neighborBottom = 5 neighborLeft = 2 neighborRight = 4 neighborTop = 3 neighborBottom = 5 neighborLeft = 3 neighborRight = 5 neighborTop = 3 neighborBottom = 5 neighborLeft = 4 neighborRight = 6 neighborTop = 3 neighborBottom = 5 neighborLeft = 5 neighborRight = 7 neighborTop = 3 neighborBottom = 5 neighborLeft = 6 neighborRight = 8 neighborTop = 3 neighborBottom = 5 neighborLeft = 7 neighborRight = 9 neighborTop = 3 neighborBottom = 5 neighborLeft = 8 neighborRight = 9 neighborTop = 4 neighborBottom = 5 neighborLeft = 1 neighborRight = 2 neighborTop = 4 neighborBottom = 5 neighborLeft = 1 neighborRight = 3 neighborTop = 4 neighborBottom = 5 neighborLeft = 2 neighborRight = 4 neighborTop = 4 neighborBottom = 5 neighborLeft = 3 neighborRight = 5 neighborTop = 4 neighborBottom = 5 neighborLeft = 4 neighborRight = 6 neighborTop = 4 neighborBottom = 5 neighborLeft = 5 neighborRight = 7 neighborTop = 4 neighborBottom = 5 neighborLeft = 6 neighborRight = 8 neighborTop = 4 neighborBottom = 5 neighborLeft = 7 neighborRight = 9 neighborTop = 4 neighborBottom = 5 neighborLeft = 8 neighborRight = 9

### Community Treasure Hunt

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

Start Hunting!