pythonimage-processingmahotas

How can I apply a function to an image proportionally to his size in python?


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)

Solution

  • 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, e.g.

    w = min(MAXVAL, max(MINVAL,SLOPE*shape[0])) 
    

    which will create a ramp between at least MINVAL and at most MAXVAL with gradient SLOPE.

    E.g. using MAXVAL = 80, MINVAL = 20, and SLOPE = 0.5 gives

    enter image description here