# How to find elliptic strips from a binary mask?

Image[DiskMatrix[All,{100,150}]];


Now I wish to have a strip like this:

such that I can manipulate the inner radius, and the outer radius (here major and minor axes) without changing the original image size.

How can I do this?

Edit 1:

I just figured out that I can do this in the following way:

Manipulate[mask1 = Image[DiskMatrix[{100*m, 150*m}, {100, 150}]];
mask2 = Image[DiskMatrix[{100*n, 150*n}, {100, 150}]];
{n, 0, m}]


Is there any better way to do this?

• you should make your last edit an answer. Seems pretty good, what do you want for "better" ? – george2079 Jan 4 '18 at 16:06
• @george2079 Thanks. I was thinking whether it can be done more easily. – Majis Jan 4 '18 at 16:09

If by "shrinking" you mean something like carving an n-pixel wide border from the mask, you can do this using morphological erosion with a disk structuring element

img = Image[DiskMatrix[All, {100, 150}]];
r1 = Erosion[img, DiskMatrix[10], Padding -> 0]


r2 = Erosion[img, DiskMatrix[20], Padding -> 0]


r1 - r2


Alternatively, you can use a distance transform to calculate the euclidean distance of each point in the mask to the background:

dist = DistanceTransform[img, Padding -> 0];
ListPlot3D[ImageData[dist]]


You can then use simple algebra to select the pixels at certain distances from the border:

UnitStep[dist - 10] - UnitStep[dist - 20]


(same result)

Here is another way:

With[{w = 100, h = 150, m = 3, n = 2},
Image@BitXor[
DiskMatrix[All, m {w, h}],
CenterArray[DiskMatrix[All, n {w, h}], m {w, h}]
]
]


another approach. (watch, this gets real slow if you try to make it any larger)

size = {100, 200}
Manipulate[
Image[SparseArray[{i_, j_} /;
a^2 < r (i - size[[1]]/2)^2 + (j - size[[2]]/2)^2 < b^2 -> 1,
size]],
{{a, 10}, 0, 100},
{{b, 50}, 0, 100},
{{r, 2}, 1, 10}]


I acknowledge other answers. However, I think I am happy with this one.

Manipulate[
mask1 = Image[DiskMatrix[{100*m[[2]], 150*m[[2]]}, {100, 150}]];
mask2 = Image[DiskMatrix[{100*m[[1]], 150*m[[1]]}, {100, 150}]];