Reputation: 1642
I'm thickening a binary image. I wished to grow the label n pixels to each direction.
Original image:
At first I used the function bwmorph(I, 'thicken', 25) and got this image :
Which is no good. The thickening seems to use the structuring element [0,1,0;1,1,1;0,1,0], so it always transforms circles into diamonds. imdilate with the mentioned structuring element results in the same output.
Next I tried dilating the original image iteratively for n=25 times with the structuring element[1,1,1; 1,1,1; 1,1,1] and got the following image:
The original shape is now completely gone.
I understand that dilation will always distort the border to some degree. I experimented with the structuring element 'disk' (r=5, dilated 5 times) and got fairly good results:
Is this as good as it gets? Which structuring element should I choose if I wish to preserve the original circular shape as well as possible? Are there any good rules of thumbs for finding the right size for a particular dilation distance (which can vary from 10-100 and the labels vary from circular to elliptical)? Is there a better way of growing a binary image in all the directions while trying to keep the original shape?
Is there a way to keep the Euler characteristic -preserving quality of thicken while changing the structuring element to something more suitable?
Upvotes: 2
Views: 1280
Reputation: 1927
Try this:
bw = imread('bw.png');
figure; imshow(imdilate(bw, strel('arbitrary', bw)))
I am using the image itself for extending it. It gives a more shape-preserving growth:
UPDATE: As @Tapio said, one can easily adjust the resize factor using imresize
:
figure; imshow(imdilate(bw, strel('arbitrary', imresize(bw, 0.5))))
with the following output:
Upvotes: 3
Reputation: 5898
If you use only unitary structuring elements, then you will always face the problems you described. If you want to dilate a shape with a structuring element of size N, do not use N times a structuring element of size 1, else you will end up with beautiful unexpected deformation.
If you want to do a dilation of size N, try a disk of radius N. However, it will be much longer to process.
An other solution is to use a distance map: the shape is the seed (distance 0), then everything at a distance smaller than N is your result. It will be pretty similar to the dilation of size N.
Upvotes: 1