I have an image and I would like to apply dilation, erosion, closing, opening operations proportionally to the image size.
In my code I divided the images in three sets but I think it's better to use other better ways. How can I change gradually the disk size for my operations?
import pymorph as pm
import mahtoas as mh
if (shape[0] < 100):
w = (shape[0]/100 )*0.2
elif(shape[0]> 100 and shape[0] <220):
w = (shape[0]/100 )*1.0
else:
w = (shape[0]/100)*3
#structuring elements
disk7 = pm.sedisk(w)
bfork = mh.morph.dilate(bfork, disk7)
You already have a valid stepped mapping from shape[0]
to w
.
If you would like to change that mapping to be more continuous you could use, eg
w = min(MAXVAL, max(MINVAL,SLOPE*shape[0]))
which will create a ramp between at least MINVAL and at most MAXVAL with gradient SLOPE.
Eg using MAXVAL = 80
, MINVAL = 20
, and SLOPE = 0.5
gives
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.