optic-nerve-cnn icon indicating copy to clipboard operation
optic-nerve-cnn copied to clipboard

Failure in segmenting OD from DRIONS DB

Open Mahanteshambi opened this issue 5 years ago • 1 comments

I am using your

U-Net, OD on DRIONS-DB (fold 0)

notebook to simulate OD segmentation on DRIONS DB, It works perfectly fine when i use your pre-trained model from folder

05.03,02_40,U-Net light, on DRIONS-DB 256 px fold 0, SGD, high augm, CLAHE, log_dice loss

to segment images from your "DRIONS_DB.hdf5" But When I load image from DRIONS db, and predict segmentation using the following code, then I see very bad segmentation.

img_path = 'E:/DRIONS/DRIONS-DB/images/image_001.jpg'
im = np.array(Image.open(img_path))
im = im[0:, 40:]
print(im.shape)
im = cv2.resize(im, (256,256))
print(im.shape)
plt.imshow(im), plt.show()
im = np.expand_dims(im, axis=0)
im = tf_to_th_encoding(im)
prediction = (model.predict(im)[0, 0]).astype(np.float64)
plt.imshow(prediction>0.5, cmap=plt.cm.Greys_r), plt.show()

So can you help me out in understanding why it is working when using an image from your DRIONS_DB.hdf5 file and why it is failing while processing a new image?

Mahanteshambi avatar Apr 23 '19 18:04 Mahanteshambi

@Mahanteshambi, big apologies for not noticing your request in time. Actually you just needed to add one line which rescales an image from uint8 [0, 255] scale to float [0, 1] scale of intensities:

im = np.array(Image.open(img_path))
im = im[0:, 40:]
print(im.shape)
im = cv2.resize(im, (256,256))

im = im.astype(np.float64) / 255.0

print(im.shape)
plt.imshow(im), plt.show()
im = np.expand_dims(im, axis=0)
im = tf_to_th_encoding(im)
prediction = (model.predict(im)[0, 0]).astype(np.float64)
plt.imshow(prediction, cmap=plt.cm.Greys_r), plt.show()

This way it works fine for me.

Also, it's necessary to add CLAHE im = skimage.exposure.equalize_adapthist(im) right after the rescaling line im = im.astype(np.float64) / 255.0 in order to reproduce exactly the same results, since model expects images only after CLAHE was performed on them.

seva100 avatar Dec 25 '19 13:12 seva100