scottykwok / cervix-roi-segmentation-by-unet

35 stars 11 forks source link

Doubt in predict.py #1

Open ronroc opened 7 years ago

ronroc commented 7 years ago

Hi Scotty - Tks for the amazing code, helped me a lot , had a doubt in predict.py . Is it possible to explain what was done in predict.py at a high level, any references to any literature on these methods would be great Thanks -

scottykwok commented 7 years ago

Hi Ronroc, for predict.py, the main logic is in predict_and_crop():

# this get the unet prediction
predict = model.predict(img, batch_size=1, verbose=0) 

# this perform auto binary threshold to give a binary mask
binary_mask = to_binary_mask(predict[0])

# this use morphology open & close to remove small holes in the mask
morphed_mask = morphology_clean(binary_mask)

# this find the coordinates & weight & height of the bounding box that bound the morphed_mask
x, y, w, h = find_bbox(morphed_mask, margin_factor)

Then the program crop the original image based on x,y,w,h.

It may be helpful to visualize the mask and the bounding box overlap on the original image, you can do so by setting:

generate_previews = True
generate_masks = True

and the visualization will be generated in 'xxxx_preview.jpg'