-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestModel.py
65 lines (54 loc) · 2.29 KB
/
testModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
##############
# TEST MODEL #
##############
'''
Python script used to test the model after computing
'''
from __future__ import print_function, unicode_literals, absolute_import, division
import numpy as np
import matplotlib.pyplot as plt
#matplotlib inline
#config InlineBackend.figure_format = 'retina'
from tifffile import imread, imsave
from csbdeep.utils import plot_some
from csbdeep.models import CARE
# author Nicolas Riss ([email protected])
##########################
# read an image as input #
##########################
x = imread("/home/nicolas/Bureau/MicroscopyImaging/Images/ruler_first_acquisition/pos3_50mw_1/pos3_50mw_1_MMStack_Pos0.ome.tif")
#x = imread("/home/nicolas/Bureau/MicroscopyImaging/Images/extract_spectra_beads_littleNoise.tif")
#x = imread("/home/nicolas/Bureau/MicroscopyImaging/Images/extract_spectra_ruler.tif") #read an image as input
imageNumber = 29 #number of the image to read on the stack
modelName = "modelRulerSpectralXCentered" #without noise
#modelName = "modelBeadsLittleNoiseSpectra64_200pepoch_woBorder" #noise added
########################
# predict output image #
########################
model = CARE(config=None, name=modelName, basedir='models')
restored = model.predict(x[imageNumber], "YX", normalizer=None)
###############
# Show result #
###############
plt.figure(figsize=(16,10))
plot_some(np.stack([x[imageNumber], restored]),
title_list=[['source image','predicted (CARE)']],
pmin=2,pmax=99.8);
plt.show()
#########################
# Predict probabilistic #
#########################
restored_prob = model.predict_probabilistic(x[imageNumber], "YX", normalizer=None) #axes?
plt.figure(figsize=(16,10))
plot_some(np.stack([restored_prob.mean(),restored_prob.scale()]), title_list=[['mean','scale']]);
plt.show()
######################
# Save the two files #
######################
imsave("restoredImage.tif", restored)
imsave("notRestoredImage.tif", x[imageNumber])
# CSBDeep has a save_tiff_imagej_compatible function that can be used also (TODO: study the difference)
# Sometimes, the images appears grey on ImageJ. It may be because of that.
# from csbdeep.io import save_tiff_imagej_compatible
# save_tiff_imagej_compatible('restoredImage.tif', restored, "YX")
# save_tiff_imagej_compatible('notRestoredImage.tif', x[imageNumber], "YX")