How to dilate lines in an image at varying levels of 'thickness'?

조회 수: 5(최근 30일)
Given a binary image of voronoi design, I want to dilate the white lines in such a way that they will have varying thickness across the image. So far I used the function imdilate to dilate the lines, however, it makes all lines the same thickness. How can I make the thickness be different across the image (something like a gradient)? I hope that makes sense.
Thank you in advance!
img_dilate = imdilate(img, strel('disk',d)); % d in an integer that controls the thickness.
Attached are two sample images.


Andrew Chen
Andrew Chen 2017년 10월 5일
I am kind of new to image processing and morphological operations but I've done some digging myself into your question. I don't think I have an entire answer but maybe have a component that can help bring you closer to your answer. Basically, I found some code online that allows you to define your own structuring element and then, in a loop does the morphological operation manually. It was in an answer to this Matlab Answers post What I have done is taken all of the integer inputs that are dependent on the structuring element size and made those inputs ACTUALLY dependent on the structuring element i.e. a change in the structuring element will automatically be taken into account in the morphological operation (via the size() function). Here is the code:
strel = [1 1 1 1 1;1 1 1 1 1]; %structuring element, must be an odd length in the 2nd (column #) dimension
C = padarray(voronoi,[size(strel,1)-1, (size(strel,2)-1)/2]);
dialated_img = false(size(voronoi));
for i = 1:size(C,1)-(size(strel,1)-1)
for j = 1:size(C,2)-(size(strel,2)-1)
dialated_img(i,j) = sum(sum(strel&C(i:i+(size(strel,1)-1),j:j+(size(strel,2)-1))));
The power in using this method of dilation (rather than the built in functionality of Matlab) would be that perhaps through some clever looping, maybe only using a structural element over a limited set of dimensions of your image and then changing the element for other regions of the image, you can achieve the result you are looking for.
Of course, it may be that you can use the built in morphological operations in Matlab, and call them over certain regions and then stitch the regions together to achieve the desired result.
Best of luck!

Community Treasure Hunt

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

Start Hunting!

Translated by